Using XPath to access comments a flat hierachy
Posted
by Sebastian
on Stack Overflow
See other posts from Stack Overflow
or by Sebastian
Published on 2010-04-14T09:17:34Z
Indexed on
2010/04/14
9:23 UTC
Read the original article
Hit count: 380
I have a given XML document (structure can not be changed) and want to get the comments that are written above the nodes. The document looks like this:
<!--Some comment here-->
<attribute name="Title">Book A</attribute>
<attribute name="Author">
<value>Joe Doe</value>
<value>John Miller</value>
</attribute>
<!--Some comment here-->
<attribute name="Code">1</attribute>
So comments are optional, but if there is one, I want to get the comment above each attribute.
Using /*/comment()[n]
would give me comment n, but for n=2 I would naturally get the comment of the third attribute, so there is no connection between attributes and comments Any ideas?
Thanks
© Stack Overflow or respective owner