GithubHelp home page GithubHelp logo

Comments (7)

 avatar commented on July 24, 2024

Have you tries setting childrenAsArray: true in the config options? This should preserve the order. If I have misunderstood your concern, can you post a sample? Thanks.

from xmltojson.

eliseevmikhail avatar eliseevmikhail commented on July 24, 2024

copy((xmlToJSON.parseString("<root><a-two /><z-one /><a-two /></root>", {childrenAsArray: true})));

{
  "_children": [ /* Skip document top-level children tree */  ],
  "root": [
    {
      "_children": [
        {          "_tagname": "a-two"  /* Right order */        },
        {          "_tagname": "z-one"  /* Right order */        },
        {          "_tagname": "a-two"  /* Right order */        }
      ],
      "a-two": [ /* <------- Two elements are putted to list */
        {          "_tagname": "a-two"        },
        {          "_tagname": "a-two"        }
      ],
      "z-one": [  /* And where was one? */
        {          "_tagname": "z-one"        }
      ],
      "_tagname": "root"
    }
  ]
}

Also, JS doesnt guarantee key order in the dict (but all current realization yes). You probably want to add option for this behavior.

from xmltojson.

 avatar commented on July 24, 2024

This is the intent of setting 'childrenAsArray: true' in the options. Have you tried this approach?

from xmltojson.

eliseevmikhail avatar eliseevmikhail commented on July 24, 2024

As you may see in my last post, "childrenAsArray: true". It causes joining same named tags into array, but tag order was losted. Once more example (original lib, w/o patch):

> copy((xmlToJSON.parseString("<root><a-two /><z-one /><a-two /></root>", {childrenAsArray: true})));
{
  "root": [
    {
      "a-two": [
        {          "_text": [            null          ]        },
        {          "_text": [            null          ]        }
      ],
      "z-one": [
        {          "_text": [            null          ]        }
      ]
    }
  ]
}


```Compare tags order in the source xml and result object

from xmltojson.

 avatar commented on July 24, 2024

I see. If you don't mind, go ahead and push a patch and I will review and
test it. I am traveling this week, but am planning on publishing a new
release sometime next week.

Thanks.

On Aug 15, 2016 9:46 PM, "eliseevmikhail" [email protected] wrote:

As you may see in my last post, "childrenAsArray: true". It causes joining
same named tags into array, but tag order was losted. Once more example
(original lib, w/o patch):

copy((xmlToJSON.parseString("", {childrenAsArray: true})));
{
"root": [
{
"a-two": [
{ "_text": [ null ] },
{ "_text": [ null ] }
],
"z-one": [
{ "_text": [ null ] }
]
}
]
}

Compare tags order in the source xml and result object


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#21 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AFAjfGC99BjEKr1q_Pz96c6ofLQwqn-fks5qgUCQgaJpZM4IXzU3
.

from xmltojson.

 avatar commented on July 24, 2024

This will require a significant change to the format of the JSON representation; possibly something like

[
 {nodetype, tag, namespace , attr [], children []},
 {nodetype, tag, namespace , attr [], children [
    {nodetype, tag, namespace , attr [], children []},
    {nodetype, tag, namespace , attr [], children []},
    {nodetype, tag, namespace , attr [], children []},
 ]},
 {nodetype, tag, namespace , attr [], children []},
]

This will require a new way of searching/walking the nodes as well.

from xmltojson.

 avatar commented on July 24, 2024

I dont like losing the tag names as keys and will have to rethink this approach. The current grouping methodology meets the original intent and I am worried about a find() or match() style api for walking the object array.

from xmltojson.

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.