-
Notifications
You must be signed in to change notification settings - Fork 607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to drop array indexes? #119
Comments
nvrmind... |
Hey, how do you drop array indexes? I would like to not have them but are unsure how to do so? |
Sorry, what do you mean by dropping array indexes? Erm, xml2js arrays are normal JS arrays and support the same operations. |
Well if I use
Where object is a JS array holding JS objects the resulting XML looks something like this:
Now I would love to not have the 0, 1, 2 tags since that seems to be invalid XML (at least my browser thinks so). I would either like to not have the 0, 1, .. tags or name them. Any thoughts? |
Well, xml2js should not generate invalid XML, so that's what I would consider a bug… |
Here's some data how you can reproduce this problem:
converts to:
but:
converts to:
it seams that it has something to with the array being too close to the root element. |
I think I figured this one out and why there are the indexes.
someArray is the root object this would be converted to xml :
but the xml does not allow empty root element nor it will not allow multiple elements without a root element. So in this case the json -> xml makes the someArray as the root element and generates indexes under the root element.
|
I recently using NW.js to build up my own desktop app and also came across the same issue. The reason causing this problem might be the condition statement of determine if the variable is an Array: typeof child === 'object' && child instanceof Array So, I just replaced the 'instanceof ' with the util module in Node.js: util.isArray(child); This seems work. |
@Roman-Lo I've just tried it and it does not seem to make a difference in my testing. |
Hi guys, as a quick solution for a project I'm implementing now, did this (see below). I know it's not the most elegant solution in the world, but my project has been up for while now and no probs at all. Only xml tags with numeric values are removed.
This also work (going down one level when defining the object):
Hope it can help somebody :-) |
any fix for this yet? |
If I try: <root>
<0>
<a>1</a>
</0>
<1>
<b>2</b>
</1>
</root> which is invalid xml. Still no fix? |
Waiting on a fix too, same problem |
Thanks for the bug reports on this issue. If someone has the time to find a fix and submit a pull request it would be much appreciated. I contributed the builder code years ago and I haven't had time to work on it. |
Hi everyone. I can see from today, that this issue has not been fixed. I have created an object like:
Returning:
Did id do something wrong? Running Version 0.4.19 |
Hi AndreKirchner, I don't know it is too late or not, but your json object has a little mistake. |
Update to 0.4.22, it's solved in that version |
I confirm it's working now, you can even use objects inside the array, e.g.: |
No description provided.
The text was updated successfully, but these errors were encountered: