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

Namespace is removed when importing fragments #178

Open
svobik7 opened this issue Apr 22, 2024 · 0 comments · May be fixed by #179
Open

Namespace is removed when importing fragments #178

svobik7 opened this issue Apr 22, 2024 · 0 comments · May be fixed by #179
Assignees
Labels
bug Something isn't working

Comments

@svobik7
Copy link

svobik7 commented Apr 22, 2024

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 xmlns="ns2">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
@svobik7 svobik7 added the bug Something isn't working label Apr 22, 2024
@svobik7 svobik7 linked a pull request Apr 22, 2024 that will close this issue
4 tasks
svobik7 added a commit to svobik7/xmlbuilder2 that referenced this issue Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants