Open GoogleCodeExporter opened 9 years ago
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
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
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
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
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
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
Can you have xsl who works with attributes...
Original comment by argentma...@gmail.com
on 13 Mar 2009 at 3:38
[deleted comment]
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
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
Original issue reported on code.google.com by
lorenzo....@gmail.com
on 9 Sep 2008 at 4:53