Skip to Content.
Sympa Menu

xom-interest - RE: [XOM-interest] Sparta: similar to XOM.

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: "O'Brien-Strain, Eamonn" <eob AT exch.hpl.hp.com>
  • Cc: "'xom-interest AT lists.ibiblio.org'" <xom-interest AT lists.ibiblio.org>
  • Subject: RE: [XOM-interest] Sparta: similar to XOM.
  • Date: Sun, 29 Sep 2002 17:50:34 -0400

At 2:11 PM -0700 9/29/02, O'Brien-Strain, Eamonn wrote:


In the Sparta XPath subset it is possible to statically determine, just by parsing the XPath expression, whether it selects an element or a string. There are different xpathSelect*() methods for returning Elements and Strings. For example:

Element foo = doc.xpathSelectElement( "/Top[@g='ggg']/Foo[4]" );
String bar = doc.xpathSelectString( "/Top[@g='ggg']/Foo[4]/@bar" );

There are also versions that return iterators over Elements or Strings -- in the case of multiple matches the above methods return the first match.

The methods throw an exception when the wrong type of XPath is passed to them.

I can't say I like that, but I also can't say I've thought of anything better. In fact, my failure to think of an API for this I actually like is part of the reason I haven't yet added XPath support to XOM. I think XPath's weak typing has real impedance mismatches with strongly typed languages such as Java. I'm not sure there is a good solution for this.

Sparta partially solves the problem in part by restricting the XPaths it can handle. Looking at the BNF, it seems your grammar is actually a little more restricted than just the abbreviated XPath syntax. For instance, no XPath functions or operators in predicates, and no support for the node() node test. I suspect the latter is particularly important for being able to statically determine the type of an expression.
--

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo AT metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| XML in a Nutshell, 2nd Edition (O'Reilly, 2002) |
| http://www.cafeconleche.org/books/xian2/ |
| http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+




Archive powered by MHonArc 2.6.24.

Top of Page