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

Building arrays #128

Closed
hartungstenio opened this issue Mar 13, 2014 · 1 comment
Closed

Building arrays #128

hartungstenio opened this issue Mar 13, 2014 · 1 comment

Comments

@hartungstenio
Copy link

When building a XML from a JSON object (using the Builder class), arrays are interpreted as objects.

Trying to simplify, the following JSON Object

var j = {
        "samples": [
          { "sample": { "id": "1" } },
          { "sample": { "id": "2" } }
        ]
      };

And the following Builder:

var builder = new xml2js.Builder({
        renderOpts: {
          "pretty": false
        },
        xmldec: {
          version: "1.0"
        }
      });

The generated XML is (notice the indexes):

<?xml version="1.0"?>
<samples>
  <0>
    <sample>
      <id>1</id>
    </sample>
  </0>
  <1>
    <sample>
      <id>2</id>
    </sample>
  </1>
</samples>

And it should be

<?xml version="1.0"?>
<samples>
  <sample>
    <id>1</id>
  </sample>
  <sample>
    <id>2</id>
  </sample>
</samples>

Am I missing something?

I think the error is in line 125 of xml2js.coffee
element = arguments.callee(element.ele(key), entry).up()

And how do I get the id to be generated as an attribute?

Thanks.

@Leonidas-from-XIV
Copy link
Owner

Looks like a duplicate of #119, therefore closing. Please contribute in the other bug report.

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

No branches or pull requests

2 participants