oozcitak / xmlbuilder-js

An XML builder for node.js
MIT License
918 stars 107 forks source link

Issue with Importing documents twice #240

Closed breiko83 closed 3 years ago

breiko83 commented 3 years ago

I need to use importDocument twice and I'm having issues going up 1 node after importing is called.

This is the expected xml:

<workout>
  <tags>
    <tag name="tag1" />
    <tag name="tag2" />
  </tags>
  <people>
    <person name="mike">
  </people>
</workout>

This is what i get:

<workout>
  <tags>
    <tag name="tag1" />
    <tag name="tag2" />
    <person name="mike">
  </tags>
  <people />
</workout>

This is my code:

let xml = Builder.begin().ele('workout').ele('tags')

tags.map((tag) => {
  t = Builder.create('tag').att('name',tag)
  xml.importDocument(t)
})

xml.up().ele('people')

people.map((name) => {
  t = Builder.create('person').att('name',name)
  xml.importDocument(t)
})
oozcitak commented 3 years ago

This line:

xml.up().ele('people')

should be:

xml = xml.up().ele('people')
breiko83 commented 3 years ago

Thank you!!