Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPath query

Reply
Thread Tools

XPath query

 
 
John Smith
Guest
Posts: n/a
 
      06-08-2004
Is it possible using an XPath query to select a child node and all its
parents. e.g.

<a x="1">
<b x="2">
<c x="3"/>
<c x="4"/>
</b>
<b x="5">
<c x="6"/>
<c x="7"/>
</b>
</a>

I want to search for c[@x="4"] and get the the following:
<a x="1">
<b x="2">
<c x="4"/>
</b>
</a>

Is this possible?

Thanks

jon


 
Reply With Quote
 
 
 
 
Richard Tobin
Guest
Posts: n/a
 
      06-08-2004
In article <ca3v43$hjt$(E-Mail Removed)>,
John Smith <(E-Mail Removed)> wrote:

>Is this possible?


No. XPath can only return nodes that exist in the document, but you
want a modified copy of some nodes. If you had an expression that
returned the "a" ancestor, it would return the whole document.

-- Richard
 
Reply With Quote
 
 
 
 
A. Bolmarcich
Guest
Posts: n/a
 
      06-08-2004
In article <ca3v43$hjt$(E-Mail Removed)>, John Smith wrote:
> Is it possible using an XPath query to select a child node and all its
> parents. e.g.
>
> <a x="1">
> <b x="2">
> <c x="3"/>
> <c x="4"/>
> </b>
> <b x="5">
> <c x="6"/>
> <c x="7"/>
> </b>
> </a>
>
> I want to search for c[@x="4"] and get the the following:
> <a x="1">
> <b x="2">
> <c x="4"/>
> </b>
> </a>
>
> Is this possible?


The value of the XPath expression

c[@x="4"]/ancestor-or-self::*

is a node set that contains the elements that you want.
 
Reply With Quote
 
Chris Huebsch
Guest
Posts: n/a
 
      06-08-2004
A. Bolmarcich (Tue, 08 Jun 2004 14:44:27 -0000):
> The value of the XPath expression
>
> c[@x="4"]/ancestor-or-self::*
>
> is a node set that contains the elements that you want.


Does it? I think the result-set will look like that:

=================
<c x="4"/>
---------------
<b x="2">
<c x="3"/>
<c x="4"/>
</b>
---------------
<a x="1">
<b x="2">
<c x="3"/>
<c x="4"/>
</b>
<b x="5">
<c x="6"/>
<c x="7"/>
</b>
</a>
=================


Chris
--
Chris Huebsch www.hübsch-gemacht.de | TU Chemmnitz, Informatik, RNVS
GPG-Encrypted mail welcome! ID:7F2B4DBA | Str. d. Nationen 62, B204
Chemnitzer Linux-Tage 2005, 5.-6.März | D-09107 Chemnitz
http://www.tu-chemnitz.de/linux/tag/ | +49 371 531-1377, Fax -1803
 
Reply With Quote
 
A. Bolmarcich
Guest
Posts: n/a
 
      06-08-2004
In article <(E-Mail Removed)-chemnitz.de>, Chris Huebsch wrote:
> A. Bolmarcich (Tue, 08 Jun 2004 14:44:27 -0000):
>> The value of the XPath expression
>>
>> c[@x="4"]/ancestor-or-self::*
>>
>> is a node set that contains the elements that you want.

>
> Does it? I think the result-set will look like that:

[snip]

As I wrote, it "contains the elements that you want". It does not
contain a tree consisting of only those elements. A program that
uses the results of this XPath expression can construct a tree
consisting only those elements.
 
Reply With Quote
 
Chris Huebsch
Guest
Posts: n/a
 
      06-08-2004
A. Bolmarcich (Tue, 08 Jun 2004 21:07:54 -0000):
> As I wrote, it "contains the elements that you want". It does not
> contain a tree consisting of only those elements. A program that
> uses the results of this XPath expression can construct a tree
> consisting only those elements.


Ok. If he has to use an other program, then he might simply use
c[@x="4"] and then use the parent-node-reference of each element
recursively towards the documentNode.


Chris
--
Chris Huebsch www.hübsch-gemacht.de | TU Chemmnitz, Informatik, RNVS
GPG-Encrypted mail welcome! ID:7F2B4DBA | Str. d. Nationen 62, B204
Chemnitzer Linux-Tage 2005, 5.-6.März | D-09107 Chemnitz
http://www.tu-chemnitz.de/linux/tag/ | +49 371 531-1377, Fax -1803
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
xpath query query David Gordon XML 2 05-18-2005 03:33 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments