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

Elements with null values not treated consistently #44

Closed
jbasiago opened this issue May 17, 2014 · 2 comments
Closed

Elements with null values not treated consistently #44

jbasiago opened this issue May 17, 2014 · 2 comments
Labels

Comments

@jbasiago
Copy link

This is a really great tool. However, I ran into an issue while trying to create documents that had iterations over their structure. I couldn't figure out how to build them with the concatenated element approach, so I used the object approach instead. But I found that elements are not treated consistently between them. Here is demonstration code:

var builder = require('xmlbuilder');

var doc1 = builder.create('doc');
doc1.ele("parent").
    ele("listItem").
    ele("child1", "present").up().
    ele("child2", null).up().up().
    ele("listItem").
    ele("child1", "present").up().
    ele("child2", null);
console.log(doc1.toString({pretty: true}));

var doc2 = builder.create('doc');
var contents = {
    parent: {
        '#list': [
            {
                listItem: {
                    'child1': "present",
                    'child2': null
                }
            },
            {
                listItem: {
                    'child1': "present",
                    'child2': null
                }
            }
        ]
    }
};
doc2.ele(contents);
console.log(doc2.toString({pretty: true}));

I need the resulting document to look like the doc1 results when there are null values in the data. Can you help with this? Is there a way to use the concatenated ele() calls to produce a variable number of listItems in the structure?

Thanks,

@jbasiago jbasiago reopened this May 17, 2014
@jbasiago
Copy link
Author

<doc>
  <parent>
    <listItem>
      <child1>present</child1>
      <child2/>
    </listItem>
    <listItem>
      <child1>present</child1>
      <child2/>
    </listItem>
  </parent>
</doc>

<doc>
  <parent>
    <listItem>
      <child1>present</child1>
    </listItem>
    <listItem>
      <child1>present</child1>
    </listItem>
  </parent>
</doc>

@oozcitak
Copy link
Owner

Iterations can be done as follows:

var doc1 = builder.create('doc');
var parent = doc1.ele("parent");
for(var i = 1; i <= 2; i++)
{
  parent.ele("child1", "present").up()
    .ele("child2", null)
}

@oozcitak oozcitak added Bug and removed Bug labels Jun 30, 2014
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

2 participants