Re: [xml] extend xml Document with new rootNode



On Sun, 2003-10-19 at 04:45, Marc Giger wrote:
Hi list,

I'm new to libxml and need some help.

What I try to do is to extend an existing xml-document with a new root
node. I've already tried some things...

To illustrate the "problem", the actual xml file is something like the
following:


Call this doc1

<?xml version="1.0"?>
<data>
[snip]
</data>

And the goal should be:


And this is doc2

<?xml version="1.0"?>
<protocol>
  <head>
  </head>
  <body>
    <data>
[snip]
    </data>
  </body>
</protocol>

What is the best way to achieve this?
Perhaps it is relevant that the xml-tree will never be written out to a
file. It's processed "in memory".


From doc1 use xmlDocGetRootElement to get the xmlNodePtr for the root
node (<data>). Then in doc2 walk the tree*, and when you got to <body>,
use xmlAddChildList to add the root node tree bit from doc1.

Cheers,
John

* http://www.xmlsoft.org/tutorial/ar01s04.html or
http://www.xmlsoft.org/example.html for how to walk the tree

-- 
John Fleck
jfleck inkstain net (h)
http://www.inkstain.net

"It makes me mad when someone writes or draws
 something that I can't get right away!"
 - Zippy the Pinhead




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