1

Is it possible to control how an xml document is rendered by XMLSerializer when using your own namespace? Namely, when creating a document like this:

root = document.implementation.createDocument('hello-world', 'Something', null);
s = new XMLSerializer();
console.log(s.serializeToString(root));

The resulting xml from serializeToString is

<Something xmlns="hello-world"/>

Is there any way to change the formatting such that the output is instead

<Something xmlns="hello-world"></Something>

1 Answer 1

1

It worked for me to add an empty text node:

root.documentElement.appendChild(root.createTextNode(""));

With that line included, I get the output

<?xml version="1.0"?><Something xmlns="hello-world"></Something>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.