Saturday, 15 September 2012

XPath, how to select a parent node which has to satisfy two attributes of child 1? -



XPath, how to select a parent node which has to satisfy two attributes of child 1? -

i select b c2attr > 5 on c2 = text2. in xpath, wrote:

a/b[c2 = text2 , c2attr >5]

however, did not give me status both satisfy when c2=text2, c2attr >5. gave me every c2 element has c2attr >5. how should write correctly select b?

for example:

<a> <b> <c1>c1 text</c1> <c2 c2attr="3">text1</c2> <c2 c2attr="8">tex2</c2> <c2 c2attr="50">text3</c2> </b> <b> <c1>c1 text</b1> <c2 c2attr="1">text4</c2> <c2 c2attr="6">tex2</c2> <c2 c2attr="10">text1</c2> </b> </a>

thank much!

you need alter c2 = text2 c2 = 'text2' since you're comparing strings, , add together attribute specifier @ c2attr so:

a/b[c2[text() = 'tex2' , @c2attr > 5]]

also, xml invalid, not sure if typo have <c1> node closed <b1>, , not contain text "text2", it's missing lastly 't' there.

xpath

No comments:

Post a Comment