Hi Ferdinand,
Ferdinand Knapitsch wrote:
Am Thu, 10 Apr 2008 13:14:13 +0200 schrieb Ferdinand Knapitsch:
I'm using XERCES-C 2.8 to read a file. It looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!-- comment this -->
<TEST>
<VALUE>
<ONE>textoneONE</ONE>
<ONE>textoneTWO</ONE>
<TWO attr="2.1"/>
<TWO attr="2.2"/>
<TWO attr="2.3"/>
<THREE>textthree</THREE>
</VALUE>
</TEST>
After parsing the document it looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><TEST>
<VALUE>
<ONE>textoneONE</ONE>
<ONE>textoneTWO</ONE>
<TWO attr="2.1"/>
<TWO attr="2.2"/>
<TWO attr="2.3"/>
<THREE>textthree</THREE>
</VALUE>
</TEST>
It seems that I loose the comments when I'm cloning the DomDocument with
this code:
newDoc->appendChild(newDoc->importNode(oldDoc->getDocumentElement(),(true)));
why does the DOMDocument::cloneNode() do not work? It fails with an
segmentation fault.
The cloneNode() method only works on nodes within the same DOMDocument -
that said, I'm not sure why it would cause a segfault.
Does anybody know here how I do best?
Your comment is outside the document element, and you are only importing
the document element into your new document - therefore you are loosing
the comment node. If you want to keep the comment, you'll have to loop
over all the children of the original document node, and import each one
into the new document.
John
--
John Snelson, Oracle Corporation http://snelson.org.uk/john
Berkeley DB XML: http://oracle.com/database/berkeley-db/xml
XQilla: http://xqilla.sourceforge.net