Java tutorial
//package com.java2s; //License from project: Apache License import org.w3c.dom.Element; import javax.xml.XMLConstants; public class Main { private static final String XMLNS_XSI = "xmlns:xsi"; private static final String XSI_SCHEMA_LOCATION = "xsi:schemaLocation"; /** * Sets the namespace to specific element. * * @param element * the element to set * @param namespace * the namespace to set * @param schemaLocation * the XML schema file location URI */ public static void setNamespace(Element element, String namespace, String schemaLocation) { element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE, namespace); element.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLNS_XSI, XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI); element.setAttributeNS(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, XSI_SCHEMA_LOCATION, schemaLocation); } }