473,395 Members | 1,915 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,395 software developers and data experts.

XPath on an XmlDataDocument

I have a DataSet I want to work with as Xml using XmlDataDocument. I can't
figure out how to query the resultant Xml using XPath. From the following XML
below, what XPath query will return the list of orders for each Male customer?

Because some tables in my DataSet have >1 foreign key columns, it is not
possible to set up a nested DataRelation for all relationships - a DataTable
can only be the child of at most one nested DataRelation. As a result, the
XmlDataDocument is tricky to navigate because I have to perform "joins" and I
don't know that XPath can do them. If there is no way to do this with XPath,
what would the XSL look like to transform the Xml below so Order appears as a
child element of Customer, in which case the XPath becomes straightforward.
In general, I want to be able to traverse my DataSet using XPath and be able
to follow every DataRelation, regardless of whether it is nested.

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<customer>
<customerName>Justin</customerName>
<gender>Male</gender>
</customer>
<customer>
<customerName>Bob</customerName>
<gender>Male</gender>
</customer>
<customer>
<customerName>Mary</customerName>
<gender>Female</gender>
</customer>
<customer>
<customerName>Erin</customerName>
<gender>Female</gender>
</customer>
<order>
<customerName>Justin</customerName>
<orderNumber>32</orderNumber>
</order>
<order>
<customerName>Justin</customerName>
<orderNumber>74</orderNumber>
</order>
<order>
<customerName>Mary</customerName>
<orderNumber>132</orderNumber>
</order>
<order>
<customerName>Bob</customerName>
<orderNumber>98</orderNumber>
</order>
<order>
<customerName>Erin</customerName>
<orderNumber>204</orderNumber>
</order>
</root>

Oct 12 '06 #1
3 2825


jmagaram wrote:
I have a DataSet I want to work with as Xml using XmlDataDocument. I can't
figure out how to query the resultant Xml using XPath. From the following XML
below, what XPath query will return the list of orders for each Male customer?
This XPath expression
/root/order[customerName = /root/customer[gender = 'Male']/customerName]
selects the order elements where the customerName is equal to a customer
with gender being 'Male'.

XPath can't reorder/restructure the existing document, if you need that
then you need to use an XSLT stylesheet.

Because some tables in my DataSet have >1 foreign key columns, it is not
possible to set up a nested DataRelation for all relationships - a DataTable
can only be the child of at most one nested DataRelation. As a result, the
XmlDataDocument is tricky to navigate because I have to perform "joins" and I
don't know that XPath can do them. If there is no way to do this with XPath,
what would the XSL look like to transform the Xml below so Order appears as a
child element of Customer, in which case the XPath becomes straightforward.
In general, I want to be able to traverse my DataSet using XPath and be able
to follow every DataRelation, regardless of whether it is nested.

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<customer>
<customerName>Justin</customerName>
<gender>Male</gender>
</customer>
<customer>
<customerName>Bob</customerName>
<gender>Male</gender>
</customer>
<customer>
<customerName>Mary</customerName>
<gender>Female</gender>
</customer>
<customer>
<customerName>Erin</customerName>
<gender>Female</gender>
</customer>
<order>
<customerName>Justin</customerName>
<orderNumber>32</orderNumber>
</order>
<order>
<customerName>Justin</customerName>
<orderNumber>74</orderNumber>
</order>
<order>
<customerName>Mary</customerName>
<orderNumber>132</orderNumber>
</order>
<order>
<customerName>Bob</customerName>
<orderNumber>98</orderNumber>
</order>
<order>
<customerName>Erin</customerName>
<orderNumber>204</orderNumber>
</order>
</root>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 12 '06 #2
It works. But how? The 'order[customerName = /root/customer[gender...' part
is confusing. If the text was 'order[customerName = Justin' I'd understand
it. But how can you have a nodeset on the right side of the '='. The '='
seems to be functioning like a set comparison - is the item on the left of
the '=' in the set on the right side. Could you explain how this works?

"Martin Honnen" wrote:
>

jmagaram wrote:
I have a DataSet I want to work with as Xml using XmlDataDocument. I can't
figure out how to query the resultant Xml using XPath. From the following XML
below, what XPath query will return the list of orders for each Male customer?

This XPath expression
/root/order[customerName = /root/customer[gender = 'Male']/customerName]
selects the order elements where the customerName is equal to a customer
with gender being 'Male'.

