Here you can find the source of setAttributeNS(Element node, String namespaceURI, String prefix, String nodeName, String value)
Parameter | Description |
---|---|
node | the node the attribute will be added to |
namespaceURI | the URI of the underlying namespace |
prefix | the namespace prefix for this attribute (w/o ':'); may be null |
nodeName | the node name w/o prefix and ':' |
value | the attribute's value |
public static void setAttributeNS(Element node, String namespaceURI, String prefix, String nodeName, String value)
//package com.java2s; /*//from w ww . ja va 2 s. com * The MIT License (MIT) * * Copyright (c) 2010 Technische Universitaet Berlin * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ import org.w3c.dom.Element; public class Main { private static boolean printXMLNamespaces; /** * Adds the named attribute with the given namespace URI and value to the given element node. * The full attribute name is constructed by the prefix followed by a colon and finally the real node name. * If the prefix is null, the full name equals the node name. * This method contains a workaround for older Java versions. * * @param node the node the attribute will be added to * @param namespaceURI the URI of the underlying namespace * @param prefix the namespace prefix for this attribute (w/o ':'); may be null * @param nodeName the node name w/o prefix and ':' * @param value the attribute's value * @see Element#setAttributeNS(java.lang.String, java.lang.String, java.lang.String) */ public static void setAttributeNS(Element node, String namespaceURI, String prefix, String nodeName, String value) { String fullName = (prefix == null) ? nodeName : prefix + ":" + nodeName; node.setAttributeNS(namespaceURI, fullName, value); if (printXMLNamespaces) { String attrName = (prefix == null) ? "xmlns" : "xmlns:" + prefix; node.setAttribute(attrName, namespaceURI); } } }