You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Guy Umbright <um...@taltrade.com> on 2000/08/15 18:10:37 UTC

How to bail out of a SAX parse?

Is there a built in way to bail out of a SAX parse?  Here is my situation:

The XML files I am dealing with have 2 main sections

<THEFILE>
	<FOO>
	  :
	</FOO>
	<BAR>
	  :
	</BAR>
</THEFILE>

I want to be able to tell the parser to stop after I finish processing the
<FOO>
section. Is there a function call or value that can be set that will then
cause 
the parse function to just return?

Guy Umbright

RE: How to bail out of a SAX parse?

Posted by Rich Taylor <rt...@webmd.net>.
Guy,

I, too, looked for "some way out" when I wanted to
stop a SAX parse.  I haven't found it yet.

So, I made my own escape by using Xerces' partial parsing
mechanism - i.e. calling parseFirst() then repeated calls
to parseNext().

I gave my document handler object a pointer to the
"parent object" (whose method is calling Xerces to do
the parse).  When the document handler hits some sort
of exit situation it sets a flag in the parent object.

My "parent object" just checks this flag between calls
to parseNext() - if the exit flag's set then I stop
doing the parse sequence.

This works...  But it would be nice to have an
escape call that I could call within document handler
to bail out.  (It would also be nice to have this
mechanism throw a error or something with details
that my doc handler code supplies - this would allow
me to catch Xerces and my own exceptions in the
same framework.)

- Rich Taylor, WebMD

> -----Original Message-----
> From: Guy Umbright [mailto:umbright@taltrade.com]
> Sent: Tuesday, August 15, 2000 12:11 PM
> To: 'xerces-c-dev@xml.apache.org'
> Subject: How to bail out of a SAX parse?
>
>
> Is there a built in way to bail out of a SAX parse?  Here is my situation:
>
> The XML files I am dealing with have 2 main sections
>
> <THEFILE>
> 	<FOO>
> 	  :
> 	</FOO>
> 	<BAR>
> 	  :
> 	</BAR>
> </THEFILE>
>
> I want to be able to tell the parser to stop after I finish processing the
> <FOO>
> section. Is there a function call or value that can be set that will then
> cause
> the parse function to just return?
>
> Guy Umbright
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>