Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML Prolog inconsistence #33

Open
laubstein opened this issue Aug 15, 2016 · 2 comments · May be fixed by #34
Open

XML Prolog inconsistence #33

laubstein opened this issue Aug 15, 2016 · 2 comments · May be fixed by #34
Milestone

Comments

@laubstein
Copy link
Contributor

Given:

var strXml = '<?xml version="1.0" encoding="UTF-8"?><a>1</a>';
var xml = JXON.stringToXml(strXml);
var json = JXON.xmlToJs(xml);
console.log('XML to String', JXON.xmlToString(xml));
console.log('JS to String', JXON.jsToString(json));

Using Chrome 52:

XML to String <?xml version="1.0" encoding="UTF-8"?><a>1</a>
JS to String <a>1</a>

Using Firefox 48:

XML to String <?xml version="1.0" encoding="UTF-8"?><a>1</a>
JS to String <a>1</a>

Using node (npm run test-node):

XML to String <?xml version="1.0" encoding="UTF-8"?><a>1</a>
JS to String <a>1</a>

Using Browserify (npm run test-webkit):

XML to String <a>1</a>
JS to String <a>1</a>

As JXON is a 'lossless', the xml prolog need to be consistent in all serializations.

Expected result:

XML to String <?xml version="1.0" encoding="UTF-8"?><a>1</a>
JS to String <?xml version="1.0" encoding="UTF-8"?><a>1</a>
@tyrasd tyrasd added this to the 2.0 milestone Aug 15, 2016
@tyrasd
Copy link
Owner

tyrasd commented Aug 15, 2016

from #32 (comment):

If you want, I can try to fix

Sure, go ahead! 👍

I'm a bit surprised that the phantomjs in test-webkit doesn't preserve the declaration, but I guess that's just because of a relatively old js engine in there. I've found this stackoverflow thread which indicates that browsers weren't (or still aren't) very consistent on this… or maybe the standard just isn't very precise, idk.

How did you thing about implementing this? Two possibilities I can think of:

  • Save the (pseudo-)parameters of the declaration in some special jxon elements. How do we handle encodings then? If I'm not mistaken, the parsed xmldom should always be in UTF-8 regardless of input charset, therefore the serialized string output is also always in UTF-8.
  • (much more pragmatic:) Just add a flag to jsToString (and maybe also xmlToString) which if true causes the output to always include at least a minimal xml declaration (i.e. <?xml version="1.0"?>), if the flag is false it would drop any eventually present <?xml… prolog, and if the flag is "auto" it just let's the underlying DOM implementation decide whatever to do. The default for this should probably the true case, maybe.

laubstein added a commit to laubstein/jxon that referenced this issue Aug 16, 2016
@laubstein laubstein linked a pull request Aug 16, 2016 that will close this issue
@TheSamsterZA
Copy link

I would love for this to be fixed in the next version of JXON. Any idea when this will be merged in and released?

cc @tyrasd, @laubstein

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants