xmlbuilder2 icon indicating copy to clipboard operation
xmlbuilder2 copied to clipboard

callback API reference/position error

Open b7kich opened this issue 2 years ago • 0 comments

Describe the bug new nodes aren't added to the element you refer to but to wherever the pointer currently is in the node tree, i.e. the latest element or it's parent(s) depending on the number of up() calls

To Reproduce See https://codesandbox.io/s/serverless-morning-gj0qou

function testXml(xml) {
  let root=xml.ele("root")
  root.ele("a")
  root.ele("b")
}


export default function App() {
  let xml = create();
  testXml(xml);
  let regular = xml.end();
  let buffer = "";
  let xmlCB = createCB({ data: (chunk) => (buffer = buffer + chunk) });
  testXml(xmlCB);
  xmlCB.end();
  console.log("Regular xmlbuilder2: "+regular)
  console.log("Callback xmlbuilder2: "+buffer)

...

Regular xmlbuilder2: <root><a/><b/></root> 
Callback xmlbuilder2: <root><a><b/></a></root> 

Expected behavior regular and callback xml should be the same

Version:

  • xmlbuilder2 [3.0.2]

Additional context Add any other context about the problem here.

b7kich avatar May 25 '22 01:05 b7kich