pullparser(3tcl)
β¨ NAME β¨
okay so bestie, this page is all about tdom::pullparser β it's the manual for making an XML pull parser command π (and yeah, it lives in the Tcl manual, section 3tcl, iykyk)
πΈ SYNOPSIS πΈ
package require tdom
tdom::pullparser cmdName ?-ignorewhitecdata?
π¦ DESCRIPTION π¦
So this command creates XML pull parser commands, and the API is simple β like, think of a very chill StAX parser, that whole vibe. But listen: the second you create one, you don't have anything useful yet π you still gotta give it an input source. That's what the input, inputchannel and inputfile methods are for.
The parser always has a state, periodt. You parse the XML data forward until it hits some next state, do whatever you needed to do, then skip along to the next state. And if there's an XML well-formedness error along the way? It gets reported as TCL_ERROR, with extra info tucked into the error message. π
Here's the tea on what the pull parsers don't do:
- they don't follow external entities
- they're XML 1.0 only
- they know nothing about XML Namespaces
You get the tags and attribute names exactly as they show up in the source. Also, you get zero notifications about comments, processing instructions and external entities β they're just silently ignored for you, like they're not even there π CDATA Sections get handled as if their content had been provided without using a CDATA Section at all.
Now the brighter side, because there is one bestie π«Ά character entity and attribute default declarations in the internal subset are respected (that's because it's using expat as the underlying parser underneath). And it's probably somewhat faster than a comparable implementation with the SAX interface. Plus it's a nice programming model. Plus it's a slim interface. Slay.
If the option -ignorewhitecdata is given, the created XML pull parser command will ignore any white space only (' ', \t, \n and \r) text content between START_TAG and START_TAG / END_TAG. The parser won't stop at such input, and it'll create TEXT state events only for not white space only text. Obsessed. β¨
π¨ real talk: not all methods are valid in every state. If you call a method in a state it isn't valid for, the parser will raise TCL_ERROR. no cap.
Valid methods of the created commands are:
stateβ this one's valid in all parser states, queen behavior π The possible return values and their meanings are:READYβ the parser is created or reset, but no input is set.START_DOCUMENTβ input is set, parser is ready to start parsing.START_TAGβ parser has stopped parsing at a start tag.END_TAGβ parser has stopped parsing at an end tagTEXTβ parser has stopped parsing to report text between tags.END_DOKUMENTβ parser has finished parsing without error.PARSE_ERRORβ parser stopped parsing at XML error in input.
inputdata β only valid in stateREADY. It prepares the parser to use data as XML input to parse, and switches the parser into stateSTART_DOCUMENT.inputchannelchannel β only valid in stateREADY. It prepares the parser to read the XML input to parse out of channel, and switches the parser into stateSTART_DOCUMENT.inputfilefilename β only valid in stateREADY. It opens filename and prepares the parser to read the XML input to parse out of that file. The method returnsTCL_ERRORif the file could not be open in read mode. Otherwise it switches the parser into stateSTART_DOCUMENT.nextβ valid in stateSTART_DOCUMENT,START_TAG,END_TAGandTEXT. It continues parsing of the XML input until the next event, which it will return.tagβ only valid in statesSTART_TAGandEND_TAG. It returns the tag name of the current start or end tag.attributesβ only valid in stateSTART_TAG. It returns all attributes of the element in a name value list.textβ only valid in stateTEXT. It returns the character data of the event. There will be always at most oneTEXTevent betweenSTART_TAGand the nextSTART_TAGorEND_TAGevent.skipβ only valid in stateSTART_TAG. It skips to the corresponding end tag and ignores all events (but not XML parsing errors π) on the way, and returns the new stateEND_TAG.find-element?tagname |-namestagnames?β only valid in statesSTART_DOCUMENT,START_TAGandEND_TAG. It skips forward until the next element start tag with tag name tagname and returns the new stateSTART_TAG. If a list of tagnames is provided with the-namesoption, any of the tagnames match. If there isn't such an element, the parser stops at the end of the input and returnsEND_DOCUMENT.resetβ valid in all parser states. It resets the parser intoREADYstate and returns that.deleteβ valid in all parser states. It deletes the parser command. bye bestie π
π Miscellaneous methods π
lineβ valid in all parser states exceptREADYandTEXT. It returns the line number of the parsing position. Line counting starts with 1.columnβ valid in all parser states exceptREADYandTEXT. It returns the offset, from the beginning of the current line, of the parsing position. Column counting starts with 0.
π KEYWORDS π
XML, pull, parsing
and that's the whole page, bestie π«Ά this was the pullparser(3tcl) manual, straight out of the Tcl camp β go forth and pull-parse responsibly, mwah π
β¨
π¦ where this page comes from
- debian trixie: tdom 0.9.5.1-3 Β· MPL-2.0
- ubuntu questing: tdom 0.9.5.1-3
- ubuntu resolute: tdom 0.9.6-2 Β· MPL-2.0
- ubuntu stonking: tdom 0.9.6-3 Β· MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms