prometheos Posted March 30, 2010 Share Posted March 30, 2010 hey, im having trouble with this dom xpath query.... heres the layout of my xml <items> <item> <itemName> </itemName> <requested> <by> </by> <confirmed> </confirmed> </requested> </item> <item> </item> . . . </items> i want it so depending if the item name is a certain thing, to query the 'requested/by' field of that same item? can any1 help me? heres the code i have $dom = new DOMDocument(); $dom->load($forfilename); $xpath = new DOMXPath($dom); $a = $xpath->query('item/[itemName='.$itemN.']/../requested/by'); any ideas welcome, thanks in advance:) Quote Link to comment https://forums.phpfreaks.com/topic/197009-php-xpath-query-xml/ Share on other sites More sharing options...
ignace Posted March 30, 2010 Share Posted March 30, 2010 Your XML is wrong <item name="whatever"> <request by="someone" confirmed="true"/> </item> Then you can use: /item[name="whatever"] Now you have to query all by: /item/request/by | //by And go over each element, retrieve it's value and check if it equals Quote Link to comment https://forums.phpfreaks.com/topic/197009-php-xpath-query-xml/#findComment-1034292 Share on other sites More sharing options...
salathe Posted March 30, 2010 Share Posted March 30, 2010 prometheos, your XPath query is problematic. One which should retrieve the elements that you are looking for is: /items/item[itemName=...]/requested/by So in PHP, something like: $nodes = $xpath->query('/items/item[itemName="'.$itemN.'"]/requested/by'); P.S. There is nothing wrong with the structure of the XML, to my eye at least. Quote Link to comment https://forums.phpfreaks.com/topic/197009-php-xpath-query-xml/#findComment-1034313 Share on other sites More sharing options...
prometheos Posted March 30, 2010 Author Share Posted March 30, 2010 thanks for the replies guyz il try that out now Quote Link to comment https://forums.phpfreaks.com/topic/197009-php-xpath-query-xml/#findComment-1034381 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.