OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] XPath filter for SAX in Java

[ Lists Home | Date Index | Thread Index ]

This is remarkably similar to the way Saxon started life, when it was just a Java SAX library and not an XSLT processor... I got rid of it because supporting serial and tree-based processing in the same code was getting too difficult.
 
I didn't have separate handlers or events for the start and end tag, I had a single NodeHandler that was notified of both the start and end events using different method calls.
 
You probably want to think in terms of the conditions being XSLT patterns rather than arbitrary XPath expressions. Alternatively, use the XML Schema subset of XPath. In fact Saxon-SA internally does now have a mechanism which works very like this, used as part of the schema validator for evaluating key/unique constraints, and supporting only the XML Schema XPath subset. 
 
 
Michael Kay


From: Phil Nash [mailto:phil.nash.lists@gmail.com]
Sent: 20 September 2005 04:28
To: xml-dev@lists.xml.org
Subject: [xml-dev] XPath filter for SAX in Java

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.

Thanks and best regards,

[)o
IhIL..





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS