I don't think there's a way to do that.  The Xerces parser APIs allow
you to specify InputSources, not other parsers.  Perhaps there's a way
to construct an InputSource from a SAX parser, but if so, it's not
obvious to me.  Even if it's possible, it would be inefficient; the
InputSource would convert have to convert SAX events into a stream that
would then be handed to another SAX parser that would then recreate the
events.

I gather the goal here is to get a DOM representation of an element in a
document (including its children, of course) without the overhead of
representing the whole document.  It's an interesting problem, and one
that others have presumably faced.  Maybe someone on the list has solved
it differently.

-----Original Message-----
From: news [mailto:[EMAIL PROTECTED] On Behalf Of Patrick Rotsaert
Sent: Thursday, March 08, 2007 10:50 AM
To: [email protected]
Subject: Re: SAX and DOM

Hi Jesse,

I also understood that the DOM parses uses SAX internally. But is it
possible to 'override' this in some way? What I mean is, once I find the
element I am interested in (using SAX), can I create a DOM parser that
uses that very same SAX parser instance (instead of creating it's own)
and starts parsing at the 'current' SAX element and stops parsing at the
end of the element?

Thanks,
Patrick

On 8/03/2007 16:29, Jesse Pelton wrote:
> I should think so.  The DOM parser creates the entire tree this way;
I'd
> think you could wait for SAX to present the element you're looking
for,
> then use standard DOM create...() functions to build your tree from
> there.  Your parser would need to keep track of its present state (am
I
> parsing something that needs to go into the DOM, and if so, where in
the
> tree am I?).
> 
> Of course, DOM is not particularly space-efficient, so a native
> representation of the data would be better if that's an option.
> 
> -----Original Message-----
> From: news [mailto:[EMAIL PROTECTED] On Behalf Of Patrick Rotsaert
> Sent: Thursday, March 08, 2007 10:20 AM
> To: [email protected]
> Subject: SAX and DOM
> 
> Hi all,
> 
> Is it possible to parse a XML file using SAX and create a DOM tree of
a
> part of the file?
> 
> Thanks,
> Patrick
> 
> 

Reply via email to