Reputation: 1302
How do I parse "id" from the following event
<event id="100990">
<title>myTitle</title>
</event>
I parse the title like this:
$xml->event[0]->title
Upvotes: 0
Views: 109
Reputation: 11385
Use the attributes method of SimpleXML
$id_attribute = (string)$xml->event[0]->attributes()->id;
Upvotes: 2
Reputation:
You access attributes just like you would access elements of an associative array:
$xml_node['id'] // The value of the attribute `id` of the node `$xml_node`
The returned value is an object (with a __toString
method), so you may want to typecast the returned value.
Upvotes: 2
Reputation: 37464
This is exactly what you need: http://www.php.net/manual/en/simplexmlelement.attributes.php
Upvotes: 0