Adding comment above root Node using DOM

Discussion in 'XML' started by Jay Sartoris, Oct 18, 2004.

  1. Jay Sartoris

    Jay Sartoris Guest

    Hi,

    I'm adding a node to my XML document using DOM. When I serialize it,
    I lose my comments that are above my root node. I've created an
    OutputFormat obect and set the setOmitComments(false) but it still
    removes the comments between my DOCTYPE tag and my root tag. I'm
    pretty sure that the reason is that only the text within the root tags
    are serialized. My comments within the root tags are still there
    after serialization, just the comment outside of the root tags are
    removed.

    Here is a snippet of my xml doc:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plugin SYSTEM "plugin.dtd">
    <!--
    // my comment here
    -->

    <plugin id="plugin1">
    ..
    ..
    ..
    </plugin>

    Does anyone have any idea what I'm doing wrong?

    Thanks in advance,
    Jay
     
    Jay Sartoris, Oct 18, 2004
    #1
    1. Advertising

  2. Jay Sartoris wrote:

    > Hi,
    >
    > I'm adding a node to my XML document using DOM. When I serialize it,
    > I lose my comments that are above my root node. I've created an
    > OutputFormat obect and set the setOmitComments(false) but it still
    > removes the comments between my DOCTYPE tag and my root tag. I'm
    > pretty sure that the reason is that only the text within the root tags
    > are serialized. My comments within the root tags are still there
    > after serialization, just the comment outside of the root tags are
    > removed.
    >
    > Here is a snippet of my xml doc:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <!DOCTYPE plugin SYSTEM "plugin.dtd">
    > <!--
    > // my comment here
    > -->
    >
    > <plugin id="plugin1">
    > .
    > .
    > .
    > </plugin>
    >
    > Does anyone have any idea what I'm doing wrong?
    >
    > Thanks in advance,
    > Jay


    You are doing it alright.
    The XML Specifications says:

    --
    [Definition: Comments may appear anywhere in a document outside other
    markup; in addition, they may appear within the document type
    declaration at places allowed by the grammar. They are not part of the
    document's character data; an XML processor may, but need not, make it
    possible for an application to retrieve the text of comments. For
    compatibility, the string "--" (double-hyphen) must not occur within
    comments.] Parameter entity references are not recognized within comments.
    --

    Note the following sentence:
    an XML processor may, but need not, make it possible for an application
    to retrieve the text of comments.

    So your DOM-library does not support retrieving comments outside the
    root node i think. And that is alright (may, but need not), maybe you
    should contact the author of the dom-package, and ask for this feature
    you want.
     
    Tjerk Wolterink, Oct 18, 2004
    #2
    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. Replies:
    0
    Views:
    1,568
  2. Replies:
    0
    Views:
    380
  3. Jay Sartoris
    Replies:
    1
    Views:
    449
    Tjerk Wolterink
    Oct 18, 2004
  4. Tjerk Wolterink
    Replies:
    2
    Views:
    1,458
    Dimitre Novatchev
    Aug 24, 2006
  5. Replies:
    1
    Views:
    576
    Martin Honnen
    May 8, 2007
Loading...

Share This Page