Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Always get a null exception while useing XPATH Saxon-8b

Reply
Thread Tools

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

 
 
Rishabh.Dayal@gmail.com
Guest
Posts: n/a
 
      09-22-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get "java.lang.OutOfMemoryError" when Parsing an XML useing DOM NeoGeoSNK Java 29 03-27-2007 01:32 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
limited or no connectivity xphome useing bt2110 router =?Utf-8?B?Y2F6NHlvdQ==?= Wireless Networking 0 10-30-2005 11:25 AM
copy tftp to switch by useing snmpset strauch t Cisco 2 11-10-2003 07:20 AM



Advertisments