Using xmldom to modify storage content

I am using the Confluence REST API to update the storage content of a page. I am using the node implementation of xmldom. Aftert I update my document and serialize to a string, xmlns="" is inserted by the serializer into all custom elements (example ac:structured-macro), causing validation to fail with the error

“Error parsing xhtml: Non-default namespace can not map to empty URI (as per Namespace 1.0 # 2) in XML 1.0 documents”

How can I get my document to pass validation? The module does not appear to provide a way to scrub the xmlns from the serialized document.

If the xmldom library does not have the ability to remove this namespace automatically, you will have to traverse the tree yourself and remove the attribute from each note.

Alternatively, I’ve used JQuery on the server before with success. (See: