alanchinese Posted July 24, 2006 Posted July 24, 2006 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. Quote
Igor Sukhov Posted July 25, 2006 Posted July 25, 2006 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. Quote
alanchinese Posted July 25, 2006 Author Posted July 25, 2006 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')]" Quote
Igor Sukhov Posted July 26, 2006 Posted July 26, 2006 What do you mean by "rules" ? How do you apply/convert your "rules" to actual XPath expressions ? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.