This was derived from code on the Tclers Wiki at http://wiki.tcl.tk/14534 by Eric Kemp-Benedict. This code only vaguely resembles the original by now. Several improvements mentioned on the wiki are not in this version.
A basic example, taken from comments in the source file:
proc myparser {args} { puts "args: $args" }
Tax parse {
<meta author="Anne Onymous"/>
<meta x="c { d } e < f > g & h">
Composed in haste for purposes of demonstration.
</meta>
<para indent='3'>This is the second paragraph.</para>
eee
<para blah='a " b' beep=1>
This line is indented.
</para>
} myparser
Output:
args: docstart {} {
}
args: meta {author "Anne Onymous"} {}
args: meta/ / {
}
args: meta {x "c { d } e < f > g & h"} {
Composed in haste for purposes of demonstration.
}
args: meta/ {} {
}
args: para {indent "3"} {This is the second paragraph.}
args: para/ {} {
eee
}
args: para {blah "a \" b" beep 1} {
This line is indented.
}
args: para/ {} {
}
args: docstart/ {} {}
Tax parse xml cmd ?top?
Parse an XML text, calling the specified command for each element.
The start and end of the parse are delimited with a pseudo node called "docstart" if the top argument is not specified.