|
XPath filter for SAX in Java
|
[
Lists Home |
Date Index |
Thread Index
]
- To: xml-dev@lists.xml.org
- Subject: XPath filter for SAX in Java
- From: Phil Nash <phil.nash.lists@gmail.com>
- Date: Mon, 19 Sep 2005 23:28:23 -0400
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type; b=dBz3BaQvi3HnD5nwqOhqp2+iTnMfew2P3CR38sOPHe2KNruwaHko7Wk3nftC4Dq8TNsxpfc8KFm/78nu7IKQmHx0ls6KrAUZDq3b6D7jAnrZ7rywIll7OiZSpM6F/ZAhLHAmdYrS5XdjwMuQdsX+Th7vmK0rbAi2c+ykEt7mL+8=
- Reply-to: Phil Nash <phil.nash.lists@gmail.com>
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..
|
|
|
|
|