Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Comments in XML

Reply
Thread Tools

Comments in XML

 
 
Adam Badura
Guest
Posts: n/a
 
      04-22-2009
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
 
Reply With Quote
 
 
 
 
Adam Badura
Guest
Posts: n/a
 
      04-22-2009
> <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
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-22-2009
Adam Badura wrote:
> 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.


--

Martin Honnen
http://msmvps.com/blogs/martin_honnen/
 
Reply With Quote
 
Joe Kesselman
Guest
Posts: n/a
 
      04-22-2009
>> <elem>some text<?-- a comment -->some more text</elem>
>
> 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".
 
Reply With Quote
 
Hermann Peifer
Guest
Posts: n/a
 
      04-24-2009
Adam Badura wrote:
> 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
 
Reply With Quote
 
aljar aljar is offline
Junior Member
Join Date: May 2010
Posts: 5
 
      05-15-2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A program to replace all JS comments with JSP comments in jsp files tungchau81@yahoo.com Javascript 4 06-03-2006 02:00 PM
A program to replace all JS comments with JSP comments in jsp files tungchau81@yahoo.com Java 0 06-02-2006 06:35 AM
Comments format: comments extending over multi-line Monk C Programming 10 04-20-2005 05:09 PM
removing comments from XML using Perl XML::DOM user@domain.invalid XML 2 07-15-2004 10:59 AM
Embedding non standard XML tags in XML comments terry ASP .Net 0 07-09-2003 01:27 PM



Advertisments