Bhat wrote: > > Hi, > > I have written a small function that dumps portions of the DOM tree > (rooted at nodes with the specified tag name) to a file [see below]. > Obviously the output file does not have a root node. How can I make the > output file a proper XML file (with a single root node)? I have tried a > few things, but nothing seems to work. My function follows: >
Here's what I did: First I created a new DOM document using the DOMImplementation::createDocument() method. For this, I had to provide the name of the root node. I traversed the original XML file and when I found the DOMNodes with the desired tag name (in the original XML file), I did a deep cloning of the nodes [using DOMNode::cloneNode(true)]. Then I tried the following options (all unsuccessful): 1). I appended the cloned nodes as a child to the new DOM document, using the appendChild() method. This caused an exception to be thrown (sadly cannot decipher the exception yet) 2). I obtained the root node of the new XML document , using the getDocumentElement() method, and tried to append the cloned nodes to the root node. Again, this caused an exception to be thrown (sadly cannot decipher the exception yet) 3). I imported the cloned nodes into the new DOM document, using the DOMDocument::importNode(DOMNode*, true) call. This time there was no exception, but the subtrees rooted at the cloned nodes dif not get attached at all. Any help will be appreciated. Thanks, Bhat -- View this message in context: http://www.nabble.com/Carving-out-a-subset-of-XML-content-into-a-separate-XML-file-tp14627707p14628251.html Sent from the Xerces - C - Users mailing list archive at Nabble.com.
