Skip to content

Add addClone method to XmlElement#141

Open
afn wants to merge 1 commit intojameslan:masterfrom
superdoc-dev:master
Open

Add addClone method to XmlElement#141
afn wants to merge 1 commit intojameslan:masterfrom
superdoc-dev:master

Conversation

@afn
Copy link

@afn afn commented Feb 8, 2026

Add an addClone function to XmlElement to allow adding cloned children from one document to another.

Example:

const { XmlDocument } = await import ('libxml2-wasm');
const doc1 = XmlDocument.fromString('<foo><bar>hello</bar></foo>');
const doc2 = XmlDocument.fromString('<root><baz>Ahoy matey!</baz></root>');
const foo = doc1.get('/foo');
const baz = doc2.get('//baz');
foo.addClone(baz);
console.log(doc1.toString());

outputs:

<?xml version="1.0" encoding="utf-8"?>
<foo>
  <bar>hello</bar>
  <baz>Ahoy matey!</baz>
</foo>

Call `xmlElement.addClone(otherElement)` to add a clone of
`otherElement` (possibly from a different XmlDocument) to the children
of `xlmElement`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant