1 <documentation title="CXML W3C DOM">
4 CXML implements the DOM Level 2 Core interfaces.  For details
5 on DOM, please refer to the <a
6 href="http://www.w3.org/TR/DOM-Level-2-Core/core.html">specification</a>.
10 <h3>Parsing into DOM</h3>
12 To parse an XML document into a DOM tree, use the SAX parser with a
13 DOM builder as the SAX handler. Example:
15 <pre>(cxml:parse-file "test.xml" (cxml-dom:make-dom-builder))</pre>
17 <div class="def">Function CXML-DOM:MAKE-DOM-BUILDER ()</div>
18 Create a SAX handler which builds a DOM document.
21 This functions returns a DOM builder that will work with the default
22 configuration of the SAX parser and is guaranteed to use
23 characters/strings instead of runes/rods, if that makes a
24 difference on the Lisp in question.
27 This is the same as <tt>rune-dom:make-dom-builder</tt> on Lisps
28 with Unicode support, and the same as
29 <tt>utf8-dom:make-dom-builder</tt> otherwise.
33 <div class="def">Function RUNE-DOM:MAKE-DOM-BUILDER ()</div>
34 Create a SAX handler which builds a DOM document using runes and rods.
38 <div class="def">Function UTF8-DOM:MAKE-DOM-BUILDER ()</div>
39 (Only on Lisps without Unicode support:)
40 Create a SAX handler which builds a DOM document using
41 UTF-8-encoded strings.
44 <a name="serialization"/>
45 <h3>Serializing DOM</h3>
47 To serialize a DOM document, use a SAX serialization sink as the
48 argument to <tt>dom:map-document</tt>, which generates SAX events
52 Applications dealing with namespaces might want to inject a
53 <a href="sax.html#misc">namespace normalizer</a> into the
57 <div class="def">Function DOM:MAP-DOCUMENT (handler document &key include-xmlns-attributes include-default-values include-doctype)</div>
58 Traverse a DOM document and call SAX functions as if an XML
59 representation of the document was processed by a SAX parser.
61 <p>Keyword arguments:</p>
64 <tt>include-xmlns-attributes</tt> -- defaults to
65 <tt>sax:*include-xmlns-attributes*</tt>
68 <tt>include-doctype</tt> -- One of <tt>nil</tt> (no doctype
69 declaration), <tt>:full-internal-subset</tt> (include a doctype
70 declaration and the full internal subset), or
71 <tt>:canonical-notations</tt> (write a doctype declaration
72 with an internal subset including only notations, as required
73 for canonical serialization).
76 <tt>include-default-values</tt> -- include attribute nodes with nil
77 <tt>dom:specified</tt>.
80 <tt>recode</tt> -- (ignored on Lisps with Unicode support.) If
81 true, recode UTF-8 strings to rods. Defaults to true if used
82 with a UTF-8 DOM document. It can be set to false manually to
83 suppress recoding in this case.
88 <h3>DOM/Lisp mapping</h3>
90 Note that there is no "standard" DOM mapping for Lisp.
94 href="http://www.w3.org/TR/DOM-Level-2-Core/idl-definitions.html">specified
95 in CORBA IDL</a>, but it refrains from using object-oriented IDL
96 features, allowing for a much more natural Lisp implemenation than
97 the the ordinary IDL/Lisp mapping would. 
98 Differences between CXML's DOM and the direct IDL/Lisp mapping:
102 DOM function names are symbols in the <tt>DOM</tt> package (not
103 the <tt>OP</tt> package).
106 DOM functions have proper required arguments, not a huge
107 <tt>&rest</tt> lambda list.
110 Although most IDL interfaces are implemented as CLOS classes by
111 CXML, the Lisp types of DOM objects is not documented and cannot
112 be relied upon.  A node's type can be determined using
113 <tt>dom:node-type</tt> instead.
116 <tt>DOMString</tt> is mapped to <tt>rod</tt>, which is either
117 an <tt>(unsigned-byte 16)</tt> array type or a string type.
120 The IDL/Lisp mapping maps CORBA enums to Lisp keywords. 
121 Unfortunately, the DOM IDL does not use enums.  Instead,
122 both exception types and node types are defined integer
123 constants.  CXML chooses to ignore this definition and uses
127 DOM uses StudlyCaps.  Lisp programmers don't.  We
128 insert <tt>#\-</tt> before every upper case letter preceded by a
129 lower case letter and before every upper case letter which is
130 followed by a lower case letter, but preceded by a capital
131 letter.  This algorithms leads to the natural Lisp spelling
132 of DOM function names.
135 Implementation note: DOM's <tt>NodeList</tt> does not
136 necessarily map to a native "sequence" type.  (For example,
137 node lists are objects in Java, not arrays.) 
138 <tt>NodeList</tt> is specified to reflect changes done after a
139 node list was created, so node lists cannot be Lisp lists. 
140 (A node list could be implemented as a CLOS object pointing to
141 said list though.)  Instead, CXML currently implements node
142 lists as adjustable vectors.  Note that code which relies on
143 this implementation and uses Lisp sequence functions
144 instead of sticking to <tt>dom:item</tt> and <tt>dom:length</tt>
145 is not portable.  As a compromise, you can use our
146 extensions <tt>dom:map-node-list</tt> or
147 <tt>dom:do-node-list</tt>, which can be implemented portably.