Forester 4.0 › Enhanced XML support [00RH]
- April 5, 2024
- Jon Sterling
An XML namespace for Forester [00RI]
- April 5, 2024
- Jon Sterling
The XML format is now governed by the XML namespace with URI http://www.forester-notes.org/005P/; as is typical of XML grammars, element names are namespaced whereas attribute names lie in no namespace. Forester emits XML with element names qualified by a prefix bound to this namespace. This change breaks existing XSL stylesheets, so you must upgrade your theme.
The new version of the default theme contains rules to allow anything in either the http://www.w3.org/1999/xhtml or http://www.w3.org/1998/Math/MathML namespaces to be copied through to the output HTML (with namespace prefixes stripped). In combination with § [00RJ], this allows you to write HTML and MathML in Forester directly.
Please note that although Forester now has a namespace, it does not has a schema. Any direct integration with the XML format (e.g. by custom themes) is not supported and should be done at your own risk — several recent releases have illustrated the continued rapid evolution of the XML format with many breaking changes. I expect this evolution will continue for some time.
Emitting XML and resolving namespaces [00RJ]
- April 5, 2024
- Jon Sterling
Since version 3.0, Forester’s source language has supported a limited form of custom XML output by means of the \xml command. This support was, however, somewhat unwieldy: no built-in accounting for XML namespaces was included, so correct usage of \xml was prohibitively difficult because of the need for xmlns attributes on essentially every node.
Feature XML namespace declaration [00RK]
- April 5, 2024
- Jon Sterling
Forester treats XML namespace prefixes in a way that respects \alpha -equivalence: in other words, any prefix mentioned must be bound, and it is possible for two different textually identical namespace prefixes to denote different namespaces depending on their scope. This makes it possible to compose code that emits XML without coordinating namespace prefixes, which I have found to be a major impediment to the correct use of XML for non-trivial work.
An XML namespace prefix is bound by a declaration like the following:
\xmlns:html{http://www.w3.org/1999/xhtml}This declaration has the same scoping rules as \def.
Feature XML literals [00RM]
- April 5, 2024
- Jon Sterling
The old \xml syntax has been replaced with a new convenient notation for XML literals that supports declared XML namespace prefixes. The grammar of XML literals is summarised below:
qname ::= prefix:name | name
expr ::= ... | \<qname>[qname]{expr}...{expr}For example, if the prefix html: is bound to http://www.w3.org/1999/xhtml as in Feature [00RK], the expression \<html:mark>[class]{highlight}{some highlighted text} will emit the following XML:
<html:mark xmlns:html="http://www.w3.org/1999/xhtml" class="highlight"> some highlighted text </html:mark>
In reality, the appropriate @xmlns:html attribute will be attached only where it is needed in keeping with the hierarchical structure of the XML tree. Note that when the same textual prefix is bound to two different namespaces, one of them will be automatically \alpha -renamed so as to result in correct XML with the intended semantics.
Example A worked example [00RL]
- April 5, 2024
- Jon Sterling
The following code causes MathML to be emitted (in the correct namespace), combining Feature [00RK] and Feature [00RM]:
\xmlns:mml{http://www.w3.org/1998/Math/MathML}
\<mml:math>[display]{block}{
\<mml:mrow>{
\<mml:msup>{
\<mml:mi>{x}
\<mml:mn>{2}
}
\<mml:mo>{+}
\<mml:mi>{x}
}
}The above displays as follows: