tnc(n)

πŸ“¦
version 0.9.6 Β· 2 versions
  • 0.9.6 Β· fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0 (latest)
  • 0.8.2 Β· fedora 43
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0

πŸ’– NAME πŸ’–

tnc β€” okay bestie, so tnc is an expat parser object extension, and what it does is validate the XML stream against the document DTD while parsing. Like, it's checking your vibes as it reads. πŸ¦‹


✨ SYNOPSIS ✨

package require tdom
package require tnc

set parser [expat]

tnc $parser enable

πŸŽ€ DESCRIPTION πŸŽ€

So here's the tea: tnc adds the C handler set "tnc" to a tcl expat parser obj. That handler set is literally just a simple DTD validator. πŸ’…

If the validator detects a validation error, it sets the interp result, signals error and stops parsing. And no, there isn't any validation error recovering β€” not a thing, not happening, no takebacks. As a consequence (and this is the important part), only valid documents are completely parsed. So if your doc is a mess, you're getting a partial read and an error, periodt. 😭

This handler set has only three methods, which is honestly so refreshing:

  • tnc parserObj enable β€” Adds the tnc C handler set to a Tcl expat parser object. 🫢
  • tnc parserObj remove β€” Removes the tnc validatore from the parser parserObj and frees all information, stored by it. Cleanup queen behavior. 🧹
  • tnc parserObj getValidateCmd ?validateCmdName? β€” Returns a new created validation command, if one is available from the parser command, otherwise it signals error. The name of the validation command is the validateCmdName, if this optional argument was given, or a random chosen name (mystery name, slay).

A validation command is available in a parser command if the parser with tnc enabled was previously used to parse an XML document with a valid doctype declaration, a valid external subset (if one was given by the doctype declaration), and a valid internal subset. Ngl, the further document doesn't need to be valid to make the validation command available. πŸ‘‘

And heads up: the validation command can only get received one time from the parser command. One shot. That's it. Don't come back for seconds.

The created validation command has this syntax:

validationCmd method ?args?

The valid methods are:

  • validateDocument domDocument ?varName? β€” Checks if the given domDocument is valid against the DTD information represented by the validation command. Returns 1 if the document ist valid, 0 otherwise. If the varName argument is given, then the variable it names is set to the detected reason for the validation error or to the empty string in case of a valid document. πŸ”₯
  • validateTree elementNode ?varName? β€” Checks if the given subtree with domNode as root element is a possible valid subtree of a document conforming to the DTD information represented by the validation command. IDREF could not checked while validating only a subtree, but it is checked that every known ID attribute in the subtree is unique. Returns 1 if the subtree is OK, 0 otherwise. If the varName argument is given, then the variable it names is set to the detected reason for the validation error or to the empty string in case of a valid subtree. 🌸
  • validateAttributes elementNode ?varName? β€” Checks if there is an element declaration for the name of the elementNode in the DTD represented by the validation command and, if yes, if the attributes of the elementNode are conform to the ATTLIST declarations for that element in the DTD. Returns 1 if the attributes and there value types are OK, 0 otherwise. If the varName argument is given, then the variable it names is set to the detected reason for the validation error or to the empty string in case the element has all its required attributes, only declared attributes, and the values of the attributes matches there type. πŸ’œ
  • delete β€” Deletes the validation command and frees the memory used by it. Returns the empty string. Bye bestie, take your memory with you. πŸŽ€

πŸ’€ BUGS πŸ’€

Okay so, keeping it a hundred, here's where the vibes get a little rough:

  • The validation error reports could be much more informative and user-friendly. Like, they're giving nothing. πŸ™ˆ
  • The validator doesn't detect ambiguous content models (see XML recomendation Section 3.2.1 and Appendix E). Most Java validators also doesn't, but handle such content models right anyhow. Tnc does not; if your DTD has such ambiguous content models, tnc can not used to validate documents against such (not completely XML spec compliant) DTDs. Not me being the only one in the group chat who can't do this. 😭
  • It isn't possible to validate XML documents with standalone="yes" in the XML Declaration. Nope. Not happening. 🚫
  • Violations of the validity constraints Proper Group/PE Nesting and Proper Conditional Section/PE Nesting are not detected. They could only happen inside a invalid DTD, not in the content of a document. So like, lowkey niche, but fr fr it's a gap.

πŸ”‘ KEYWORDS πŸ”‘

Validation, DTD


That's the whole page, bestie β€” brought to you by the Tcl girlies, tnc(n), and the entire manual section. Go validate something iconic. πŸ’…βœ¨

πŸ“¦ where this page comes from