Re: [xml] query - append DOM tree, identify leaf node

Senthil Nathan wrote:
1. Suppose if I have a pointer xmlDoc *doc1 to a DOM tree, built using xmlReadFile( ) or xmlParseFile( ) for file1.xml.
    Is it possible to add another DOM tree to this existing tree?
Like, if *doc2 points to another DOM tree of file2.xml, can this be appended to the *doc1.

Have a look at the tree module API documentation

xmlNodePtr xmlDocCopyNode(const xmlNodePtr node,
  xmlDocPtr doc,
  int extended)

You can then append the node to its new parent in doc1 with xmlAddChild

2. Using xmlXPathEvalExpression( ), I could search for a tree structure exists in the DOM tree or not.
    But how do I find that is the leaf node.

With leaf node I assume you mean an element node that has only text or attribute children but no other element children. A way of doing this in XPath is like this:


Which reads a select all elements E such that the count of element children of E is zero.

You can also traverse the tree with the tree api and check whether a node has no children of node-type element, but I find using XPath much more convenient


Sun Microsystems                Lars Oppermann <lars oppermann sun com>
Nagelsweg 55                    Software Engineer
20097 Hamburg, Germany          Phone: +49 40 23646 959             Fax:   +49 40 23646 550
Sitz der Gesellschaft: Sun Microsystems GmbH, Sonnenallee 1,
D-85551 Kirchheim-Heimstetten, Amtsgericht Muenchen: HRB 161028
Geschaeftsfuehrer: Wolfgang Engels, Dr. Roland Boemer
Vorsitzender des Aufsichtsrates: Martin Haering

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