>I am trying to select a node in a document based on a xpath but using SAX.
Is there an implementation of >an XPath adapter/handler that would generate
events when a node that is part of the XPath is reached?
Xalan doesn't currently have a "streaming XPath" function. You can't
actually do it very well if you want full XPath support, since some
expressions can't be resolved until the whole document has been considered
-- one contrived example being "//foo[following::bar]", where you can't be
sure the <foo/> does not match until you've completely exhausted the
possibility that a <bar/> will appear later in the document. So we couldn't
guarantee immediate results when the node was reached... and keeping around
nodes which might-or-might-not eventually match, plus enough context to do
something useful with them if they do match, has so far seemed
prohibitively expensive. (The problem gets worse when, as in XSLT, you're
trying to manage multiple XPaths at once plus result trees.)
If you were willing to restrict yourself to a simplified subset of XPath,
this would be much more practical. We are hoping to eventually be able to
recognize this sort of special-case and switch over to code optimized
specifically for it, but that's still an area where we have to do more
research.
For now, the best suggestion I can offer is Xalan-J's incremental DTM mode,
briefly mentioned at
http://xml.apache.org/xalan-j/dtm.html#incremental
which attempts to build only as much of the data model as is actually
needed by the stylesheet. It still reads the whole SAX stream, though,
since I was told I wasn't allowed to shut down the SAX source by throwing
an exception from the handler and SAX didn't offer any other way to stop
parsing.
______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk