You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Daniel Smith <da...@actional.com> on 2002/10/31 05:26:52 UTC

Using SAX to apply XPATHS?

Hello!

I am new to Xalan-J (and a bit new to SAX parsers but have read some
online docs).

I would like to know if I can and how to do the following:

I want to apply XPATHs to an input XML document.  The XML document
must be parsed using a SAX parser.  The SAX parsing should, if possible,
be performed incrementally.

The idea is, to start this process, and keep the partially parsed input
and DTM in my test app for reuse.  I'd like to be able to come back
and apply more XPATHs for extracting data from the document without
having to restart the parse or rebuild the internal DTMs.  I would
only restart when I have a new input XML document.

The API docs give some clues that it may involve SAX2DTM and possibly
CachedXPathAPI or XPathAPI but I am unsure of the details.  For one thing,
I cannot use DOM for performance reasons.  But the two XPATHAPIs eval()
methods seem to require DOM Nodes.

Is there a way around this?

Best regards / AmitiƩs / Saludos,

Daniel D. Smith

Re: Using SAX to apply XPATHS?

Posted by k1...@mail.theotherbell.com.
I'm watching this thread closely because I may also have a need to do
something similar and am interested in the outcome.

Rumor has it that Joseph Kesselman said:
> And  in a case like yours, where you're using the XPath API
> rather than a stylesheet, we might not even have the information
> available  to allow us to apply the proposed pruning/filtering
> solutions; those  really requre that we know all the XPaths that
> might be applied, which  means they might work only on stylesheets.

I'm new to Xalan and still trying to get my arms from DTM's and in
particular translets... but I'm wondering if it would be possible to
extend the translet concept to XPath -- a way of constructing and
precompiling XPath expressions such that they are optimized from the
start.

-- 
Cheers,

    Brenda



Re: Using SAX to apply XPATHS?

Posted by Joseph Kesselman <ke...@us.ibm.com>.
That's an interesting question. I'm not sure you _can_ currently request 
incremental parsing when using our XPath APIs (as opposed to running a 
stylesheet), since the normal way we request incremental mode is via a 
flag on the TransformerFactory object (see 
http://xml.apache.org/xalan-j/dtm.html#incremental). We should look into 
that...

You might want to search archives of this mailing list for past 
discussions (keywords "incremental", "streaming", "prune", "pruning", 
"filter", "filtering"). Incremental mode does _not_ always reduce memory 
use; if your XPaths need to search the whole document, the whole document 
*will* be loaded into memory at once, due to the random-access nature of 
the XPath language. Incremental mode reduces latency before output starts, 
and *may* reduce memory usage if the XPaths stop before the end of the 
document, but its performance effects will depend on exactly what you're 
trying to do. And  in a case like yours, where you're using the XPath API 
rather than a stylesheet, we might not even have the information available 
to allow us to apply the proposed pruning/filtering solutions; those 
really requre that we know all the XPaths that might be applied, which 
means they might work only on stylesheets. (Unless we extend the XPath 
APIs to allow preloading that information... which is an interesting idea, 
actually.)

______________________________________
Joe Kesselman  / IBM Research