From: Steve B. <Ste...@zv...> - 2000-12-05 03:27:02
|
Dear All, I've been doing some work on new commands for XML processing, and the issue of push XML parsers versus pull XML parsers has cropped up. Please read the overview below, and let your thoughts be known on whether this proposal would be worth the effort. Currently, TclXML is mostly a push model parser. The application feeds the parser with data. However, sometimes the parser will ask for data, notably when an external entity reference is encountered. In contrast, a pull model parser will ask for data when it becomes starved of input to parse. This might be a cleaner model to use, because it would allow data from the document entity and external entities to be treated the same way. It may easier to control reading data incrementally when the parser is being used by some higher-level package (for example, TclDOM). I shall propose a new option for TclXML: '-getdatacommand'. The value for this option would be a Tcl script which returns XML data. This script is invoked when the parser requires more data. When data is required for the current entity, no arguments are appended. If data is required from an external entity then the public and system identifiers are appended as arguments. An (incomplete) example: set ch [open mydoc.xml] ;# this could be a socket... fconfigure $ch -blocking no fileevent $ch readable [list gotdata $ch] set parser [xml::parser -getdatacommand [list pull $ch]] $parser parse [read $ch] ;# we can supply initial data if available proc pull {ch {publicid {}} {systemid {}}} { global dataAvailable switch -glob -- $publicid,$systemid { , { # Need to wait on input to be ready, check eof, etc. vwait ::dataAvailable return $dataAvailable } *, { # Public identifier only } ,* { # System identifier only set token [http::geturl $systemid] return [http::data $token] } default { # Both public and system identifier given } } } proc gotdata ch { global dataAvailable if {[eof $ch]} { close $ch set dataAvailable {not any more} } else { set dataAvailable [read $ch] } } -- Steve Ball | waX Me Lyrical XML Editor | Training & Seminars Zveno Pty Ltd | Web Tcl Complete | XML XSL 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 |