473,385 Members | 2,269 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,385 software developers and data experts.

Using Jaxen XPath

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
Jul 20 '05 #1
2 2670


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/

Jul 20 '05 #2
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!
Jul 20 '05 #3

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

Similar topics

0
by: bdinmstig | last post by:
I am building various framework components for my team to use in development, and one of those components is a Facade for reading/writing user preferences. The idea is that preference settings...
1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
6
by: 0wl | last post by:
Hi, I am trying to get the value of child from xmlstr = """<p:root xmlns:p="http://tempuri.org/string"><p:child DataType="String">Hellpppp</p:child></p:root>""" using...
0
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"...
2
by: ree32 | last post by:
When I import an xml document in Visual studio and Genereate as schema from it, and create a dataset from it, it adds this line into to the root element of my xml file -...
3
by: Goran Djuranovic | last post by:
Hi All, Does anyone know how to retreive deepest XPath value from XML document by using VB.NET? For example, if I had an XML file like this: <Root> <Customer> <Name>MyName</Name> </Customer>...
3
by: Brian | last post by:
Using external XML, I'm trying to build a quiz, but I can't seem to specify the DataSource for the RadioButtonList within a Repeater ItemTemplate. I've tried a number of approaches, but I haven't...
4
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
5
by: rcronk | last post by:
I'm new to C#/.NET. I am writing some C#/.NET (2.0) classes that will allow someone to get and set values in an XML file using an XPath to point to the location of that data. It's more complicated...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.