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.