I am trying to use php to work with several xml files. I have read through the explanations and some examples on php simpleXML website but I am having trouble getting what I want out of the xml.
I have no control over the xml. Here is a snippet of the xml file:\[code\]<end-user-emails> <user email="[email protected]"/></end-user-emails>\[/code\]A snippet of code I currently have:\[code\]$result = $xml->xpath("end-user-emails/user[@email]");print_r($result[0]);\[/code\]Which outputs: \[code\]SimpleXMLElement Object ( [0] => [email protected] ) \[/code\]I cannot find a way to simply return attribute value.
I have tried casting it to a string and get errors.I have tried several variations of:\[code\]$result = $xml->end-user-emails[0]->user[0]->attributes();\[/code\]and it tells me, despite the previous output, that I cannot call attributes() because it is not being called on an object.So, if anyone could let me know how to grab both the attribute name and value from the xml it would be much appreciated. The attribute name is not nessasary but I would like to use it so I can check that I am in fact grabbing an email, something like: \[code\]if attributeName = "email" then $email = attributevalue\[/code\]
I have no control over the xml. Here is a snippet of the xml file:\[code\]<end-user-emails> <user email="[email protected]"/></end-user-emails>\[/code\]A snippet of code I currently have:\[code\]$result = $xml->xpath("end-user-emails/user[@email]");print_r($result[0]);\[/code\]Which outputs: \[code\]SimpleXMLElement Object ( [0] => [email protected] ) \[/code\]I cannot find a way to simply return attribute value.
I have tried casting it to a string and get errors.I have tried several variations of:\[code\]$result = $xml->end-user-emails[0]->user[0]->attributes();\[/code\]and it tells me, despite the previous output, that I cannot call attributes() because it is not being called on an object.So, if anyone could let me know how to grab both the attribute name and value from the xml it would be much appreciated. The attribute name is not nessasary but I would like to use it so I can check that I am in fact grabbing an email, something like: \[code\]if attributeName = "email" then $email = attributevalue\[/code\]