Re: Possible using XPath?
| From: | Robin Vickery | Date: | Thu, 27 Mar 2008 16:26:27 +0000 |
| Subject: | Re: Possible using XPath? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-272179@lists.php.net to get a copy of this message | ||
On 27/03/2008, Christoph Boget <christoph.boget@gmail.com> wrote:
> Let's say I have the following structure:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
> <child id="c1">
> <child id="gc1">
> <child id="ggc1"/>
> <child id="ggc2"/>
> </child>
> <child id="gc2">
> <child id="ggc3"/>
> <child id="ggc4"/>
> </child>
> </child>
> <child id="c2">
> <child id="gc3">
> <child id="ggc5"/>
> <child id="ggc6"/>
> </child>
> <child id="gc4">
> <child id="ggc7"/>
> <child id="ggc8"/>
> </child>
> </child>
> </root>
>
> By using the following XPath query
>
> //child[@id="gc3"]/child
>
> I can get the child nodes of "gc1". But what I'd really like to get
> is the sub branch/path going back to the root. So instead of just
> returning the two nodes
>
> <child id="ggc5"/>
> <child id="ggc6"/>
>
> I'd like to be able to return the sub branch/path
>
> <root>
> <child id="c2">
> <child id="gc3">
> <child id="ggc5"/>
> <child id="ggc6"/>
> </child>
> </child>
> </root>
>
> Is that possible? Or is this something I'd have to do programatically
> using the nodes returned by the XPath query? Basically, I'm just
> trying to get a fragment of the larger xml document...
//child[@id='gc3']/child/ancestor-or-self::*
-robin