Here you can find the source of getNamespace(Node node)
public static String getNamespace(Node node)
//package com.java2s; //License from project: Open Source License import java.util.HashMap; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { public static String getNamespace(Node node) { Element root = node.getOwnerDocument().getDocumentElement(); HashMap<String, String> namespaces = getAllAttributes(root); String prefix = getPrefix(node.getNodeName()); if (prefix == null) return namespaces.get("xmlns"); return namespaces.get("xmlns:" + prefix); }/*w ww . j av a2 s .c o m*/ public static HashMap<String, String> getAllAttributes(Node node) { HashMap<String, String> attributes = new HashMap<String, String>(); NamedNodeMap attr = node.getAttributes(); for (int j = 0; j < attr.getLength(); j++) { attributes.put(attr.item(j).getNodeName(), attr.item(j).getNodeValue()); } return attributes; } public static String getPrefix(String value) { try { return value.substring(0, value.indexOf(":")); } catch (Exception e) { } return null; } }