Thank you very much for the replies. I got it working, true the default namespaces does seem a little tricky.

On Monday, February 17, 2014 4:52 AM, Michael Kay <> wrote:
I think you have asked this question in several places and have received an answer.

The treatment of the default namespace by XPath is something that many beginners find puzzling, but Saxon is behaving as required by the specs.

Michael Kay

On 15 Feb 2014, at 18:45, Pratap Nataraj <> wrote:


I wanted some help/info related to xpath parsing of default namespace using saxon. I am using the Saxon-HE-9.5.1-3.jar to use xpath 2 features in my code. After including the saxon library in the class path, I am facing a issue parsing xpath for XML documents with default namespaces.

Sample XML in am using :
<?xml version="1.0" encoding="utf-8"?>
<RESPONSE  xmlns=""200">


Below are the cases where it works and does not work:
1. "XPATH Works" : When no namespace is specified
Example : <RESPONSE  responseCode="200">

2. "XPATH Works" : When namespace with prefix is given
Example : <RESPONSE  xmlns:res=""200">

3. "XPATH does not work" : When default namespace with out prefix is given
Example : <RESPONSE  xmlns=""200">

Can you please help me out on why saxon treats no namespace and default namespace in a different way ?
Also how do I solve the case of doing xpath for documents with default namespace.

Below is chunks of my code:
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import net.sf.saxon.xpath.XPathEvaluator;
import net.sf.saxon.xpath.XPathFactoryImpl;


DocumentBuilder builder;
Document doc;

DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
builder = domFactory.newDocumentBuilder();
doc = builder.parse(new ByteArrayInputStream(b, 0, size));

XPathFactory factory = XPathFactoryImpl.newInstance(XPathConstants.DOM_OBJECT_MODEL);
XPathEvaluator xpathCompiler = (XPathEvaluator) factory.newXPath();
XPathExpression expr = xpathCompiler.compile(xpath);
NodeList childNodes = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);

Thanks & Regards

Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
saxon-help mailing list archived at