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

Re: XPath filter for SAX in Java


parse xpath
On Mon, 2005-09-19 at 23:28 -0400, Phil Nash wrote:
> Hi all,
> 
> This sounds like something that would be very useful, and obvious -
> and yet after spending quite some time searching I've yet to find a
> concrete implementation! I've caught whispers here and there that it
> can be done, perhaps by hooking into the Saxon or Xalan libraries, but
> in the end it's still elluding me.
> 
> So what is it?
> 
> I just want to be able to (in Java - and 1.5 is fine) give an XML
> document to a SAX parser and have events fired when certain,
> pre-registered, XPath expressions are matched.
> To put it another way, I want to layer a set of XPath filters over a
> SAX parser.
> Naturally only a subset of XPath is meaningful within the SAX context,
> and ideally I'd like to see a couple of extensions to cater for the
> dynamic nature of SAX parsing (in particular, a way of specifying
> "node tests" for closing tags).
> 
> An example could be something like (pseudo code):
> 
>   SaxPathParser parser = new SaxPathParser();
>   parser.AddHandler( "/TestDoc/Node1/Node2", new NodeHandler() );
>   parser.AddHandler( "/TestDoc/Node1/text()", new TextHandler() );
>   parser.AddHandler( "//Node3/endtag()", new EndTagHandler() );
> 
>   parser.parse();
> 
> I've started an implementation along the above lines that wraps a JAXP
> SAX parser, but handling things like the // operator efficiently is
> something that I'd rather leave to a dedicated library if possible.
> 
> So does anyone know of an XPath filter for SAX parsers, or something
> which achieves essentially the same thing? I really don't want to have
> to parse a full DOM tree when I just want to catch a few XPath
> specified nodes.

FWIW, in a long conversation on this point earlier this year I pointed
out that I had in Amara XML Tools a Python framework for just this
capability.  I thought a couple of Java folks chimed in that they had
similar.  Perhaps look into Nux?


-- 
Uche Ogbuji                               Fourthought, Inc.
http://uche.ogbuji.net                    http://fourthought.com
http://copia.ogbuji.net                   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/


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.