Jump to content

PHP xpath query - xml


prometheos

Recommended Posts

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:)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.