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
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