Comments (7)
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.
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.
This is the intent of setting 'childrenAsArray: true' in the options. Have you tried this approach?
from xmltojson.
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.
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.
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.
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)
- tag names in JSON result HOT 12
- Add license in bower.json and .min.js HOT 1
- Update module on npm HOT 7
- When attribute name of an element have ":" character, does not parse HOT 1
- oXMLParent.hasChildNodes is not a function HOT 1
- Add the proper require() statement to your Readme.md file HOT 1
- Internal state (options) can be modified asynchronously HOT 2
- Cannot get it working with latest angular-cli with webpack HOT 4
- Doesn't work in NodeJS HOT 5
- syntax error display on console when call xml_str2json() on firefox HOT 2
- How to convert XML to JSON in an external reference HOT 3
- How to force to dispaly 0 after decimal? HOT 1
- Implement promises for asynchronous parsing of XML
- Improve examples in README
- Improve test coverage
- Migrate to latest Jasmine (2.8.x)
- Add support for processing instructions and comments HOT 2
- Migrate to DOM4
- Cannot parse Android Manifest XML HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xmltojson.