Java tutorial
//package com.java2s; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; public class Main { /** * Add the first node with a namespace attribute as below: * <asset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> * @nodeName: name of the element * @ * */ public static Document addNodeWithNSAttribute(Document document, String nodeName, String attrName, String namespace) { Element node = document.createElement(nodeName); Attr attr = document.createAttribute(attrName); attr.setValue(namespace); node.setAttributeNodeNS(attr); document.appendChild(node); return document; } }