How do I add a namespace prefix to an XML DOM object? How do I add a namespace prefix to an XML DOM object? spring spring

How do I add a namespace prefix to an XML DOM object?


You can use setPrefix.

But it is better to create the root element like this:

document.createElementNS("http://www.myschema.com", "m:documentObject");

Note also that passing null to createElement is a supported way of forcing a null namespace. In your original example this would however not work because your document element effectively forces a default namespace by combining a namespace URI with no prefix.