473,324 Members | 2,370 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.

Writing XPath Help

I am an XPath newbie and I trying to write a query.

I have the below xml

<P C="24709" O="2019307">
<E C="1" O="1" W="True">
<A C="11" V="11" />
<A C="12" V="12" />
<A C="13" V="13" />
</E>
<E C="1" O="2" W="True">
<A C="11" V="21" />
<A C="12" V="22" />
<A C="13" V="23" />
</E>
<E C="1" O="3" W="True">
<A C="11" V="31" />
<A C="12" V="32" />
<A C="13" V="33" />
</E>
<E C="1" O="4" W="True">
<A C="11" V="41" />
<A C="12" V="42" />
<A C="13" V="43" />
</E>
<E C="1" O="5" W="True">
<A C="11" V="51" />
<A C="12" V="52" />
<A C="13" V="53" />
</E>
<A C="24606" V="" />
</P>

I am trying to write an XPath which matches the following:
- E element with a C attribute = 1
- Which contains an A element with attributes equal to the following:
- ((C= 11 and V=11) and (C= 12 and V=12) and (C= 13 and V=13))

In the above example, the first E element node would be returned.

This code is sort of what I want:
//E[@C='1']/A[(@C='11' and @V='11') or (@C='12' and @V='12') or
(@C='13' and @V='13')]

However, this XPath returns values if (@C='13' and @V='13')] is change
to (@C='13' and @V='')]

Basically, I want all or nothing.

I thought the following code would work but it does not:
//E[@C='1']/A[(@C='11' and @V='11') and (@C='12' and @V='12') and
(@C='13' and @V='13')]

Note: If this helps, I really do not care if I get nodes returned. I
really just want a true / false to signify a match was found.

Nov 22 '06 #1
4 1511
Candle wrote:
I thought the following code would work but it does not:
//E[@C='1']/A[(@C='11' and @V='11') and (@C='12' and @V='12') and
(@C='13' and @V='13')]
That expression looks for a single A which has all those combinations,
which is of course impossible and not what you wanted. Try

//E[@C='1'] [A[(@C='11' and @V='11')] and A[(@C='12' and @V='12')] and
A[(@C='13' and @V='13')] ]
>
Note: If this helps, I really do not care if I get nodes returned. I
really just want a true / false to signify a match was found.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Nov 22 '06 #2
Joseph,

Man I love Google Groups.

Worked like a charm.

Thx,

R
Joseph Kesselman wrote:
Candle wrote:
I thought the following code would work but it does not:
//E[@C='1']/A[(@C='11' and @V='11') and (@C='12' and @V='12') and
(@C='13' and @V='13')]

That expression looks for a single A which has all those combinations,
which is of course impossible and not what you wanted. Try

//E[@C='1'] [A[(@C='11' and @V='11')] and A[(@C='12' and @V='12')] and
A[(@C='13' and @V='13')] ]

Note: If this helps, I really do not care if I get nodes returned. I
really just want a true / false to signify a match was found.


--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Nov 22 '06 #3
Candle wrote:
Man I love Google Groups.
Personal pet peeve: They aren't "google groups" -- that's just Google's
interface to newsgroups (which predate google by several decades, and
which can be reached using many other tools).

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Nov 22 '06 #4


On Nov 22, 12:22 pm, Joseph Kesselman <keshlam-nos...@comcast.net>
wrote:
Candle wrote:
Man I love Google Groups.Personal pet peeve: They aren't "google groups" -- that's just Google's
interface to newsgroups (which predate google by several decades, and
which can be reached using many other tools).

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Man I love Google's interface to newsgroups (which predate google by
several decades, and which can be reached using many other tools).

Man I crack myself up.

Nov 22 '06 #5

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

Similar topics

0
by: gael.pegliasco | last post by:
Hi, How are you dear and nice helper :) ? I'm trying to test xpath with this simple program : import xml.dom.minidom from xml.xpath.Context import Context import xml.xpath
3
by: Nelson Minar | last post by:
Could someone help me get started using XPath or XQuery in Python? I'm overwhelmed by all the various options and am lacking guidance on what the simplest way to go is. What library do I need to...
13
by: tfsquare | last post by:
All, I am new to XSLT and having some problems understanding the syntax of XPath which selects nodes in the XML document. Consider this bit of XML, which contains three outer XML elements. ...
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: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
6
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
2
by: Locusta | last post by:
Hello, I would like to use XPATH in a C program to retrieve values from XML documents. Did anyone tried this and can give me some advice? Cheers, Locusta
1
by: Candle | last post by:
I am an XPath newbie and I trying to query. I have the below xml <P C="24709" O="2019307"> <E C="1" O="1" W="True"> <A C="11" V="11" /> <A C="12" V="12" /> <A C="13" V="13" /> </E>
2
by: Monty | last post by:
Despite reading posts in Google, I don't understand XPATH. Can someone help me write an XPATH. From Google I think my problem is that the default namespace does not have a prefix. I can't change...
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
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...
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.