473,386 Members | 1,753 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,386 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 1515
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.