Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Using Jaxen XPath

Reply
Thread Tools

Using Jaxen XPath

 
 
Anna
Guest
Posts: n/a
 
      04-04-2004
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>

I want to get the first preceding element of the div element.
I apply the following XPath - //div/preceding::*[1]
Saxon results in span element matched.
Jaxen results in p element matched.

What I want is the span element.

From what I understood (I may be wrong), the difference in results is
because
Jaxen uses bredth first search, when saxon uses depth first search.

I can maybe construct something more specific to match the element I
want for Jaxen,but the problem is that my queries are already
complicated, and adding a lot more predicates slows the whole
evaluation drastically.

So I wondered if there is any elegant way to match nodes in Jaxen by
document order, in particular, match the closest preceding element to
a context element.

Sorry if this has been asked before, I've been searching for an answer
for a while, and didn't find anything.

Thank you very much for help.

Anna
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      04-04-2004


Anna wrote:


> 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>
>
> I want to get the first preceding element of the div element.
> I apply the following XPath - //div/preceding::*[1]
> Saxon results in span element matched.
> Jaxen results in p element matched.
>
> What I want is the span element.
>
> From what I understood (I may be wrong), the difference in results is
> because
> Jaxen uses bredth first search, when saxon uses depth first search.


I think that Jaxen is wrong here, it should yield the first preceding
element in reverse document order.

> I can maybe construct something more specific to match the element I
> want for Jaxen,but the problem is that my queries are already
> complicated, and adding a lot more predicates slows the whole
> evaluation drastically.
>
> So I wondered if there is any elegant way to match nodes in Jaxen by
> document order, in particular, match the closest preceding element to
> a context element.


Well, with Jaxen then using
[last()]
instead of
[1]
as the predicate should give you what you want but I think it is better
to file a bug report on Jaxen, citing
http://www.w3.org/TR/xpath#predicates
--

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

 
Reply With Quote
 
 
 
 
Anna Afonchenko
Guest
Posts: n/a
 
      04-04-2004
I think Jaxen is giving the wrong answer too, that's why I posted.
Jaxen list seems to be not very active lately, that's why I first tried
here. I'll post to them anyway then.
By the way, for my example //div/preceding::*[last()] will return p, but
for a full page, say
<html>
<head>
</head>
<body>
<p>
<span>text1</span>
</p>
<div>text2</div>
</body>
</html>

this XPath in Jaxen will return head element as a match!

Thank you for your help and advice.

Anna

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
 
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
"Memory leak" in javax.xml.xpath.XPath Marvin_123456 Java 4 07-29-2005 03:49 PM
XPath: efficiency in xpath expressions Tjerk Wolterink XML 1 11-13-2004 06:03 PM
Are there any XPath parsers that generate XPath trees? goog XML 0 01-14-2004 01:47 PM
XPath that does not include other XPath Anna XML 0 07-31-2003 07:55 AM
Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal? Alastair Cameron XML 1 07-08-2003 07:24 PM



Advertisments