Re: [xml] Document comments



On Wed, Apr 09, 2003 at 01:08:17PM +0000, Bjorn Reese wrote:
Daniel Veillard wrote:

   Hum, I would rather use xmlAddChild(doc, comment) if the root isn't

xmlAddChild() takes an xmlNodePtr, not an xmlDocPtr. If I use root
instead of doc, the comment ends up in the wrong place.

  xmlAddChild((xmlNodePtr) doc, comment)
those kind of operations work on the common part of the node structures.

set yet or if the root is already in place use xmlDocGetRootElement()
and xmlAddPrevSibling(root, comment) .

This does not seem to work. The comment does not appear in the output.

  Hum, strange, checking with python which avoid the compilation phase:

paphio:~ -> python
Python 2.2.1 (#1, Aug 30 2002, 12:15:30)
[GCC 3.2 20020822 (Red Hat Linux Rawhide 3.2-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import libxml2
doc = libxml2.newDoc("1.0")
comment = doc.newDocComment("This is a generated document")
doc.addChild(comment)
<xmlNode (comment) object at 0x81ff744>
doc.serialize()
'<?xml version="1.0"?>\n<!--This is a generated document-->\n'

  that looks fine. Lets create the root node first:

doc = libxml2.newDoc("1.0")
root = doc.newChild(None, "doc", None)
comment = doc.newDocComment("This is a generated document")
root.addPrevSibling(comment)
<xmlNode (comment) object at 0x8130ebc>
doc.serialize()
'<?xml version="1.0"?>\n<!--This is a generated document-->\n<doc/>\n'


   xmlAddPrevSibling() seems to work too ...

   xmlDocSetRootElement() is more expected to be used for elements nodes
for example it will wipe out the old root if it already exists.

I fail to see the purpose of xmlNewDocComment() then.

  I don't see the link between your sentence and mine ...

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]