xpath question.

alanchinese

Well-known member
Joined
Jan 12, 2005
Messages
58
i wonder if there is a simple xpath query to retrieve a list of book IDs whose notes Descendants evaluates a dynamic condition to be true. to make it simple, consider the following XML.
<BOOKS>
<BOOK ID=1234>
<CATEGORIES>1,2,9</CATEGORIES>
</BOOK>
<BOOK ID=2333>
<CATEGORIES>2,7,8</CATEGORIES>
</BOOK>
<BOOK ID=5555>
<CATEGORIES>1,7,8</CATEGORIES>
</BOOK>
</BOOKS>

Dim sRule1 as String = "(contains//CATEGORIES, 2)"
Dim sRule2 as String = "(contains//CATEGORIES, 8)"
when sRule1 is used, IDs 1234, 2333 would be returned.
when sRule2 is used, IDs 2333, 5555 would be returned.
 
Following xpath query returns all Book elements which child CATEGORIES element
contains string "2":

Code:
"//Book[contains(CATEGORIES/text(), 2)]"

alanchinese said:
i wonder if there is a simple xpath query to retrieve a list of book IDs whose notes Descendants evaluates a dynamic condition to be true. to make it simple, consider the following XML.
<BOOKS>
<BOOK ID=1234>
<CATEGORIES>1,2,9</CATEGORIES>
</BOOK>
<BOOK ID=2333>
<CATEGORIES>2,7,8</CATEGORIES>
</BOOK>
<BOOK ID=5555>
<CATEGORIES>1,7,8</CATEGORIES>
</BOOK>
</BOOKS>

Dim sRule1 as String = "(contains//CATEGORIES, 2)"
Dim sRule2 as String = "(contains//CATEGORIES, 8)"
when sRule1 is used, IDs 1234, 2333 would be returned.
when sRule2 is used, IDs 2333, 5555 would be returned.
 
Thankx for the tips!
but I cannot modify the Rules, so rule1 and rule2 cannot be modified to obtain a list of Book elements.
any ways to plug in the rule strings into the xpath?
also, what would the above xpath be if i CATEGORIES is a decendant element instead of a direct child?
again, thankx a lot

Igor Sukhov said:
Following xpath query returns all Book elements which child CATEGORIES element
contains string "2":

Code:
"//Book[contains(CATEGORIES/text(), 2)]"
 
Back
Top