GithubHelp home page GithubHelp logo

broken in node 0.8.8 about node-xml2json HOT 8 CLOSED

buglabs avatar buglabs commented on September 28, 2024
broken in node 0.8.8

from node-xml2json.

Comments (8)

c4milo avatar c4milo commented on September 28, 2024

What result are you expecting? I'm getting the same result in previous versions of xml2json and nodejs. The reason is that the parser doesn't know how to treat that object, it could be handled as an attribute or as an element value. You can give the parser a hint by changing your object like:

{ foo: {$t: 'bar'} };

from node-xml2json.

ttezel avatar ttezel commented on September 28, 2024

Yeah that's what I've been using so far with this library. I was hoping for a cleaner way to handle regular Object -> XML conversion, because in order to use this library I need to transform all my Objects before converting them to XML. Is there no cleaner way to do this?

from node-xml2json.

c4milo avatar c4milo commented on September 28, 2024

How do you think that cleaner way would be?

from node-xml2json.

ttezel avatar ttezel commented on September 28, 2024

why not like this:

{ 
  foo: { 
    '$attr': 'attributes go here',  
    bar: 'baz' 
  }
}

that way objects without attributes don't require any extra work.

from node-xml2json.

c4milo avatar c4milo commented on September 28, 2024

What is the xml that you would expect as output for

{ foo: 'bar' }

from node-xml2json.

ttezel avatar ttezel commented on September 28, 2024
<foo>bar</foo>

from node-xml2json.

c4milo avatar c4milo commented on September 28, 2024

json2xml parser was designed to get along with xml2json. As I said above, there is no way for the parser to know that

 { foo: 'bar' }

should be translated to

<foo>bar</foo>

For that purpose you need to hint the json2xml parser using this form instead:

{ foo: {$t: 'bar'} };

which I consider compatible with xml2json and cleaner than

{ 
  foo: { 
    '$attr': 'attributes go here',  
    bar: 'baz' 
  }
}

That said, I'll close this issue and considerer it invalid unless you have a better proposal to disambiguate the json string and at the same time get along with the xml2json parser.

from node-xml2json.

c4milo avatar c4milo commented on September 28, 2024

BTW, this parser behaves like you want: https://gist.github.com/3738875

from node-xml2json.

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.