[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XPath calculation

  • From: Robin Berjon <robin@k...>
  • To: "Vakulenko, Andrey V" <andrey.vakulenko@e...>
  • Date: Fri, 09 Feb 2001 23:09:58 +0100

xpath calculation
At 15:42 09/02/2001 -0600, Vakulenko, Andrey V wrote:
>I am looking for Java implementation of an algorithm for finding the most
>generic and short XPath expression for a selected element in DOM (XML
>document). Any ideas and recommendations are welcomed.

You'd need to specify your requirements a little more. Do you mean an XPath
that is certain to match that element (and potentially others) or one that
matches that one and only that one ? I guess it's the latter because the
former is ultra-trivial (unless you have specific needs not stated here).

Also, is it possible that your DOM would change or is it for a DOM that
won't change ?

The first thing I'd do (I think) is check to see if that element has an id,
and if so use that. A properly optimized get_element_by_id() will get it
fast, and it certainly makes for the shortest (I think) XPath expression
that'll select that element. If your element doesn't have an idea but one
of it's parent's does, then you could start selecting from that parent.
Likewise if it has a sibling or even a child with an id.

Otherwise, a path listing all the parent elements + their position and the
element + it's position might be the most generic way.

If you have a schema for your document then you can probably apply specific
rules, it all depends on your needs and what you have at hand.

Amaya displays the path to the current element in the context bar. I don't
remember if it's expressed as XPath but it isn't far from it for sure. You
might want to take a look at it (though obviously it isn't Java).

-- robin b.
There are trivial truths and there are great Truths. The opposite of a
trival truth is obviously false. The opposite of a great Truth is also
true.  -- Neils Bohr 


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.