How to access the comments inside the XML document using XPath?
For example:
<table> <length> 12 </length> <!--Some comment here--> </table>
I want to access the "Some comment here".
Thanks...
EDIT: I am using MSXML DOM ActiveX and the command comment() seems to be failing... Any idea why?
Comments are allowed in an XPath expression, wherever nonessential whitespace is allowed. Comments do not affect expression processing. A comment is a string that is delimited by the symbols (: and :) . The following example is a comment in XPath: (: This is a comment.
An XML comment encountered outside the document type declaration is represented by the Comment value syntax element. It contains the comment text from the XML message. If the value of the element contains the character sequence --> , the sequence is replaced with the text --> .
Allows notes and other human readable comments to be included within an XML file. XML Parsers should ignore XML comments. Some constrains govern where comments may be placed with an XML file.
With the path
/foo/bar/comment()
you can select all comments in the /foo/bar element. May depend on your language of choice, of course. But generally this is how you do it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With