Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

i wonder if there is a simple xpath query to retrieve a list of book IDs whose note's 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.

Posted

Following xpath query returns all Book elements which child CATEGORIES element

contains string "2":

 

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

 

i wonder if there is a simple xpath query to retrieve a list of book IDs whose note's 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.

Posted

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

 

Following xpath query returns all Book elements which child CATEGORIES element

contains string "2":

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...