Copyright © 2011 , Kurt Nørmark |
This version of the XML DTD parser also parses the content models of the XML elements. This is the basis for the fully automatic synthesis of finite state automata for validation of XML-in-LAML documents at document generation time.
Another tool - the XML-in-LAML mirror generation tool - is able to produce a Scheme mirror of the XML language. The mirror generation tool takes as input the data structures, which are produced by the DTD parser.
There is some internal elucidative documentation of the DTD parser at the LAML development site.
Please consult "XML mirrors in Scheme: XML in LAML" (section 2) for a tutorial introduction to the use of the parser.
The DTD parser is not perfect, but we steadily improve it when it is needed. See the README file in the directory of the source files for details and progress.
An earlier (and now obsolete) version of this tool was used to parse the HTML4.01 DTD (which is a non-XML DTD).
attribute-list | attribute-list | A list of attributes defined by the parser |
dtd-parse-verbose | dtd-parse-verbose | A boolean variable which controls whether the parser should report on the progress while parsing. |
element-list | element-list | A list of elements defined by the parser |
entity-list | entity-list | A list of entities defined by the parser |
forced-inclusion-of-marked-sections | forced-inclusion-of-marked-sections | A boolean variable which controls whether to parse ignored marked sections anyway. |
notation-list | notation-list | A list of notations defined by the parser |
parse-dtd | (parse-dtd file . non-expanding-entities) | Parses a dtd file to Lisp expressions and writes the parsed result to another file. |
parse-rhs-string | (parse-rhs-string rhs-str) | Top level rhs parser function. |
1 Introduction and usage. | |||
The easiest way to parse an XML DTD is to use the procedure xml-dtd-parse located in laml.scm in the root of LAML distribution. This procedure can be called from a LAML prompt. Here is another slightly more low-level way to use the parser.
We now describe the format of an entity, an attribute, and an element in the parsed result. Each unit in the result of the parsing is either an element, an attribute, or an entity. An element describes, in popular terms, "a single tag" in the markup language. An attribute describes the attribute of an element. Thus, in general, there is a one-to-one correspondance between the element list and the attribute-list. The list of entities are macro expansions, which have been applied to achieve a clean and parsable dtd file. The entity list is of minor importance once the file has been parsed. The first element in each of the top level form of the parsed result distinguishes this element from each others (tagging).
Mixed contents list have the form (mixed-content pcdata) (mixed-content (choice zero-or-more pcdata NAME-STRING NAME-STRING ... NAME-STRING))Element contents lists have the form (element-contents CONT)where CONT ::= ( KIND MULTIPLICITY DATA+ ) and where NAME-STRING is a placeholder for a string constant. Here is information about the parsed formats of attributes and entities:
| |||
2 The main parsing function. | |||
There is only one function, parse-dtd, to learn. This function represents and "is" the tool. | |||
parse-dtd | |||
Form | (parse-dtd file . non-expanding-entities) | ||
Description | Parses a dtd file to Lisp expressions and writes the parsed result to another file. The parameter file is without extension. The second parameter is a list of entity names (strings without leading percent chars); no entity in the list will be expanded. This function also defines the lists element-list, attribute-list, and entity-list. The parsed result is the appending of element-list, attribute-list, and entity-list. It is assumed that the DTD file resides on file.dtd. This function writes the result to the file.lsp. | ||
3 Variables which control the parser. | |||
dtd-parse-verbose | |||
Form | dtd-parse-verbose | ||
Description | A boolean variable which controls whether the parser should report on the progress while parsing. Default #t. | ||
forced-inclusion-of-marked-sections | |||
Form | forced-inclusion-of-marked-sections | ||
Description | A boolean variable which controls whether to parse ignored marked sections anyway. Default #t. | ||
4 Variables which is assigned to parser output. | |||
entity-list | |||
Form | entity-list | ||
Description | A list of entities defined by the parser | ||
element-list | |||
Form | element-list | ||
Description | A list of elements defined by the parser | ||
attribute-list | |||
Form | attribute-list | ||
Description | A list of attributes defined by the parser | ||
notation-list | |||
Form | notation-list | ||
Description | A list of notations defined by the parser | ||
parse-rhs-string | |||
Form | (parse-rhs-string rhs-str) | ||
Description | Top level rhs parser function. | ||