Hi guys,
I am trying to get a value from a node within an XML response.
Here is the code:
[code=php]$xml = ‘
<NotificationService Version=”2.3″>
<NotificationList>
<Tags>
<Tag Name=”Apple”>gdfgfdsgdsg</Tag>
<Tag Name=”Banana”>hgfhfghfgh</Tag>
<Tag Name=”Orange”>fghfghfghgf</Tag>
</Tags>
</NotificationList>
</NotificationService>
‘;
$xml_element = new SimpleXMLElement($xml);
//How to get the value from the node with the attribute Name=”Banana” ?
I am trying to get the value of a node based on its attribute. For example, in the example above, if I would like to get the value of the tag Name Banana, I would do:
[code=php]$xml_element->NotificationList->Tags->Tag[1]
The thing is that the XML response I receive does not always have the node in the same order, so for example, in the example, the banana tag could sometime be the first node instead of the second etc..
I am trying to get the value of a node based on its attribute so that way, it doesnt matter in wich order the node are, I will always get the right value.
I tried something like this, but it is not working:
[code=php]$xml_element->NotificationList->Tags->Tag[‘banana’]
How can I do that?
Thanks alot!