Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing Comments in XML using XPath

Tags:

xpath

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?

like image 624
Manoj Avatar asked Apr 24 '09 06:04

Manoj


People also ask

How do I comment out XPath?

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.

How do I comment out an element in XML?

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 --&gt; .

Does XML allow commenting elements?

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.


1 Answers

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.

like image 108
Björn Avatar answered Sep 16 '22 19:09

Björn