[xml] Is a document a node? Is there a "virtual root node"?



Hi people,

I am totally new to libxml.

I'm wondering if comments can be added to a new document, via xmlCopyNode.

I have an xml document that I want to split up into smaller documents. I want to copy all the comments on the root level, though. like this:

<?xml version="1.0"?>
<!-- hi -->
<root>lots of data...</root>

into this:


<?xml version="1.0"?>
<!-- hi -->
<root>a little data</root>


<?xml version="1.0"?>
<!-- hi -->
<root>another little bit of data</root>


Now, this leads me to wonder, whats the best way to copy these comments. If the document is also a node, or there is some node that owns the XML PI, the "hi" comment and the "root" element, then I'd like access to that node. From the struct's appearance, it looks like the document can be typecasted into an xmlNode.

Basically, I'd like to do all my work with as few functions as possible, so that I can reuse code instead of having to write two methods that do basically the same thing, but just one that can work on the "real root node" (the invisible root that owns the PI, the visible root and any comments), or any other node.

Otherwise I'd sometimes need to call xmlCopyNode to copy comments, and othertimes call xmlNewDocComment! Why use two functions when you can use one?



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