Unknown error in XPath (using variables)

T

Tim Hallwyl

Hi there!

I am trying to evaluate an XPath expression using variables, like this:
"$foo/Street" -- where $foo is a variable with an Address element,
containing a Street element:

<Address>
<ID>Fakturering</ID>
<Street>Holsteinsgade</Street>
<HouseNumber>63</HouseNumber>
<CityName>København Ø.</CityName>
<PostalZone>2100</PostalZone>
<Country>
<Code>DK</Code>
</Country>
</Address>

While evaluating the simple "$foo" expression works fine, the
"$foo/Street" expression throws an exception with the message "Unknown
error in XPath".

Any help, hints or references to documentation is appreciated. Thank you
for your time. I hope to be able to help you out some day.

The attached source code and XML file illustrates this problem if you
like to try it out your self. I used a JDK 1.5.0_08.
 
M

Martin Honnen

Tim Hallwyl wrote:

NodeList result = (NodeList) xpath.evaluate(expression, (Object) null, XPathConstants.NODESET);

Have you tried passing in an object like that document you have as the
second argument, and not null like you do?
 
T

Tim Hallwyl

Hi Martin!
Have you tried passing in an object like that document you have as the
second argument, and not null like you do?

Well, I have now -- and it works!! So I'm grateful for you help!

However it is supposed to work with "null" according to the interface
description:

"If a null value is provided for item, an empty document will be used
for the context."*

But it works even if the document passed is an newly created (empty) one
-- so it will do.

Thank you for your help!

--tim

* see
http://java.sun.com/j2se/1.5.0/docs... java.lang.Object, javax.xml.namespace.QName)
 
M

Martin Honnen

Tim Hallwyl wrote:

However it is supposed to work with "null" according to the interface
description:

"If a null value is provided for item, an empty document will be used
for the context."*

You might want to file a bug on that with Sun, they either need to
change the documentation or fix the code.
 
T

Tim Hallwyl

Martin said:
You might want to file a bug on that with Sun, they either need to
change the documentation or fix the code.

Ah, yes -- I found that is was already filed as a bug (id 6211561). Next
time I might take a look at the bug database first (however I did not
suspect it to be a bug at first, rather that I was missing out on some
thing -- but it is a bug)
 

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

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top