-
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
Builder: for each item in children array, I get "[object Object]" #561
Comments
let a = [{ bar: 1 }, { bar: 2 }, { bar: 3 }]
var builder = new xml2js.Builder({rootName:"foo"});
var xml = builder.buildObject(a);
console.log(xml); Output: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<foo>
<bar>1</bar>
<bar>2</bar>
<bar>3</bar>
</foo> |
I have a similar issue except my output needs to be something along the lines of:
|
I wrote a simple demo for this case. Is it what you need? :) const xmlObj = {
"Fields": {
"Inputs": {
"Foo": {
"$": {
"name": "some string"
},
"Bar": [
"1",
"2",
"3",
"4"
]
}
}
}
};
const builder = new xml2js.Builder();
const xmlstr = builder.buildObject(xmlObj);
console.log(xmlstr); Output: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Fields>
<Inputs>
<Foo name="some string">
<Bar>1</Bar>
<Bar>2</Bar>
<Bar>3</Bar>
<Bar>4</Bar>
</Foo>
</Inputs>
</Fields> |
Perfect, thanks. I wish this would have been documented with the $ and _ usage. |
@hadesflames - close issue? |
Just ran into this, I also think this should be added to the documentation before closing. |
Sorry never saw this, I'm not the one that opened the issue though. |
The following:
Returns this:
How do I get rid of the [object Object]?
The text was updated successfully, but these errors were encountered: