xmlbuilder2
xmlbuilder2 copied to clipboard
Namespace is removed when importing fragments
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.
- 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>
- 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
I've also encountered this issue and can confirm that the PR addresses it for me. Haven't noticed any other issues.
Seeing the same issues coming from 2 and going to 3