pullparser(3tcl)

πŸ“¦
version 0.9.6 Β· 3 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ 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 tag
    • TEXT β€” 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.
  • input data β€” only valid in state READY. It prepares the parser to use data as XML input to parse, and switches the parser into state START_DOCUMENT.
  • inputchannel channel β€” only valid in state READY. It prepares the parser to read the XML input to parse out of channel, and switches the parser into state START_DOCUMENT.
  • inputfile filename β€” only valid in state READY. It opens filename and prepares the parser to read the XML input to parse out of that file. The method returns TCL_ERROR if the file could not be open in read mode. Otherwise it switches the parser into state START_DOCUMENT.
  • next β€” valid in state START_DOCUMENT, START_TAG, END_TAG and TEXT. It continues parsing of the XML input until the next event, which it will return.
  • tag β€” only valid in states START_TAG and END_TAG. It returns the tag name of the current start or end tag.
  • attributes β€” only valid in state START_TAG. It returns all attributes of the element in a name value list.
  • text β€” only valid in state TEXT. It returns the character data of the event. There will be always at most one TEXT event between START_TAG and the next START_TAG or END_TAG event.
  • skip β€” only valid in state START_TAG. It skips to the corresponding end tag and ignores all events (but not XML parsing errors πŸ‘€) on the way, and returns the new state END_TAG.
  • find-element ?tagname | -names tagnames? β€” only valid in states START_DOCUMENT, START_TAG and END_TAG. It skips forward until the next element start tag with tag name tagname and returns the new state START_TAG. If a list of tagnames is provided with the -names option, any of the tagnames match. If there isn't such an element, the parser stops at the end of the input and returns END_DOCUMENT.
  • reset β€” valid in all parser states. It resets the parser into READY state and returns that.
  • delete β€” valid in all parser states. It deletes the parser command. bye bestie πŸ’œ

🌈 Miscellaneous methods 🌈

  • line β€” valid in all parser states except READY and TEXT. It returns the line number of the parsing position. Line counting starts with 1.
  • column β€” valid in all parser states except READY and TEXT. 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