Java tutorial
//package com.java2s; import javax.xml.namespace.NamespaceContext; import javax.xml.namespace.QName; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import org.w3c.dom.Document; public class Main { public static String getNamespace(Document document) throws XPathExpressionException { return (String) evaluateXpath("//mapper/@namespace", document, XPathConstants.STRING, null); } public static Object evaluateXpath(String expression, Object node, QName returnType, NamespaceContext nsContext) throws XPathExpressionException { XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xpath = xpathFactory.newXPath(); if (nsContext != null) { xpath.setNamespaceContext(nsContext); } return xpath.evaluate(expression, node, returnType); } }