XPath can't reorder/restructure the existing document, if you need that
then you need to use an XSLT stylesheet.

Because some tables in my DataSet have >1 foreign key columns, it is not
possible to set up a nested DataRelation for all relationships - a DataTable
can only be the child of at most one nested DataRelation. As a result, the
XmlDataDocument is tricky to navigate because I have to perform "joins" and I
don't know that XPath can do them. If there is no way to do this with XPath,
what would the XSL look like to transform the Xml below so Order appears as a
child element of Customer, in which case the XPath becomes straightforward.
In general, I want to be able to traverse my DataSet using XPath and be able
to follow every DataRelation, regardless of whether it is nested.

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<customer>
<customerName>Justin</customerName>
<gender>Male</gender>
</customer>
<customer>
<customerName>Bob</customerName>
<gender>Male</gender>
</customer>
<customer>
<customerName>Mary</customerName>
<gender>Female</gender>
</customer>
<customer>
<customerName>Erin</customerName>
<gender>Female</gender>
</customer>
<order>
<customerName>Justin</customerName>
<orderNumber>32</orderNumber>
</order>
<order>
<customerName>Justin</customerName>
<orderNumber>74</orderNumber>
</order>
<order>
<customerName>Mary</customerName>
<orderNumber>132</orderNumber>
</order>
<order>
<customerName>Bob</customerName>
<orderNumber>98</orderNumber>
</order>
<order>
<customerName>Erin</customerName>
<orderNumber>204</orderNumber>
</order>
</root>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 12 '06 #3


jmagaram wrote:
It works. But how? The 'order[customerName = /root/customer[gender...' part
is confusing. If the text was 'order[customerName = Justin' I'd understand
it. But how can you have a nodeset on the right side of the '='. The '='
seems to be functioning like a set comparison - is the item on the left of
the '=' in the set on the right side. Could you explain how this works?
In
> /root/order[customerName = /root/customer[gender = 'Male']/customerName]
/root/order selects all order elements which are children of the root
element. What follows in square brackets is a predicate that filters out
nodes based on the condition. The condition compares customerName child
element(s) of the order to customerName child elements of customer
elements which have a gender child element with string value 'Male'.

For such a comparison of two node sets the rule

"If both objects to be compared are node-sets, then the comparison
will be true if and only if there is a node in the first node-set and a
node in the second node-set such that the result of performing the
comparison on the string-values of the two nodes is true."

from the XPath specification <http://www.w3.org/TR/xpath#booleans>
holds. So the string value of one of the customerName child elements of
order needs to be equal to the string value of one of the customer name
child elements of the customer elements for which the gender is as
specified.

--

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

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

Similar topics

3
by: Bob | last post by:
Below is some code that use to work. Now it is not and I have yet to figure out why. I want to select the nodes to a nodelist and remove them from the dom. The only thing I can figure is it broke...
5
by: cyphos | last post by:
Hi, I'm trying to display the data from my typed dataset on a page using the Xml web control. I have the following code: Xm1.Document = new XmlDataDocument(ds);
2
by: gonzalez | last post by:
Hi all, How come the following XPath expression doesn't return any nodes? descendant::* Here's how it's called on the document root node: XmlNodeList list =...
3
by: Patrick | last post by:
Dear Ng, after I have loaded am XmlDataDocument file, I try to extract a single node via XmlElement myElem = (XmlElement)this.XmlDataDocument.SelectSingleNode("/Document/Headerdata/myElem");...
2
by: James Ankrom | last post by:
Why does this fail? Dim relResources As New Data.DataRelation("Application_Resources", ..Tables("User_Applications").Columns("Application_id"),...
0
by: Steve | last post by:
I have a dataset. I fill it with two recordsets from SQL queries. Tables are called tblPlanFYSpendingStage, tblSpendingStage.
0
by: pete | last post by:
Hi there, I've just tried the xml / xslt you provided in XmlSpy and it transformed correctly. Have you checked that your transformation code works correctly? Cheers Pete From: "cyphos"...
4
by: Adrian Meyer | last post by:
Hi, On the server I code the following web service: ))] public XmlDataDocument GetTypedXmlDataDocument() { sqlDataAdapter1.Fill(typedDataSet1); XmlDataDocument dataDoc
1
by: Joe | last post by:
Hi Only think I am sure of is that I am doing something wrong :-) Never worked on a xml format like this but what I am trying to do is loop thru L1 get all the possible Companies The go...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.