473,320 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

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

Sep 22 '05 #1
0 1149

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Sebastian Petzelberger | last post by:
Hi group, please give me an example of a xpath with regex or better a link with examples. Thanks in advance, Sebastian
2
by: Anna | last post by:
Hi all. I am using Jaxen to evaluate XPath expressions in Java. I encountered problems when comparing results returned by jaxen with results returned by other XPath implementation - I was using...
1
by: Murtaza Tinwala | last post by:
Hi mates, I have the following problem in XSLT. I have following variables: ref-file = <path of XML document> eg "xmlDoc.xml" repeatpath = <a repeat path expressed in Xpath like /root/person >...
6
by: Stefan Franke | last post by:
Hi, I've got a little bit of a problem when dealing with namespaces and XPath. I'm trying very basic things, like showing all the nodes of one particular namespace. Here is my XPath statement:...
4
by: Christofer Dutz | last post by:
Hi, I just ran into an interesting situation, where I was not able to write an xpath expression doing what I want it to. Mabe someone here can help me ... I hope ;) Here a sample xml-file I...
1
by: Loudin | last post by:
Hello, I`ve got Problems with Xpath and xsltproc/libxslt. I have got a variable with tags in my Style sheet and later in the same Style sheet i want to work with this tags using a...
7
by: Scott W Gifford | last post by:
Hello, I'm considering using XML to represent a stream of location information, and XPath to do queries against it. I've got most of it figured out (at least on paper), but I can't figure out...
1
by: Philipp Schumann | last post by:
Hi .NET XML fans, does anyone know ad hoc whether support for the above standards is planned for .NET 2.0? I suppose this would be extremely valuable for many folks... Thanks, Phil
2
by: Felix Engelhardt | last post by:
Hi there, I'm having a problem compiling an XSL-stylesheet using JAXP/Xalan which is really driving me nuts... When I try to compile a stylesheet that contains something like: <xsl:value-of...
3
by: Bloody Viking | last post by:
Namaste, Y'all! I've got a valid XQuery expression that I need to convert to XPath 2.0. This expression will be stored in a resource file and applied to XML by a Java program with saxon8.jar...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.