Page 1 of 1

Simple question, quick answer ?

Posted: Sat Apr 26, 2008 8:06 am
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 !

Re: Simple question, quick answer ?

Posted: Sat Apr 26, 2008 11:40 am
by RobertGonzalez
Have you tried it to see if it is correct?