node-xml icon indicating copy to clipboard operation
node-xml copied to clipboard

stream with multiple input

Open broncha opened this issue 8 years ago • 1 comments

Hi, I have multiple input to xml. When I close on of the input stream, closing other has no effect. I dont get the closing tag for the last element

kml = xml.element({ _attr: { xmlns: 'http://www.opengis.net/kml/2.2'} });
doc = xml.element({})

stream = xml([{kml: kml}, {Document: doc}], {declaration: true})

stream.on 'data', (chunk) ->
  console.log(chunk);

doc.close()
kml.close()

And here is the output

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
</Document>

Closign tag for kml is missing

broncha avatar Jul 14 '16 17:07 broncha

I think I found the issue here. The first element should be the one that should end the stream when closing

if (i + 1 === input.length)
    last = end;
add(value, last);

should be

if (i == 0)
    last = end;
add(value, last);

broncha avatar Jul 14 '16 18:07 broncha