Skip to content

importDocument created from begin() #213

Closed
@danielsetreus

Description

@danielsetreus

When creating dynamic documents it's really useful to be able to import a document containing only child elements. Consider:

import { XMLElementOrXMLNode, create, begin } from "xmlbuilder";

const doc = begin();
const boldDoc = create('b');
boldDoc.text('Hello World');

doc.importDocument(boldDoc);

const main = create('p');
main.importDocument(doc);

console.log(main.toString());

I would expect this to result in XML document

<p><b>Hello World</b></p>

Instead I get an error: Cannot read property 'clone' of undefined (/node_modules/xmlbuilder/lib/XMLNode.js:569:32).

doc is not undefined:

console.log(doc.toString()); // <b>Hello World</b>

However doc.root() returns undefined, causing the issue.

Not sure if this is a bug or not, but reading the docs this is not what I was expecting :/

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions