Writing XPath Help

C

Candle

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

Joseph Kesselman

Candle said:
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')] ]
 
C

Candle

Joseph,

Man I love Google Groups.

Worked like a charm.

Thx,

R
Joseph said:
Candle said:
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.
 
J

Joseph Kesselman

Candle said:
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).
 
C

Candle

interface to newsgroups (which predate google by several decades, and
which can be reached using many other tools).

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Blue J Ciphertext Program 2
Translater + module + tkinter 1
Machine Learning.. Endless Struggle 3
My Status, Ciphertext 2
Tic Tac Toe Game 2
Help with code 0
Taskcproblem calendar 4
Help please 8

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top