2011-08-09 21 views
0

如何解析 “ID”,从以下事件PHP的XML simple_load ID

<event id="100990"> 
    <title>myTitle</title> 
</event> 

我分析标题是这样的:

$xml->event[0]->title 

回答

2

使用的SimpleXML

attributes方法
$id_attribute = (string)$xml->event[0]->attributes()->id; 
2

access attributes就像你会访问一个关联数组的元素:

$xml_node['id'] // The value of the attribute `id` of the node `$xml_node` 

返回的值是一个对象(使用__toString方法),因此您可能需要对返回的值进行类型转换。