<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="COOKING">
</book>
<book category="WEB_v2">
</book>
<book category="WEB">
</book>
<book category="WEB_v1">
</book>
</bookstore>
I am trying to find an XPath query that will work with the System.Xml.XmlDocument.SelectNodes()
method, that will quite simply return
the two book elements for categories Cooking and WEB_v2.
There are several of these in my actual XML that some will have a _v1 version a _v2 version, up to possibly a _vNN version of the tag. So if the tag has no other versions (like the Cooking category in the above example) I want it, but if other categoried tags exist with a _v# pattern (like WEB category) I only want the "MAX" version or WEB_v2 in this case.
if this isn't possible in XPATH 1.0 that's fine, I can do it via c#, I just wondered if there was.
I first thought using this" "bookstore/books[substring-after(@category, '_v')='' and count(bookstore/book[@category = substring-before(@category, '_v')])=0]" but as you can see the nested @category connections don't work.
Tragically this is .Net so I'm screwed on xpath 2.0 functionality at the moment.
Parsing an XMLDocument so, ya know, wanted to see what I could do using the xpath syntax. (obvious where .net is concerted, not much).