Re: [xml] How to creata one big DOM from Multiple DOMS



On Tue, 2005-10-11 at 13:28 -0400, Daniel Veillard wrote:
On Tue, Oct 11, 2005 at 12:16:39PM -0500, Vedantam, Pavan wrote:

Hi,
I am using Libxml2 to parse the xml documents and build DOMS, I would like
to know if there is a provision for linking the DOMS so that all the DOMS
are under one ROOT ?,

  not really.

i.e I should be able to traverse the DOMS through one
starting point, just like a tree.

  you could move the element roots under the new top, but you should
first either disable dictionaries at parsing time or make sure all 
document are parsed with the same dictionnary (which is best done
by reusing the same parser context for all parses)

Daniel

Optionally you could try (and test) some new functions in
tree.c.

Assuming we have:
A-doc with document element A-elem
B-doc with document element B-elem
the destination C-doc with document element C-elem

/* Move A-elem to C-doc. */
xmlDOMWrapAdoptNode(NULL, A-doc, A-elem, C-doc, C-elem, 0);
xmlAddChild(C-elem, A-elem);

... and the same procedure for B-elem.

This is designed to:
- handle docs with different/none string dictionaries
- handle ID-attributes
- handle out-of-scope namespace declarations (xmlNs)

However, it will be slower than Daniel's solution, since
the moved branch needs to be fully traversed and the
strings to be reallocated if different dictionaries are
used.

The xmlDOM... functions are relatively new, so we'll be happy
to have them better tested.

Regards,

Kasimier





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