0
<?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).

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
JaedenRuiner
  • 329
  • 4
  • 18
  • Have you given thought on using LINQ to XML? Probably that may give you good solution compared to plain XPath. – Pankaj Kapare May 18 '15 at 19:57
  • Of course. I said, I _can_ use c#. I wanted to figure out how to do this with xpath if possible. curiosity does not mean stop at the first solution as if it were the only solution. I'm looking to figure out how to nest values within a search via xpath as well: "//tag[starts-with(@attr1, 'X') and not (//li[starts-with(@attr2, @attr1)])]" but attr1 and attr2 are the same attribute in the xml stream. the basic, i've found x, but i don't want any others that "look like x" (typically with a starts-with). I've already solved it with c# code, I curious about xpath variations. – JaedenRuiner May 18 '15 at 20:21
  • @JaedenRuiner For reference : [How to find the max attribute from an XML document using Xpath 1.0](http://stackoverflow.com/questions/8702039/how-to-find-the-max-attribute-from-an-xml-document-using-xpath-1-0) – har07 May 19 '15 at 02:49

0 Answers0