Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Unknown error in XPath (using variables)

Thread view: 
Tim Hallwyl - 26 Sep 2006 17:07 GMT
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.
Martin Honnen - 26 Sep 2006 17:28 GMT
>             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?

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/

Tim Hallwyl - 26 Sep 2006 17:58 GMT
Hi Martin!

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

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/api/javax/xml/xpath/XPath.html#evaluate(java
.lang.String,%20java.lang.Object,%20javax.xml.namespace.QName
)
Martin Honnen - 26 Sep 2006 18:42 GMT
> 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.

Signature

    Martin Honnen
    http://JavaScript.FAQTs.com/

Tim Hallwyl - 27 Sep 2006 18:22 GMT
> 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)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.