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

IE11 Bug: Namespaces serialized incorrectly in XML #42

Open
TheSamsterZA opened this issue Jun 7, 2017 · 6 comments
Open

IE11 Bug: Namespaces serialized incorrectly in XML #42

TheSamsterZA opened this issue Jun 7, 2017 · 6 comments

Comments

@TheSamsterZA
Copy link

Hi there @tyrasd,

Great library, thanks a lot!

Here's an example that works perfectly in Chrome 58 and Firefox 53:

<html>
  <head>
    <title>XML Serialization</title>
  </head>
  <body>
    <script src="jxon.js"></script>
    <script>
      var xml = '<?xml version="1.0"?><People xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://MyNS.com"><Person><Id>a012345d-12bc-41fe-a35d-ff713bc876e0</Id><Name>Complete Automatically?</Name><Prompt>Would you like to complete this...</Prompt><Options><Option><Text>Automatically</Text><Value>Automatic Name</Value></Option><Option><Text>Manually</Text><Value>Manual Name</Value></Option></Options><Value>Current Name</Value></Person></People>';
      
      var json = JXON.stringToJs(xml);
      console.log(JSON.stringify(json));
      var desXml = JXON.jsToString(json);
      console.log(desXml);
    </script>
  </body>
</html>

Output:

{
  "People": {
    "Person": {
      "Id": "a012345d-12bc-41fe-a35d-ff713bc876e0",
      "Name": "Complete Automatically?",
      "Prompt": "Would you like to complete this...",
      "Options": {
        "Option": [{
            "Text": "Automatically",
            "Value": "Automatic Name"
          }, {
            "Text": "Manually",
            "Value": "Manual Name"
          }
        ]
      },
      "Value": "Current Name"
    },
    "$xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
    "$xmlns:xsd": "http://www.w3.org/2001/XMLSchema",
    "$xmlns": "http://MyNS.com"
  }
}
<People xmlns="http://MyNS.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <Person>
    <Id>a012345d-12bc-41fe-a35d-ff713bc876e0</Id>
    <Name>Complete Automatically?</Name>
    <Prompt>Would you like to complete this...</Prompt>
    <Options>
      <Option>
        <Text>Automatically</Text>
        <Value>Automatic Name</Value>
      </Option>
      <Option>
        <Text>Manually</Text>
        <Value>Manual Name</Value>
      </Option>
    </Options>
    <Value>Current Name</Value>
  </Person>
</People>

In IE11, the same code produces identical JSON, but the XML looks like this:

<People xmlns="http://MyNS.com" xmlns:NS1="" NS1:xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:NS2="" NS2:xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Person>
    <Id>a012345d-12bc-41fe-a35d-ff713bc876e0</Id>
    <Name>Complete Automatically?</Name>
    <Prompt>Would you like to complete this...</Prompt>
    <Options>
      <Option>
        <Text>Automatically</Text>
        <Value>Automatic Name</Value>
      </Option>
      <Option>
        <Text>Manually</Text>
        <Value>Manual Name</Value>
      </Option>
    </Options>
    <Value>Current Name</Value>
  </Person>
</People>

So there are these empty xmlns:NSx="" namespaces and the actual namespaces are prefixed incorrectly.

Is there a way to get IE11 to serialize namespaces correctly?

@tyrasd
Copy link
Owner

tyrasd commented Jun 7, 2017

which version of jxon are you using?

@TheSamsterZA
Copy link
Author

The version is 2.0.0-beta.5 which I believe is the latest.

@mstock
Copy link

mstock commented Apr 8, 2018

I also ran into this issue when trying to generate GPX data using the togpx module (0.5.4) in IE11 (which seems to be using version 2.0.0-beta.5 of JXON).

mstock added a commit to mstock/osrm-frontend that referenced this issue Apr 8, 2018
This works around JXON issue Project-OSRM#42 [1] by repairing the invalid XML name
space declarations in the GPX data and should thus yield usable GPX files
in IE11, too.

[1] tyrasd/jxon#42
mstock added a commit to mstock/osrm-frontend that referenced this issue Apr 8, 2018
This works around JXON issue Project-OSRM#42 [1] by repairing the invalid XML name
space declarations in the GPX data and should thus yield usable GPX files
in IE11, too.

[1] tyrasd/jxon#42
mstock added a commit to mstock/osrm-frontend that referenced this issue Apr 8, 2018
This works around tyrasd/jxon#42 [1] by repairing the invalid XML name
space declarations in the GPX data and should thus yield usable GPX files
in IE11, too.

[1] tyrasd/jxon#42
@nrenner
Copy link

nrenner commented Mar 4, 2021

PR #53 adds some additional namespace support, can someone with an IE setup please test and see if it also fixes this issue?

@TheSamsterZA
Copy link
Author

@nrenner Hello! Thank you for attempting to fix this problem. I've found a couple of things with your PR:

  1. It appears that, for JSON, your PR moves the namespaces up so that they are listed first. I don't mind that, but I do think it's worth calling out. The rest of the JSON looks to be serialized correctly.
  2. For XML, on Chrome 88.0.4324.190, the xmlns namespace is moved to the end of the top-level element. Again, this is fine, but worth mentioning.
  3. For XML, on IE11 (11.789.19041.0), only the xmlns value is provided; both of the xmlns:xsd and xmlns:xsi values are missing. On Chrome, those values are provided, and appear to be defaults. Why do they not show up on IE11?

So this PR is a step towards fixing my original issue, but the way it affects serialization for both JSON and XML might be cause for concern for other people.

@nrenner
Copy link

nrenner commented Mar 5, 2021

For XML, on Chrome 88.0.4324.190, the xmlns namespace is moved to the end of the top-level element.

That's because it's ordered like that in the input XML and the PR sets the namespace attributes explicitly. The current master version relies on the XML serializer to add the xmlns attribute automatically, which seems put it first.

For XML, on IE11 (11.789.19041.0), only the xmlns value is provided; both of the xmlns:xsd and xmlns:xsi values are missing.

My guess would be, that those namespaces are not used in the document and are therefore removed by the XML serializer, probably nothing we can do about it. My question would rather be why they are added in the original XML?

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

No branches or pull requests

4 participants