Giter Site home page Giter Site logo

Comments (4)

darronschall avatar darronschall commented on July 17, 2024

Updated by darron.schall on 2006-12-29T21:02:55

Changed issue title (accidentally left it as default when I entered it).

Title changed from 'JSON does not encode XML instances into anything useful' to 'JSON does not encode XML instances into anything useful'

from as3corelib.

darronschall avatar darronschall commented on July 17, 2024

Updated by mikechambers on 2007-01-10T04:41:34

I believe Firefox 2 has support for e4x. Might be useful to see how they handle it.

from as3corelib.

demauk avatar demauk commented on July 17, 2024

For me, converting XML to JSON has three major issues to be resolved: a) what do to about the XML root element name? b) how to encode attributes? c) how to encode text nodes when the parent element has attributes or other element children?

To that end, I added an xmlToString() function to JSONEncoder and a JSONEncoderXMLOptions class as an optional parameter to the JSONEncoder constructor. Let's say you have this XML:

<root>
  <category>Sci-Fi</category>
  <books>
    <book id="1">Text for Book 1</book>
    <book id="2">Text for Book 2</book>
  </books>
</root>

Option omitRootElement:Boolean;

Sometimes you want the JSON version to simply be { "books" : [ etc. ] }. And sometimes you want everything: { "root" : { "books" : [ etc. ] } }.

Option useAttributeAtSymbol:Boolean

Defaults to true. Determines whether or not attributes should be encoded with an @ sign at the beginning, like "@id" : "1" I think this should be standard, but I've set it as an option because I've seen implementations where they don't use @. IMO, if you can't differentiate attributes, you can't turn the JSON back into XML.

Option defaultSimpleContentLabel:String

Defaults to #text. A simple element like <category> can have its text node as its only value, like "category" : "Sci-Fi". But the text node of <book> needs its own property name, which in this case would look like: "book" : { "@id" : "1", "#text" : "Text for Book 1" }.

Other implementations use "label" but that's already a common property name for many actionscript objects.

I'll see if I can offer a patch, at least as a reference.

from as3corelib.

demauk avatar demauk commented on July 17, 2024

I've pushed my changes to my fork: https://github.com/demauk/as3corelib/tree/master/src/com/adobe/serialization/json

There are kind of a lot of changes in that one commit. Sorry about that.

from as3corelib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.