Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Adding comment above root Node using DOM

Reply
Thread Tools

Adding comment above root Node using DOM

 
 
Jay Sartoris
Guest
Posts: n/a
 
      10-18-2004
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
 
Reply With Quote
 
 
 
 
Tjerk Wolterink
Guest
Posts: n/a
 
      10-18-2004
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.
 
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
We are currently buying Foundy Networks - primarily NetIron MLX andXMR but are also looking for BigIron RX, ServerIron WMS7, and FastIronFESX's. If you have the above or have access to the above from a clientlooking ro recover value, please sen Network/Software Buyer Cisco 1 07-30-2010 01:25 AM
Problem updating an attribute that appears in both root node and child node! Tedros.G@googlemail.com XML 1 05-08-2007 11:32 AM
How to set the node indent property between the parent node and the leaf node viveknatani@gmail.com ASP .Net 0 02-13-2006 07:11 PM
Adding comment above root Node using DOM Jay Sartoris XML 1 10-18-2004 08:38 PM
[HELP] Create a DOM using a node from another node yio@free.fr Java 0 07-16-2003 12:30 PM



Advertisments