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

Tricky XPath query

Hi all, I've just changed the structure of my XML file and now I need
to construct an XPathNavigator object that uses tags from two
different levels in the XML file.

For example:

<someTag>
<innerTagA>
<innerInnerTagA>
<innerInnerInnerTagA>
Some Data That Belongs Here
</innerInnerInnerTagA>
<innerInnerInnerTagB>
Some Data that Belongs More Specifically Here
</innerInnerInnerTagB>
</innerInnerTagA>
<innerInnerTagB>
<innerInnerInnerTagZ>
This Data should really go here
</innerInnerInnerTagZ>
</innerInnerTagB>
</innerTagA>
<innerTagA>
<innerInnerTagA>
<innerInnerInnerTagA>
This is another node with some Data That Belongs Here
</innerInnerInnerTagA>
<innerInnerInnerTagB>
Still another node with some Data that Belongs More
Specifically Here
</innerInnerInnerTagB>
</innerInnerTagA>
<innerInnerTagB>
<innerInnerInnerTagZ>
Another Node with the data that should really go here
</innerInnerInnerTagZ>
</innerInnerTagB>
</innerTagA>
</someTag>

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

Dim iterator As XPathNodeIterator

iterator = nav.Select("/someTag/innerTagA/innerInnerTagA[innerInnerInnerTagB
= '" + someVariable + "'] and
/someTag/innerTagA/innerInnerTagB[innerInnerInnerTagZ = '" + secondVar
+ "']")
---------------------------------------------------
Initially, both innerInnerInnerTagB and innerInnerInnerTagZ fell under
the same node/tag - so I just used the code below:

iterator = nav.Select("/someTag/innerTagA/innerInnerTagA[innerInnerInnerTagB
= '" + someVariable + "' and innerInnerInnerTagZ = '" + anotherVar +
"']")

Will this XPath query work:
"/someTag/innerTagA/innerInnerTagA[innerInnerInnerTagB = '" +
someVariable + "'] and
/someTag/innerTagA/innerInnerTagB[innerInnerInnerTagZ = '" + secondVar
+ "']"

AND/OR
is there a better way of formulating the query?

Thanks,
Novice
Nov 12 '05 #1
2 1273
It's hard to tell what you are trying to do and the format of your XML file
is hard to read. Can you simplify the XML file and describe what elements
you want to access? Some of the queries you wrote probably don't do what you
think but since I'm not sure what you want to do I can't be a 100% sure.

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

"Novice" <6t**@qlink.queensu.ca> wrote in message
news:b8**************************@posting.google.c om...
Hi all, I've just changed the structure of my XML file and now I need
to construct an XPathNavigator object that uses tags from two
different levels in the XML file.

For example:

<someTag>
<innerTagA>
<innerInnerTagA>
<innerInnerInnerTagA>
Some Data That Belongs Here
</innerInnerInnerTagA>
<innerInnerInnerTagB>
Some Data that Belongs More Specifically Here
</innerInnerInnerTagB>
</innerInnerTagA>
<innerInnerTagB>
<innerInnerInnerTagZ>
This Data should really go here
</innerInnerInnerTagZ>
</innerInnerTagB>
</innerTagA>
<innerTagA>
<innerInnerTagA>
<innerInnerInnerTagA>
This is another node with some Data That Belongs Here
</innerInnerInnerTagA>
<innerInnerInnerTagB>
Still another node with some Data that Belongs More
Specifically Here
</innerInnerInnerTagB>
</innerInnerTagA>
<innerInnerTagB>
<innerInnerInnerTagZ>
Another Node with the data that should really go here
</innerInnerInnerTagZ>
</innerInnerTagB>
</innerTagA>
</someTag>

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

Dim iterator As XPathNodeIterator

iterator = nav.Select("/someTag/innerTagA/innerInnerTagA[innerInnerInnerTagB = '" + someVariable + "'] and
/someTag/innerTagA/innerInnerTagB[innerInnerInnerTagZ = '" + secondVar
+ "']")
---------------------------------------------------
Initially, both innerInnerInnerTagB and innerInnerInnerTagZ fell under
the same node/tag - so I just used the code below:

iterator = nav.Select("/someTag/innerTagA/innerInnerTagA[innerInnerInnerTagB = '" + someVariable + "' and innerInnerInnerTagZ = '" + anotherVar +
"']")

Will this XPath query work:
"/someTag/innerTagA/innerInnerTagA[innerInnerInnerTagB = '" +
someVariable + "'] and
/someTag/innerTagA/innerInnerTagB[innerInnerInnerTagZ = '" + secondVar
+ "']"

AND/OR
is there a better way of formulating the query?

Thanks,
Novice

Nov 12 '05 #2
I will try to reduce the complexity of my question
For example
<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

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 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

Thanks for any suggestions
Novic
----- Dare Obasanjo [MSFT] wrote: ----

It's hard to tell what you are trying to do and the format of your XML fil
is hard to read. Can you simplify the XML file and describe what element
you want to access? Some of the queries you wrote probably don't do what yo
think but since I'm not sure what you want to do I can't be a 100% sure

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

"Novice" <6t**@qlink.queensu.ca> wrote in messag
news:b8**************************@posting.google.c om..
Hi all, I've just changed the structure of my XML file and now I nee
to construct an XPathNavigator object that uses tags from tw
different levels in the XML file
For example
<someTag>><innerTagA>><innerInnerTagA>><innerInn erInnerTagA>> Some Data That Belongs Her</innerInnerInnerTagA>><innerInnerInnerTagB>> Some Data that Belongs More Specifically Her
</innerInnerInnerTagB>></innerInnerTagA>><innerInnerTagB>><innerInnerInnerT agZ>> This Data should really go her
</innerInnerInnerTagZ>></innerInnerTagB>></innerTagA>>>><innerTagA>><innerInnerTagA>><innerIn nerInnerTagA>> This is another node with some Data That Belongs Her
</innerInnerInnerTagA>><innerInnerInnerTagB>> Still another node with some Data that Belongs Mor
Specifically Her
</innerInnerInnerTagB>></innerInnerTagA>><innerInnerTagB>><innerInnerInnerT agZ>> Another Node with the data that should really go her
</innerInnerInnerTagZ>></innerInnerTagB>></innerTagA>></someTag>>> My idea is to do something like this
--------------------------------------------------
Dim nav As XPathNavigator = doc.CreateNavigator(
Dim iterator As XPathNodeIterato
iterator

nav.Select("/someTag/innerTagA/innerInnerTagA[innerInnerInnerTag = '" + someVariable + "'] an
/someTag/innerTagA/innerInnerTagB[innerInnerInnerTagZ = '" + secondVa
+ "']"
--------------------------------------------------
Initially, both innerInnerInnerTagB and innerInnerInnerTagZ fell unde
the same node/tag - so I just used the code below
iterator
nav.Select("/someTag/innerTagA/innerInnerTagA[innerInnerInnerTag = '" + someVariable + "' and innerInnerInnerTagZ = '" + anotherVar
"']"
Will this XPath query work

"/someTag/innerTagA/innerInnerTagA[innerInnerInnerTagB = '"
someVariable + "'] an
/someTag/innerTagA/innerInnerTagB[innerInnerInnerTagZ = '" + secondVa
+ "']
AND/O

is there a better way of formulating the query
Thanks

Novic


Nov 12 '05 #3

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

Similar topics

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...
3
by: Novice | last post by:
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...
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:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.