473,795 Members | 2,892 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="name space1-uri" xmlns="namespac e1-uri">
<baz/>
<ns2:baz xmlns:ns2="name space2-uri"/>
</ns1:bar>
<ns3:hi xmlns:hi="names pace3-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.ne wInstance(Names paceConstant.OB JECT_MODEL_SAXO N);
}
catch( javax.xml.xpath .XPathFactoryCo nfigurationExce ption exception
)
{
System.out.prin tln( "Exception XPathFactory.ne wInstance" );
}

StandaloneConte xt context = new StandaloneConte xt();
context.declare Namespace("a"," namespace1-uri");
context.declare Namespace("b"," namespace1-uri");
NamespaceContex t namespaceContex t = new
NamespaceContex tImpl(context);
InputSource is = new InputSource(xml Expr);
SAXSource ss = new SAXSource(is);
XPathEvaluator xpe = new XPathEvaluator( );
xpe.setNamespac eContext(namesp aceContext);

String result = null;
try
{
result = xpe.evaluate(xp athExpr, ss);
}
catch( javax.xml.xpath .XPathExpressio nException exception )
{
System.out.prin tln( exception.getCa use() );
}

Any suggestions would be of great help.

Thanks
-Anurag

Sep 22 '05 #1
0 1171

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

Similar topics

7
16660
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
2704
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 Saxon. Here is my example: <p> <span>text1</span> </p> <div>text2</div>
1
4272
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 > eg "/root/person" node = <name of a child node in repeat path> eg" "name" Now, I want to get to the 'node' in XSLT using Xpath.
6
2229
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: //* Unfortunately this doesn't work. I have found several ways to solve this with XSLT, but I need the pure XPath statement.
4
3866
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 want to do the query on: <?xml version="1.0" encoding="UTF-8"?> <cart> <product count="2" price="10.00" id="sdkjfhdaf-A"/>
1
1994
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 <xsl:for-each>. Here is a example:
7
2155
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 how to create an XPath statement asking for the "last node with a value less than" a given value. I need this to be able to ask "Where was Scott at 11:00 yesterday", which should find the last sighting of Scott before or at 11:00
1
1751
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
2300
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 select="encode-for-uri(/bla)"/> then I get a TransformerConfigurationException saying that there was an
3
3568
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 (I'm pretty sure it's v.8.7). The manifest from the jar file follows: Manifest-Version: 1.0 Ant-Version: Apache Ant 1.7.0 Created-By: 1.5.0_06-b05 (Sun Microsystems Inc.) Project-Name: Saxon-B
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9522
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.