473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XPath query

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
Jul 20 '05 #1
5 1894
In article <ca**********@titan.btinternet.com>,
John Smith <us*******@ntlworld.com> 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
Jul 20 '05 #2
In article <ca**********@titan.btinternet.com>, 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.
Jul 20 '05 #3
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
Jul 20 '05 #4
In article <sl**************************@chu.informatik.tu-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.
Jul 20 '05 #5
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
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joshua Beall | last post by:
Hi All, I have a task that should be very simple but I'm running into trouble. All I want to do is query a document using XPath, and save the resulting XML in a string. Here's that I am trying...
6
by: 0wl | last post by:
Hi, I am trying to get the value of child from xmlstr = """<p:root xmlns:p="http://tempuri.org/string"><p:child DataType="String">Hellpppp</p:child></p:root>""" using...
8
by: Terry P | last post by:
Are there any tools (java classes, tag libraries) which can translate xpath statements into a SQL query? Given an xpath query which has a predicate that filters node values or attributes, I want...
3
by: gfrommer | last post by:
Hello Everyone, I'm writing a server in java, and I want the clients to pass me an XPath query. I want the XPath queries to be in a specific format though, I'm pretty sure it's valid but I want...
7
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned...
10
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
6
by: dotnetnoob | last post by:
i would like to know how i can build xpath expression dynamiclly. let's say i have a following xml file: <EventEnrollment InstanceNumber = "675"> <EventSource> <ObjectReference...
3
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml...
2
by: =?Utf-8?B?RGlmZmlkZW50?= | last post by:
Hello All, I am trying to construct an XPath query against an XML document, for a requirement that I have. Below is the XML fragment: <SUBMISSIONS> <SUBMISSION YEAR="2004"> <MONTH...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.