cyrfer / x2js

Automatically exported from code.google.com/p/x2js
0 stars 2 forks source link

Problems when having ':' in XML attribute names #31

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use an XML document containing an attribute with ':' in the attribute name, 
like:
<container>
  <test my:attrib="abc">
    <d>hello world!</d>
  </test>
</container>
2. Create an X2JS object and pass the test document:
var x = new X2JS();
x.xml_str2json('<container><test my:attrib="abc"><d>hello 
world!</d></test></container>');

What is the expected output? What do you see instead?
Expected:
{
  container: {
    test: {
      '_my:attrib': 'abc',
      d: 'hello world!'
    }
  }
}
Got instead:
{
  container: {}
}

What version of the product are you using? On what operating system and
browser version?
X2JS Version 1.1.7,
Windows 7, Chrome 39.0.2171.65

Please provide any additional information below.
It seems the DOMParser has the problem. However, it does not happen when the 
mime type 'text/html' is used, with all others, the error happens. However, 
X2JS does not parse correctly if this mime type is used.

Original issue reported on code.google.com by weinberg...@gmail.com on 24 Nov 2014 at 5:37

GoogleCodeExporter commented 9 years ago
Turns out X2JS works fine when using the mime type 'text/html', but the 
DOMParser didn't like the short form of an element (<testnode />). When I 
changed it to (<testnode></testnode>) it worked.
It would be nice to change the mime type using a parameter instead of digging 
into the library.
As a side effect, all elements and attributes are in lowercase letters which 
might come in handy in some use cases.

Original comment by weinberg...@gmail.com on 25 Nov 2014 at 6:30

GoogleCodeExporter commented 9 years ago
text/html - is actually isn't XML :) And if your XML is not well-defined in XML 
terms, you probably need to use namespaces like this?

<container xmlns:my="test">
  <test my:attrib="abc">
    <d>hello world!</d>
  </test>
</container>

{"container":{"test":{"d":"hello 
world!","_my:attrib":"abc"},"_xmlns:my":"test"}}

Original comment by abdulla....@gmail.com on 25 Nov 2014 at 10:00

GoogleCodeExporter commented 9 years ago

Original comment by abdulla....@gmail.com on 25 Nov 2014 at 10:00

GoogleCodeExporter commented 9 years ago
Oh... I totally forgot about XML namespaces! Thanks a lot, that solved the 
issue of course! :)

Original comment by weinberg...@gmail.com on 26 Nov 2014 at 9:57

GoogleCodeExporter commented 9 years ago
np

Original comment by abdulla....@gmail.com on 27 Nov 2014 at 3:44