Jump to content

get value of an xml node/element


real_illusions
 Share

Recommended Posts

Hi all,Is there a simple way of getting the value of a specific element in an XML file?<result><element>value here</element></result>I know that result and elements names are constant, but the value inside the element will change, its this value I need to get.I have the XML file loaded, was hoping something like this works, but it doesn't:$xml = simplexml_load_file("http://externalsite.com/url?url= $url") or die ("Unable to load results");$results = $xml->xpath("//result/element/.."); // returns an array of objects But printing out the array results in nothing been printed out.

Edited by real_illusions
Link to comment
Share on other sites

You're making the XPath expression a bit too complex... try

$xml->xpath("//result/element");

You do want all "element" elements, right? Doing ".." would return you one level above, i.e. to the "result" level, i.e. you'd get all "result" elements.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...