Klacks-Beispiel
[cxml-rng.git] / index.html
blob354730ffb71e2a593351c749ac5908998a323223
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>
6 cxml-rng: Relax NG for Closure XML
7 </title>
8 <link rel="stylesheet" type="text/css" href="index.css">
9 </head>
10 <body style="width: 60%">
11 <div id="header"><table cellspacing="0" cellpadding="0" width="100%"><tr>
12 <td width="176"><img src="doc/logo.png"></td>
13 <td valign="center">
14
15 <b> Relax NG for Closure XML</b>
16 </td>
17 </tr></table></div>
18 <div id="homepage" class="main">
19 <p>
20 An implementation
21 of <a href="http://relaxng.org/spec-20011203.html">Relax
22 NG</a> schema validation
23 written in Common Lisp.
24 </p>
25 <p>
26 cxml-rng was written
27 by <a href="mailto:david@lichteblau.com">David
28 Lichteblau</a> and is designed as an add-on library for
29 <a href="http://common-lisp.net/project/cxml">Closure XML</a>.
30 It is available under an X11-style license.
31 </p>
32 <p>
33 Please send bug reports
34 to <a href="mailto:cxml-devel@common-lisp.net">
35 cxml-devel@common-lisp.net</a>
36 (<a href="http://common-lisp.net/cgi-bin/mailman/listinfo/cxml-devel">list information</a>).
37 </p>
39 <h3>Download and Installation</h3>
41 <p>
42 Download
43 cxml-rng <a href="http://www.lichteblau.com/cxml-rng/download/">tarballs</a>
44 or get it from
45 git: <tt>http://www.lichteblau.com/git/cxml-rng.git</tt>
46 </p>
47 <p>
48 cxml-rng
49 needs <a href="http://common-lisp.net/project/cxml">Closure
50 XML</a> and <a href="http://weitz.de/cl-ppcre/">CL-PPCE</a>.
51 <a href="http://www.cliki.net/asdf">ASDF</a> is used for
52 compilation. Register the .asd file, e.g. by symlinking it,
53 then compile cxml-rng using <tt>asdf:operate</tt>.
54 </p>
55 <pre>$ ln -sf `pwd`/cxml-rng.asd /path/to/your/registry/
56 * (asdf:operate 'asdf:load-op :cxml-rng)</pre>
58 <h3>Implementation-specific notes</h3>
59 <p>
60 At this point, cxml-rng is written to work with Lisp strings
61 (as opposed to runes and rods), and is meant to be used on
62 Lisp implementations with Unicode support.
63 </p>
65 <h3>Example</h3>
66 <p>
67 Use <a href="doc/pages/cxml-rng__parse-relax-ng.html">cxml-rng:parse-relax-ng</a>
68 to parse a Relax NG schema file. The
69 resulting <a href="doc/pages/cxml-rng__parsed-grammar.html">parsed-grammar</a>
70 object is a representation of a simplified schema using Lisp
71 objects, which has gone through most stages of simplification as
72 described the Relax NG
73 specification. <a href="doc/pages/cxml-rng__serialize-grammar.html">cxml-rng:serialize-grammar</a>
74 can be used to write a Relax NG file in XML syntax for this
75 grammar.
76 </p>
77 <p>
78 In order to validate XML against a schema, create a
79 validation handler for the grammar
80 using <a href="doc/pages/cxml-rng__make-validator.html">cxml-rng:make-validator</a>.
81 The validation
82 handler processes SAX events and can be used with any
83 function generating such events, in particular
84 with <a href="http://common-lisp.net/project/cxml/sax.html#parser">cxml:parse-file</a>.
85 </p>
86 <pre class="code">(cxml:parse-file "example.xml"
87 <span style="color: black">(cxml-rng:make-validator
88 (cxml-rng:parse-relax-ng #p"example.rng"))</span>)</pre>
89 <p>
90 In order to validate while also processing events with
91 another handler, use a broadcast handler. For example, to
92 parse XML into DOM while also validating it, broadcast to
93 the validator and DOM builder (in that order):
94 </p>
95 <pre class="code" style="color: #777777">(cxml:parse-file "example.xml"
96 <span style="color: black">(cxml:make-broadcast-handler</span>
97 (cxml-rng:make-validator
98 (cxml-rng:parse-relax-ng #p"example.rng"))
99 <span style="color: black">(cxml-dom:make-dom-builder))</span>)</pre>
101 To validate with the klacks parser, use a tapping source.
102 </p>
103 <pre class="code" style="color: #777777">(klacks:with-open-source
104 (s <span style="color: black">(klacks:make-tapping-source</span>
105 (cxml:make-source #p"example.xml")
106 <span style="color: black">(cxml-rng:make-validator
107 (cxml-rng:parse-relax-ng #p"example.rng"))</span>))
108 (loop for key = (klacks:peek-next s) while key do (print key)))</pre>
110 <h3>Documentation</h3>
112 Detailed <a href="doc/index.html">API documentation</a>
113 is available.
114 </p>
115 </div>
116 </body>
117 </html>