Skip to content

Namespace is removed when importing fragments #178

@svobik7

Description

@svobik7

Describe the bug
There is a namespace misalignment when creating child element with .ele and when importing fragment child using .import.

To Reproduce
⚙️ Try to run following functions and compare their outputs.

  1. Function called "workingExample" outputs properly.
function workingExample() {
  const doc = create({ version: '1.0' });
  const root = doc.ele('ns1', 'Root');

  // creates Child element with proper namespace set to "ns2"
  root.ele('ns2', 'Child').txt('text');

  return doc.end({ prettyPrint: true })
}

✅ Output of workingExample function that is OK:

<?xml version="1.0"?>
<Root xmlns="ns1">
  <Child xmlns="ns2">text</Child>
</Root>
  1. Function called "notWorkingExample" outputs child element without namespace.
function notWorkingExample() {
  const doc = create({ version: '1.0' });
  const root = doc.ele('ns1', 'Root');

  // inserts Child element (fragment) but namespace 'ns2' is omitted
  const child = fragment().ele('ns2', 'Child').txt('text');
  root.import(child);

  return doc.end({ prettyPrint: true })
}

⚠️ Output of notWorkingExample function that is NOK:

<?xml version="1.0"?>
<Root xmlns="ns1">
  <Child>text</Child>
</Root>

Expected behavior
Output of notWorkingExample function is equal to output of workingExample = both functions output:

<?xml version="1.0"?>
<Root xmlns="ns1">
  <Child xmlns="ns2">text</Child>
</Root>

Version:

  • node.js: [20.11.0]
  • xmlbuilder2 3.1.1

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions