Skip to content
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

Support for Array #33

Closed
beeing opened this issue May 16, 2018 · 3 comments
Closed

Support for Array #33

beeing opened this issue May 16, 2018 · 3 comments
Labels

Comments

@beeing
Copy link

beeing commented May 16, 2018

Hi, I like your library which is simple and straight-forward.

However, I was caught by surprised when the array being converted to xml.

const { toXML } = require('jstoxml')
console.log(toXML({ x: ['lat','lng'] })) // -> <x>latlng</x>
console.log(toXML({ x: [1,2,3] })) // -> <x>123</x>

The library will just concat all the values into a string instead of separating it, presumably like:

<x-arr name="x">
    <x>1</x>
    <x>2</x>
    <x>3</x>
</x-arr>

Is there anything that I missed?

Thanks in advance.

@davidcalhoun
Copy link
Owner

Thanks for using the library! That's an interesting suggestion, I can definitely see how that would be handy. I'll leave this open and consider adding in this feature.

Currently you can achieve what you need with this (see the duplicate keys example in the readme as well):

toXML([
  { x: 1 },
  { x: 2 },
  { x: 3 }
]);

// -> '<x>1</x><x>2</x><x>3</x>'

@jimmdd
Copy link

jimmdd commented Jun 28, 2018

I like your library but I need this feature! I have to convert JavaScript object with nested array like data:{name:sth, risk:[{sth},{sth}]} and convert to <data><name>sth</name><risk>sth</risk><risk>sth</risk></data>. With current version, I can't do this conversion without rewrite the entire json to use _name and _content.

@davidcalhoun
Copy link
Owner

Thanks for the feedback. This is now implemented in 1.4.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants