Re: [xml] Document comments



On Wed, Apr 09, 2003 at 12:00:33PM +0000, Bjorn Reese wrote:
I am using the <libxml/tree.h> interface to create an XML document.
I need to add comments before the root element; something like this:

<?xml version="1.0"?>
<!--A document comment-->
<root/>

It seems that this can be achieved if I create a comment using
xmlNewDocComment() and then add it to the document with
xmlDocSetRootElement() before I add the actual root element.

I just wanted to verify that this is the correct way to add
document comments.

   Hum, I would rather use xmlAddChild(doc, comment) if the root isn't
set yet or if the root is already in place use xmlDocGetRootElement()
and xmlAddPrevSibling(root, comment) .
   xmlDocSetRootElement() is more expected to be used for elements nodes
for example it will wipe out the old root if it already exists.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]