|
From: <Ste...@zv...> - 2001-10-01 09:18:36
|
Mats Bengtsson wrote:
> Steve Ball wrote:
> > Mats Bengtsson wrote:
> > >
> > > The docs for TclXML specify the -errorcommand proc to take two parameters,
> > > 'tclProc errorcode errormessage', but browsing through the 'sgmlparser.tcl'
> > > file, the error proc is usually called as:
> > >
> > > uplevel #0 $options(-errorcommand) "$attr around line $state(line)"
> ...
> > >
> > > Am I right here?
> >
> > Hmmm... yes I'd say so. The Error procedure in sgml-8.[01].tcl simply
> > uses 'args'. Sorry about that! Would you care to submit a patch? ;-)
> >
>
> Since I don't know the code that well, the risk is that I create more
> errors than I fix.
That's what the regression test suite is for. Make your changes, and
then
run 'make test'.
> One related issue. If I make a crude workaround by having 'args' in
> the errorcommand proc, see below, the elementendcommand fails,
> see stack below. What is the correct procedure to make the best
> error recovery?
>
> code-----------------------------------
> set data2 {<stream:error>Invalid XML</stream:error>}
> .
> proc HandleErrorFix {args} {
> global myParser
>
> puts "HandleErrorFix ==> args=$args"
> $myParser reset
> $myParser free $myParser
> }
>
> set myParser [xml::parser]
> $myParser configure -elementstartcommand HandleStart \
> -elementendcommand HandleEnd -characterdatacommand HandleText \
> -final 0 -errorcommand HandleErrorFix
>
> $myParser parse $data2
You're destroying the parser state while it is in the middle of parsing.
You must return an error code of TCL_ERROR or TCL_BREAK in order to
terminate
the parser. For example:
proc HandleErrorFix {args} {
global myParser
puts "HandleErrorFix ==> args=$args"
#$myParser reset
#$myParser free $myParser
return -code break
}
The reset and free calls are commented out because I don't believe
that's
a reasonable thing to do at that point.
Cheers,
Steve Ball
--
Steve Ball | XSLT Standard Library | Training & Seminars
Zveno Pty Ltd | Web Tcl Complete | XML XSL Schemas
http://www.zveno.com/ | TclXML TclDOM | Tcl, Web Development
Ste...@zv... +---------------------------+---------------------
Ph. +61 2 6242 4099 | Mobile (0413) 594 462 | Fax +61 2 6242 4099
|