473,324 Members | 2,193 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,324 software developers and data experts.

Xpath Query

Hi All

Couldn't find an xpath specifig UG, so I'm posting this here.

I have XML in the following structure:

<Assignments>
<Assignment>
<ID>123</ID>
<Description>Test Assignment 1</Description>
<DueDate>2006/10/10</DueDate>
<Tasks>
<Task>
<ID>1</ID>
<Description>Task 1</Description>
</Task>
<Task>
<ID>2</ID>
<Description>Task 2</Description>
</Task>
<Task>
<ID>3</ID>
<Description>Task 3</Description>
</Task>
</Tasks>
</Assignment>
<Assignment>
<ID>456</ID>
<Description>Test Assignment 2</Description>
<DueDate>2006/10/12</DueDate>
<Tasks>
<Task>
<ID>4</ID>
<Description>Task 4</Description>
</Task>
<Task>
<ID>5</ID>
<Description>Task 5</Description>
</Task>
<Task>
<ID>6</ID>
<Description>Task 6</Description>
</Task>
</Tasks>
</Assignment>
<Assignment>
<ID>789</ID>
<Description>Test Assignment 3</Description>
<DueDate>2006/10/15</DueDate>
</Assignment>
</Assignments>

As you can see, not all Assignment Nodes have a Tasks node. I require
an XPATH query that will return all Assignments that have Tasks, but
the result should only contain the Assignment's ID and the Tasks node.
For example, the above XML should be returned as:

<Assignment>
<ID>123</ID>
<Tasks>
<Task>
<ID>1</ID>
<Description>Task 1</Description>
</Task>
<Task>
<ID>2</ID>
<Description>Task 2</Description>
</Task>
<Task>
<ID>3</ID>
<Description>Task 3</Description>
</Task>
</Tasks>
</Assignment>
<Assignment>
<ID>456</ID>
<Tasks>
<Task>
<ID>4</ID>
<Description>Task 4</Description>
</Task>
<Task>
<ID>5</ID>
<Description>Task 5</Description>
</Task>
<Task>
<ID>6</ID>
<Description>Task 6</Description>
</Task>
</Tasks>
</Assignment>

Thanks.

Sep 21 '06 #1
3 1476
<co***********@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
Hi All

Couldn't find an xpath specifig UG, so I'm posting this here.

I have XML in the following structure:
....
As you can see, not all Assignment Nodes have a Tasks node. I require
an XPATH query that will return all Assignments that have Tasks, but
the result should only contain the Assignment's ID and the Tasks node.
For example, the above XML should be returned as:

<Assignment>
<ID>123</ID>
<Tasks>
<Task>
<ID>1</ID>
<Description>Task 1</Description>
</Task>
<Task>
<ID>2</ID>
<Description>Task 2</Description>
</Task>
<Task>
<ID>3</ID>
<Description>Task 3</Description>
</Task>
</Tasks>
</Assignment>
I think that it isn't an XPath query you need, but rather an XSL
transformation. This transformation would be driven by an XPath expression
like //Assignment[Tasks].

John
Sep 21 '06 #2

John Saunders wrote:
>
I think that it isn't an XPath query you need, but rather an XSL
transformation. This transformation would be driven by an XPath expression
like //Assignment[Tasks].

John
Hi John, thanks for the reply.

I really was hoping to do this with one XPath expression.
//Assignment[Tasks] is halfway there as it only returns Assignments
that contain Tasks, but it also brings back the entire Assignment Node,
and I only want the ID and the Tasks Node.

Any ideas?

Sep 21 '06 #3


co***********@gmail.com wrote:
I really was hoping to do this with one XPath expression.
//Assignment[Tasks] is halfway there as it only returns Assignments
that contain Tasks, but it also brings back the entire Assignment Node,
and I only want the ID and the Tasks Node.
XPath does not change the structure of the of the original document, you
need a stylesheet to do that.
What you can do with XPath is select the Assignment elements you are
looking for with one expression, then use relative XPath expressions to
select the child nodes you are looking for.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sep 21 '06 #4

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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.