Simple question, quick answer ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rt-box
Forum Newbie
Posts: 1
Joined: Sat Apr 26, 2008 7:53 am

Simple question, quick answer ?

Post by rt-box »

Hi all

I would like to check this :
I have a valid DOMXPath handler $xpath based on a valid XML DOMDocument, and a string $urlpart.
The XML document has basically this structure :

Code: Select all

<forest>
  <tree id="treeID">
    <url>tree URL</url>
    <branch>
      <url>branch URL 1</url>
    </branch>
    <branch>
       <url>branch URL 2</url>
    </branch>
    ...
   </tree>
   <tree>
     ...
   </tree>
   ...
</forest>
I want $treeid to contain the ID of the <tree> element for which one of the <url> descendants (either the direct child <url> or one <url> of a <branch> element) has the value of $urlpart.
Is the following correct :?:

Code: Select all

 
$treeid = $xpath->query("//tree[.//url[.='{$urlpart}']][1]/@id");
 

Thanks for your help !
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Simple question, quick answer ?

Post by RobertGonzalez »

Have you tried it to see if it is correct?
Post Reply