Always get a null exception while useing XPATH Saxon-8b

R

Rishabh.Dayal

Hi,

I always get a null exception while using XPATH Saxon-8b. I am using
this for the first time.

My xml document is:
<foo xmlns="default-namespace">
<ns1:bar xmlns:ns1="namespace1-uri" xmlns="namespace1-uri">
<baz/>
<ns2:baz xmlns:ns2="namespace2-uri"/>
</ns1:bar>
<ns3:hi xmlns:hi="namespace3-uri">
<there/>
</ns3:hi>
</foo>

XPATH expression is /foo/a:bar/b:baz
java code is:

String xpathExpr = "/foo/a:bar/b:baz";

try
{
XPathFactory xpf =
XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
}
catch( javax.xml.xpath.XPathFactoryConfigurationException exception
)
{
System.out.println( "Exception XPathFactory.newInstance" );
}

StandaloneContext context = new StandaloneContext();
context.declareNamespace("a","namespace1-uri");
context.declareNamespace("b","namespace1-uri");
NamespaceContext namespaceContext = new
NamespaceContextImpl(context);
InputSource is = new InputSource(xmlExpr);
SAXSource ss = new SAXSource(is);
XPathEvaluator xpe = new XPathEvaluator();
xpe.setNamespaceContext(namespaceContext);

String result = null;
try
{
result = xpe.evaluate(xpathExpr, ss);
}
catch( javax.xml.xpath.XPathExpressionException exception )
{
System.out.println( exception.getCause() );
}

Any suggestions would be of great help.

Thanks
-Anurag
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top