Comments in XML

A

Adam Badura

Are comments in XML treated by parser (regarding the value of the
enclosing element) as nothing or as a whitespace? In the example:

<elem>some text<?-- a comment -->some more text</elem>

the contents of "elem" is "some textsome more text", or maybe "some
text some more text" or even "some text[unspecified whitespace]some
more text"?

How does it work for example with XPath when comparing element's value
to an arbitrary string?

I read the specification (http://www.w3.org/TR/REC-xml/#sec-comments)
however I am not entirely sure.

Adam Badura
 
A

Adam Badura

<elem>some text<?-- a comment -->some more text</elem>

Obviously I made a mistake in the comment - as it is not a comment.
Proper example must look like:

<elem>some text<!-- a comment -->some more text</elem>

Adam Badura
 
M

Martin Honnen

Adam said:
Are comments in XML treated by parser (regarding the value of the
enclosing element) as nothing or as a whitespace? In the example:

<elem>some text<?-- a comment -->some more text</elem>

the contents of "elem" is "some textsome more text", or maybe "some
text some more text" or even "some text[unspecified whitespace]some
more text"?

How does it work for example with XPath when comparing element's value
to an arbitrary string?

XPath defines the string value of element nodes here:
http://www.w3.org/TR/xpath#element-nodes
"The string-value of an element node is the concatenation of the
string-values of all text node descendants of the element node in
document order"
so only the two text nodes "some text" and "some more text" constitute
the string value of the element.
 
J

Joe Kesselman

XPath defines the string value of element nodes here:
http://www.w3.org/TR/xpath#element-nodes
"The string-value of an element node is the concatenation of the
string-values of all text node descendants of the element node in
document order"
so only the two text nodes "some text" and "some more text" constitute
the string value of the element.

In other words, the value is the string "some textsome more text".
 
H

Hermann Peifer

Adam said:
Are comments in XML treated by parser (regarding the value of the
enclosing element) as nothing or as a whitespace?

I would guess is that all (serious) XML parsers treat comments as comments.

Hermann
 
Joined
May 15, 2010
Messages
5
Reaction score
0
Parsers and comments

Hello

A very quick test would have answered the question. try this xsl (uses built-in templates) on your xml file:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="...">
</xsl:stylesheet>

The result is a firefox is exactly:
some text some more text

regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top