Comments in XML

Discussion in 'XML' started by Adam Badura, Apr 22, 2009.

  1. Adam Badura

    Adam Badura Guest

    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
    Adam Badura, Apr 22, 2009
    #1
    1. Advertising

  2. Adam Badura

    Adam Badura Guest

    > <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
    Adam Badura, Apr 22, 2009
    #2
    1. Advertising

  3. 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/
    Martin Honnen, Apr 22, 2009
    #3
  4. >> <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".
    Joe Kesselman, Apr 23, 2009
    #4
  5. 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
    Hermann Peifer, Apr 24, 2009
    #5
  6. Adam Badura

    aljar

    Joined:
    May 15, 2010
    Messages:
    5
    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
    aljar, May 15, 2010
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. terry
    Replies:
    0
    Views:
    375
    terry
    Jul 9, 2003
  2. Replies:
    2
    Views:
    1,149
    Tom Regner
    Jul 15, 2004
  3. Replies:
    0
    Views:
    1,094
  4. Monk
    Replies:
    10
    Views:
    1,435
    Michael Wojcik
    Apr 20, 2005
  5. Replies:
    4
    Views:
    573
    Dr John Stockton
    Jun 3, 2006
Loading...

Share This Page