NamespaceContextImpl nsctx = new NamespaceContextImpl();
nsctx.setNamespaceURI("xml", "http://www.w3.org/XML/1998/namespace");
nsctx.setNamespaceURI("xhtml", "http://www.w3.org/1999/xhtml");
xpath.setNamespaceContext(nsctx);
The source XML document is an XHTML web page with its root element being declared as belonging to http://www.w3.org/1999/xhtml namespace:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
I can't see anything wrong with the xpath expression, nor can I find any documentation explaining why an XPathExpressionException would be thrown in this case.
Could you tell any possisble causes for the exception being thrown?