You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Ferdinand Knapitsch <no...@tugraz.at> on 2008/04/10 13:14:13 UTC

XLM comments deleted after load/save

Hi!

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>

The problem is, that it is not the same any more and the comments are
deleted.
I do not know what's going wrong when parsing.

I have set the 

      parser->setFeature(XMLUni::fgDOMComments, true);

which should keep comment nodes in the document.

Does anybody have the same experiences?


Ferdinand




Re: XLM comments deleted after load/save

Posted by John Snelson <jo...@oracle.com>.
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

Re: XLM comments deleted after load/save

Posted by Ferdinand Knapitsch <no...@tugraz.at>.
Am Thu, 10 Apr 2008 13:14:13 +0200 schrieb Ferdinand Knapitsch:

> Hi!
> 
> 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.


Does anybody know here how I do best?


Best regards,
 Ferdinand