Inist-CNRS/node-xml-mapping

Symetry breaking / strange loading behaviour

niederlec opened this issue · 4 comments

This behaviour looks strange/unexpected, but I guess it is a limitation of the Google GData protocol.

var json = xmlMapping.load('<root>hello <child>!</child>you</root>');
console.log(json)
// => returns { root: { '$t': [ 'hello', 'you' ], child: { '$t': '!' } } }

var xml = xmlMapping.dump(json);
console.log(xml);
// => returns <root><child>!</child><:t><![CDATA[hello]]></:t><:t><![CDATA[you]]></:t></root>

Two major problems for me :

  • the order of XML nodes is not preserved
  • bad xml elements with empty namespace are generated

Any idea or solution ?

Oh... On the official doc, this case is processed another way on the example :

XML input :

...
    <content type="text">Google is sponsoring at 
      <a href="http://www.pubcon.com/">WebmasterWorld PubCon 2006</a>. Come and
      visit us at the booth or join us for an evening demo reception where we
      will be talking "5 ways to enhance your website with Google Code". 
      After all, it is Vegas, baby! See you soon.</content>
...

JSON representation :

...
"content": {
        "type": "text",
        "$t": "Google is sponsoring at
          <a href="http://www.pubcon.com/">WebmasterWorld PubCon 2006</a>.
          \nCome and visit us at the booth or join us for an evening demo
          reception where we will be talking "5 ways to enhance your website
          with Google Code".\nAfter all,\nit is Vegas, baby! See you soon."
},
...

The sub-element <a> is not JSONified, but preserved as XML code.

touv commented

I don't know but have you try the nested option like the first example https://github.com/Inist-CNRS/node-xml-mapping#loadstring-xml-object-options
is it the same issue or not ?

touv commented

image

Yes, it is the same issue.
If you make a dump on this JSON, you don't get initial XML :

console.log(XMLMapping.dump(json));
> <title>Title is&lt;strong&gt;important&lt;/strong&gt;<strong>important</strong></title>