Groups | Blog | Home
all groups > dotnet xml > april 2004 >

dotnet xml : Tricky XPath query - Part 2



6tc1 NO[at]SPAM qlink.queensu.ca
4/19/2004 12:10:44 PM
Hey all, I've attempted to simplify my question (or at least the XML
that is part of my example in my question):

I have the following XML:
<A>
<B><C><D>
I want to query the data in this node for the element B
</D></C><E>
I also want to query the data in this node for the element B
</E>
</B>
<B><!--Additional data for another B element-->
</B>
</A>

My idea is to do something like this:
---------------------------------------------------
Dim nav As XPathNavigator = doc.CreateNavigator()

Dim iterator As XPathNodeIterator

iterator = nav.Select("/A/B/C[D = '" + someVariable + "'] and /A/B[E =
'" + secondVar + "']")
---------------------------------------------------
Initially, both D and E fell under the same node or tag - so I just
used the code below:
iterator = nav.Select("/A/B/C[D = '" + someVariable + "' and E = '" +
anotherVar + "']")

But now they are at different levels in the node hierarchy (as in the
above example).

Thanks for any suggestions,
Dare Obasanjo [MSFT]
4/19/2004 6:21:23 PM
Your question is still not clear. What node(s) do you expect to get back or
do you simply want to test that both those values exist under a particular B
element?

--
This posting is provided "AS IS" with no warranties, and confers no rights.

[quoted text, click to view]

Novice
4/20/2004 5:46:03 AM
Hey all, I'll try to make my question a little more clear

I have the following XML
<A><B><C><D
I want to query the data in this node for the element
</D></C><E
I also want to query the data in this node for the element
</E></B><B><!--Additional data for another B element--></B></A

Let's say I want to get all the B elements/nodes returned to me that have the following text in the D element
I want to query the data in this node for the element

AN

the following text in the E element
I also want to query the data in this node for the element

My idea is to do something like this
--------------------------------------------------
Dim nav As XPathNavigator = doc.CreateNavigator(
Dim iterator As XPathNodeIterato
iterator = nav.Select("/A/B/C[D = '" + someVariable + "'] and /A/B[E = '" + secondVar + "']"
--------------------------------------------------
Initially, both D and E fell under the same node or tag - so I jus
used the code below
iterator = nav.Select("/A/B/C[D = '" + someVariable + "' and E = '" + anotherVar + "']"

But now they are at different levels in the node hierarchy (as in th
above example) and so the query immediately above will no longer work

Thanks
Novice
4/20/2004 6:41:04 AM
In actual fact, in the XML below
<A><B><C><D
I want to query the data in this node for the element
</D></C><C><D
I don't want this one
</D></C><E
I also want to query the data in this node for the element
</E></B><B><!--Additional data for another B element--></B></A

I will receive two query strings - one that is for element E and another that is for element D

If I find a match in element E (belonging to a B element), I would like to return all C elements in that B element that have a D element that matches. So in the example above, if I had the request for the text in node/element D
I want to query the data in this node for the element

and the request for the text in the node/element E
I also want to query the data in this node for the element

Then I would only return one C element
<C><D
I want to query the data in this node for the element
</D></C

However, I've tried to simplify my question and reduce my overall question to "how to make queries between different levels in the XML hierarchy"

Thanks
AddThis Social Bookmark Button