Debian Codegraph @

examples/FleXML.xml

raw
1 <!DOCTYPE html PUBLIC "-//IETF//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <!--$Id: FleXML.xml,v 1.2 2006/07/18 18:21:13 mquinson Exp $-->
4 <html>
5 <head>
6 <title>FleXML - XML Processor Generator</title>
7 </head>
8
9 <body bgcolor='white'>
10
11 <h1> FleXML - XML Processor Generator </h1>
12
13 <blockquote><p><em>
14 See also <a href="ftp/FleXML/flexml.html">the manual page</a>
15 and a short <a href="ftp/FleXML/paper.html">white paper</a>.
16 Or peek into the <a
17 href="http://www.ens-lyon.fr/~krisrose/ftp/FleXML/">master
18 source archive</a>.
19 </em></p></blockquote>
20
21 <p>
22 FleXML reads a DTD (Document Type Definition)
23 describing the format of XML (Extensible Markup Language)
24 documents; it may be specified as a URI to the DTD on the
25 web. From this FleXML produces a validating XML
26 processor with an interface to support XML applications. Proper
27 applications can be generated optionally from special action
28 files, either for linking or textual combination with the
29 processor.
30 </p>
31
32 <p>
33 FleXML is specifically developed for XML applications
34 where a fixed data format suffices in the sense that a single
35 DTD is used without individual extensions for a large number of
36 documents. (Specifically it restricts XML rule [28] to
37 </p>
38
39 <pre> [28r] doctypedecl ::= '<code>&lt;!DOCTYPE</code>' S Name S ExternalID S? '<code>&gt;</code>'
40 </pre>
41
42 <p>
43 where the ExternalId denotes the used DTD - one might say, in
44 fact, that FleXML implements ``non-extensible'' markup. :)
45 </p>
46
47 <p>
48 With this restriction we can do much better because the possible
49 tags and attributes are static: FleXML-generated XML processors
50 read the XML document character by character and can immediately
51 dispatch the actions associated with each element (or reject the
52 document as invalid). Technically this is done by using the
53 Flex scanner generator to produce a deterministic finite
54 automaton with an element context stack for the DTD, which means
55 that there is almost no overhead for XML processing.
56 </p>
57
58 <p>
59 Furthermore we have devised a simple extension of the C
60 programming language that facilitates the writing of `element
61 actions' in C, making it easy to write really fast XML
62 applications. In particular we represent XML attribute values
63 efficiently in C when this is possible, thus avoiding the
64 otherwise ubiquitous conversions between strings and data
65 values.
66 </p>
67
68 <p>
69 Compared to SAX and its XSL-based friends, FleXML immediately
70 produces efficient code in that the interdiction of extension
71 makes it possible to encode efficiently, FleXML for example uses
72 native C `enum' types to implement enumeration attribute
73 types. However, the above limitation does prevent uses in more
74 complex settings.
75 </p>
76
77 <p>
78 As an example: the following is all that is needed to produce a
79 fast program that prints all href-attributes in
80 <code>&lt;a...&gt;</code> tags in XHTML documents (and rejects
81 invalid XHTML documents).
82 </p>
83
84 <pre><code> &lt;!DOCTYPE actions SYSTEM "flexml-act.dtd"&gt;
85 &lt;actions&gt;
86 &lt;top&gt;&lt;![CDATA[ #include &lt;stdio.h&gt; ]]&gt;&lt;/top&gt;
87 &lt;start tag='a'&gt;&lt;![CDATA[ if ({href}) printf("%s\n", {href}); ]]&gt;&lt;/start&gt;
88 &lt;/actions&gt;
89 </code></pre>
90
91 <p>
92 In general, action files are themselves XML documents conforming
93 to the DTD
94 </p>
95
96 <pre><code> &lt;!ELEMENT actions ((top|start|end)*,main?)&gt;
97 &lt;!ENTITY % C-code "(#PCDATA)"&gt;
98 &lt;!ELEMENT top %C-code;&gt;
99 &lt;!ELEMENT start %C-code;&gt; &lt;!ATTLIST start tag NMTOKEN #REQUIRED&gt;
100 &lt;!ELEMENT end %C-code;&gt; &lt;!ATTLIST end tag NMTOKEN #REQUIRED&gt;
101 &lt;!ELEMENT main %C-code;&gt;
102 </code></pre>
103
104 <p>
105 with <code>%C-code;</code> segments being in C enriched as
106 described below. The elements are used as follows:
107 </p>
108
109 <dl compact='compact'>
110 <dt>top</dt>
111 <dd><p>
112 Use for top-level C code such as global declarations, utility
113 functions, etc.
114 </p></dd>
115
116 <dt>start</dt>
117 <dd>
118 <p>
119 Attaches the code as an action to the element with the name
120 of the required ``tag'' attribute. The ``%C-code;''
121 component should be C code suitable for inclusion in a C
122 block (i.e., within {...} so it may contain local
123 variables); furthermore the following extensions are
124 available: {attribute} Can be used to access the value of
125 the attribute as set with attribute=value in the start
126 tag. In C, {attribute} will be interpreted depending on the
127 declaration of the attribute. If the attribute is declared
128 as an enumerated type like
129 </p>
130
131 <pre><code> &lt;!ATTLIST attrib (alt1 | alt2 |...) ...&gt;
132 </code></pre>
133
134 <p>
135 then the C attribute value is of an enumerated type with the
136 elements written <code>{attrib=alt1}</code>,
137 <code>{attrib=alt2}</code>, etc.; furthermore an unset
138 attribute has the ``value'' <code>{!attrib}</code>. If the
139 attribute is not an enumeration then <code>{attrib}</code>
140 is a null-terminated C string (of type <code>char*</code>)
141 and <code>{!attrib}</code> is <code>NULL</code>.
142 </p>
143 </dd>
144
145 <dt>end</dt>
146 <dd>
147 <p>
148 Similarly attaches the code as an action to the end tag with
149 the name of the required ``tag'' attribute; also here the
150 ``%C-code;'' component should be C code suitable for
151 inclusion in a C block. In case the element has ``Mixed''
152 contents, i.e, was declared to permit <code>#PCDATA</code>,
153 then the special variable <code>{#PCDATA}</code> contains
154 the text (<code>#PCDATA</code>) of the element as a
155 null-terminated C string (of type char*). In case the Mixed
156 contents element actually mixed text and child elements then
157 <code>{#PCDATA}</code> contains the plain concatenation of
158 the text fragments as one string.
159 </p>
160 </dd>
161
162 <dt>main</dt>
163 <dd>
164 <p>
165 Finally, an optional ``main'' element can contain the C main
166 function of the XML application. Normally the main function
167 should include (at least) one call of the XML processor
168 <code>yylex</code>.
169 </p>
170 </dd>
171
172 </dl>
173 <p>
174 The program is freely redistributable and modifiable (under GNU
175 `copyleft').
176 </p>
177 <hr />
178 <address>Copyright (c)
179 <a href="mailto:[email protected]">Kristoffer Rose</a>.
180 <!-- Created: Thu Dec 9 08:09:41 CET 1999 -->
181 <!-- hhmts start -->
182 Last modified: Mon Dec 13 17:17:44 CET 1999
183 <!-- hhmts end -->
184 </address>
185 </body>
186 </html>