ilude Posted April 16, 2009 Share Posted April 16, 2009 Hey all, Here's dilemma - I'm working with xPath to drill-down into XML, but now I need to go back UP the XML tree. XML:[pre] <?xml version="1.0" encoding="UTF-8"?> <Report> <Enterprises> <Enterprise id="" status="4"> <Name>entName</Name> <Divisions> <Division id="" status="4"> <Name>mydomain.com</Name> <Users> <User id="" status=""> <OriginialUsername>username</OriginialUsername> <OriginialPassword>password</OriginialPassword> <NewUserName>newusername</NewUserName> <Errors/> </User> </Users> </Division> <Division id="" status="4"> <Name>anotherdomain.com</Name> <Users> <User id="" status=""> <OriginialUsername>username</OriginialUsername> <OriginialPassword>password</OriginialPassword> <NewUserName>newusername</NewUserName> <Errors/> </User> </Users> </Division> </Divisions> <Errors> <Error id="806" severity="4"> <Name>Call to API failed.</Name> <Detail><![CDATA[]]></Detail> </Error> </Errors> </Enterprise> [/pre] What I need is every Division->Name where the Enterprise has an Error with the id=806. The xPath query '/Report/Enterprises/Enterprise/Errors/Error[@id=806]' will get me to the Error and it's children, how can I go back UP the tree? Quote Link to comment https://forums.phpfreaks.com/topic/154414-php-xpath-and-transversing/ Share on other sites More sharing options...
Maq Posted April 16, 2009 Share Posted April 16, 2009 There's no reason to go back up the tree. Just grab everything on the way down. What exactly are you using to grab the XML? Quote Link to comment https://forums.phpfreaks.com/topic/154414-php-xpath-and-transversing/#findComment-811910 Share on other sites More sharing options...
soak Posted April 16, 2009 Share Posted April 16, 2009 If it's available on your setup may I recommend simplexml: http://uk3.php.net/manual/en/book.simplexml.php Quote Link to comment https://forums.phpfreaks.com/topic/154414-php-xpath-and-transversing/#findComment-811913 Share on other sites More sharing options...
ilude Posted April 16, 2009 Author Share Posted April 16, 2009 I'm open for anything, but most of what I've done in the past was done using SimpleXML. [pre]$file = file_get_contents('./xml/' . $v); $xml = new SimplexmlElement($file);[/pre] Quote Link to comment https://forums.phpfreaks.com/topic/154414-php-xpath-and-transversing/#findComment-811916 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.