XPATH使用namespace

XPath xpath = XPathFactory.newInstance().newXPath();
NamespaceContext nsContext = new XHTMLNamespaceContext();
xpath.setNamespaceContext(nsContext);
XPathExpression expr = xpath.compile("//xhtml:TABLE");


public class XHTMLNamespaceContext implements NamespaceContext {

@Override
public String getNamespaceURI(String prefix) {
return "http://www.w3.org/1999/xhtml";
}

@Override
public String getPrefix(String namespaceURI) {
throw new UnsupportedOperationException();
}

@Override
public Iterator getPrefixes(String namespaceURI) {
throw new UnsupportedOperationException();
}

}

你可能感兴趣的:(JAVA)