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

Attributes? #11

Open
GoogleCodeExporter opened this issue Mar 19, 2015 · 10 comments
Open

Attributes? #11

GoogleCodeExporter opened this issue Mar 19, 2015 · 10 comments

Comments

@GoogleCodeExporter
Copy link

Attributes are not converted:
I have this XML:
<root>
<agencies id="2" agenzia="Trieste" bank_id="1" abi="1030" cab="2200" />
..
..
</root>

and receive this JSON:
{"root":[null,null,null,null,null,null,null,null]}

Original issue reported on code.google.com by lorenzo....@gmail.com on 9 Sep 2008 at 4:53

@GoogleCodeExporter
Copy link
Author

this is a great library, but the lack of support for attributes is a bummer.

one possible solution would be to generate an {attributes:{"name":"value",...}} 
child
item for any element that has attributes. this will keep the attributes from
colliding w/ existing elements and keep them in a 'known' place. 

please give it a shot as i really like this library.

Original comment by mca%amun...@gtempaccount.com on 23 Jan 2009 at 12:04

@GoogleCodeExporter
Copy link
Author

A better solution in my opinion would be to use the @-character in the first 
value 
as a prefix. This is also the way that IBM generates it's JSON.
JSON doesn't support atttributes, only value pairs.
{root : ["@id": "2", "@agenzia":"Trieste", "@bank_id": "1"....]}

Original comment by RonB1...@gmail.com on 4 Mar 2009 at 8:05

@GoogleCodeExporter
Copy link
Author

I think the @ solution is the best.
it's really simple to recognize and useful.

Original comment by lorenzo....@gmail.com on 4 Mar 2009 at 8:47

@GoogleCodeExporter
Copy link
Author

I think the @-solution is nice enough to implement it. 

Question 1: can an XML-element's name start with an @-sign? If yes, do we need 
to 
escape it?

Question 2: Is backward compatibility needed?

Original comment by doek...@gmail.com on 4 Mar 2009 at 12:35

@GoogleCodeExporter
Copy link
Author

I tryed with a validator online with this code:

<?xml version="1.0" ?> 
<note>
<@test>works</@test>
</note>

at the address: http://www.w3schools.com/Dom/dom_validate.asp

It does NOT validate, so I think it's ok to use @ for attributes.

Note that also XML attributes that start with @ are not validate:

<?xml version="1.0" ?> 
<note>
<test @myattr="1">works</test>
</note>

This is NOT validate.

Original comment by lorenzo....@gmail.com on 4 Mar 2009 at 2:14

@GoogleCodeExporter
Copy link
Author

According to the XML specification, a tag starts with STag (and via Name to 
NameStartChar), which doesn't list a @-sign (
(http://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags). The XML Namespaces 
spec 
even brings (QName, LocalPart, NCName to NCNameStartChar) it down to a letter 
or an 
underscore
(http://www.w3.org/TR/REC-xml-names/#ns-using).

And also my tool XMLStarlet (http://xmlstar.sourceforge.net/) thinks it is 
illegal.

Answer to question 1: we can assume a tagname doens't start with a @-sign, so 
we 
don't need to escape it.

Original comment by doek...@gmail.com on 5 Mar 2009 at 8:34

@GoogleCodeExporter
Copy link
Author

Can you have xsl who works with attributes...

Original comment by argentma...@gmail.com on 13 Mar 2009 at 3:38

@GoogleCodeExporter
Copy link
Author

[deleted comment]

@GoogleCodeExporter
Copy link
Author

OK. Is someone willing to make this change? 

You can attach a svn patch (including testcases) to this issue.

Original comment by doek...@gmail.com on 16 Mar 2009 at 7:11

@GoogleCodeExporter
Copy link
Author

Martynas Jusevičius has a version that works with attributes. See his blog at
http://www.xml.lt/Blog/2009/01/21/XML+to+JSON

Original comment by dayb...@gmail.com on 12 Jul 2009 at 7:01

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

No branches or pull requests

1 participant