473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Adding comment above root Node using DOM

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
Jul 20 '05 #1
1 2421
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.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Maersa | last post by:
hi, i'm trying to add "attributes" to some nodes and it works at design time but fails at runtime. XmlDocument doc = new XmlDocument(); XmlElement elem = doc.CreateElement( "root" );...
4
by: ghanley | last post by:
Hi Guys, I need some help with a problem related to the looping through a recordset to display on a tree view control. My table has no Primary key - because duplicates are allowed. ID ...
3
by: Brian Henry | last post by:
If i already have a tree view created, and want to add another new node to it, how would i do so? Is there a way to throught tags or anything? like i have this RootNode | +-- Child 1 +--...
2
by: bg | last post by:
sorry this is way off topic. using _vb6_: i'm trying to add/replace nodes to an xml document via CreateTextNode: xml = "<item>floogle</item>" set newNode = oDom.createTextNode(xml) call...
2
by: scottpet | last post by:
Hi, I want to add a namespace prefix to the root node of an object I am serializing to XML. I have been reading though this article:...
0
by: romcab | last post by:
Hello expert, I would like to ask how can I add a parent node and child node simultaneously. I try this code; //create parent node XmlElement ^elem =...
0
by: theonlydavewilliams | last post by:
Hi there I'm hoping there's an easy answer to a (hopefully) not too long-winded issue... I'm building a C# web client using a proxy wsdl.exe'd from a wsdl file and six schemas, each in a different...
6
by: SQACSharp | last post by:
I'm using the EnumChildWindows API with an EnumChildWndProc callback to populate the treeview. The output will be something similar to spy+ + How can I specify the parent when adding a new node...
0
by: RolfK | last post by:
Hello All, I'm trying to output an XML node tree in COMMENT tags. Processing is done with XSLT2.0. The output schould be avild xml like this: <root> <e c="some element 1"/> <e c="some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.