pullparser(n)
π pullparser(n) π
okay bestie, gather round, because we're about to make a pull parser and it's gonna be so much fun, no cap β¨
π NAME π
tdom::pullparser β creates an XML pull parser command. that's the whole vibe. one command, endless possibilities, main character energy fr fr π
πΈ SYNOPSIS πΈ
package require tdom
tdom::pullparser cmdName ? -ignorewhitecdata ?
π¦ DESCRIPTION π¦
so this command makes XML pull parser commands with a simple API, in the style of a basic StAX parser. lowkey elegant, highkey useful. π«Ά
okay but here's the thing β after you create it, you have to set an input source before it'll do literally anything useful. no input, no vibes. for that, go look at the input, inputchannel and inputfile methods. they're your besties here π
the parser always has a state. that's just how it lives. you start parsing the XML data until some next state, do whatever needs doing, 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 in the error message. so pay attention π
now, the lore:
- these pull parsers don't follow external entities and they're XML 1.0 only
- they know nothing about XML Namespaces. zero. nada. π
- you get the tags and attribute names as in the source
- you aren't notified about comments, processing instructions and external entities β they're silently ignored for you. like they're not even there
- CDATA Sections are handled as if their content had been provided without using a CDATA Section
but on the brighter side βοΈ β character entity and attribute default declarations in the internal subset are respected (because it uses expat as the underlying parser π§). it's probably somewhat faster than a comparable implementation with the SAX interface. it's a nice programming model. it's a slim interface. slay.
if the option-ignorewhitecdatais given, the created XML pull parser command will ignore any white space only (' ',\t,\nand\r) text content betweenSTART_TAGandSTART_TAG/END_TAG. the parser won't stop at such input, and will createTEXTstate events only for not white space only text. periodt.
not all methods are valid in every state!! if you call a method in a state it isn't valid for, the parser raises TCL_ERROR. respect the boundaries bestie π€
the valid methods of the created commands are:
stateβ this method is valid in all parser states. 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 tag.TEXTβ parser has stopped parsing to report text between tags.END_DOKUMENTβ parser has finished parsing without error. (yes, that's spelledEND_DOKUMENT, i don't make the rules π)PARSE_ERRORβ parser stopped parsing at XML error in input.
input dataβ only valid in stateREADY. it prepares the parser to use data as the XML input to parse, and switches the parser into stateSTART_DOCUMENT. β¨inputchannel channelβ 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.inputfile filenameβ only valid in stateREADY. it opens filename and prepares the parser to read the XML input to parse out of that file. it returnsTCL_ERRORif the file could not be opened in read mode. otherwise it switches the parser into stateSTART_DOCUMENT.nextβ valid in stateSTART_DOCUMENT,START_TAG,END_TAGandTEXT. it continues parsing the XML input until the next event, which it will return. go off π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 always be at most oneTEXTevent betweenSTART_TAGand the nextSTART_TAGorEND_TAGevent.skipβ only valid in stateSTART_TAG. it skips to the corresponding end tag, ignores all events on the way (but not XML parsing errors, those still come for you π), and returns the new stateEND_TAG.find-element ? tagname | -names tagnames ?β 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. it's giving search bar energy πresetβ valid in all parser states. it resets the parser intoREADYstate and returns that. fresh start, new me π§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 with1.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 with0.
β KEYWORDS β
XML, pull, parsing
okay that's the whole page π«Ά this came to you from the Tcl corner of the universe, manual name pullparser(n) β and that's on periodt π
β¨π
π¦ where this page comes from
- fedora 43: tdom 0.9.6-3.fc43 Β· MPL-2.0 AND MIT
- fedora 44: tdom 0.9.6-3.fc44 Β· MPL-2.0 AND MIT
- nixos 26.05: tdom 0.9.6
- nixpkgs unstable: tdom 0.9.6
- opensuse-leap 16.0: tdom 0.9.4-bp160.1.2 Β· MPL-2.0
- opensuse-leap 16.0: tdom 0.9.4-bp160.1.2 Β· MPL-2.0
- opensuse-leap 16.0: tdom 0.9.4-bp160.1.2 Β· MPL-2.0
- opensuse-leap 16.0: tdom 0.9.4-bp160.1.2 Β· MPL-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms