From 0d67d0719de2c475f2f48e6fc5b93758c4e7819d Mon Sep 17 00:00:00 2001
From: dlichteblau
- CXML implements the DOM Level 2 Core interfaces. For details
- on DOM, please refer to the specification.
-
- To parse an XML document into a DOM tree, use the SAX parser with a
- DOM builder as the SAX handler. Example:
-
-
-
- The DOM implementation
- Parsing into DOM
- (cxml:parse-file "test.xml" (cxml-dom:make-dom-builder))
-
-
-
- To serialize a DOM document, use a SAX serialization sink as the - argument to dom:map-document, which generates SAX events - for the DOM tree. -
-- Applications dealing with namespaces might want to inject a - namespace normalizer into the - sink chain. -
--
Keyword arguments:
-- Note that there is no "standard" DOM mapping for Lisp. -
-- DOM is specified - in CORBA IDL, but it refrains from using object-oriented IDL - features, allowing for a much more natural Lisp implemenation than - the the ordinary IDL/Lisp mapping would. - Differences between CXML's DOM and the direct IDL/Lisp mapping: -
-+ CXML implements the DOM Level 2 Core interfaces. For details + on DOM, please refer to the specification. +
+ + ++ To parse an XML document into a DOM tree, use the SAX parser with a + DOM builder as the SAX handler. Example: +
+(cxml:parse-file "test.xml" (cxml-dom:make-dom-builder))+
+
+
+ This functions returns a DOM builder that will work with the default + configuration of the SAX parser and is guaranteed to use + characters/strings instead of runes/rods, if that makes a + difference on the Lisp in question. ++
+ This is the same as rune-dom:make-dom-builder on Lisps + with Unicode support, and the same as + utf8-dom:make-dom-builder otherwise. + + ++
+
+ To serialize a DOM document, use a SAX serialization sink as the + argument to dom:map-document, which generates SAX events + for the DOM tree. +
++ Applications dealing with namespaces might want to inject a + namespace normalizer into the + sink chain. +
++
Keyword arguments:
++ Note that there is no "standard" DOM mapping for Lisp. +
++ DOM is specified + in CORBA IDL, but it refrains from using object-oriented IDL + features, allowing for a much more natural Lisp implemenation than + the the ordinary IDL/Lisp mapping would. + Differences between CXML's DOM and the direct IDL/Lisp mapping: +
+An XML parser written in Common Lisp.
@@ -87,9 +29,9 @@ CXML implements a namespace-aware, validating XML 1.0 + href="http://www.w3.org/TR/2000/REC-xml-20001006">XML 1.0 parser as well as the DOM Level 2 Core + href="http://www.w3.org/TR/DOM-Level-2-Core/">DOM Level 2 Core interfaces. Two parser interfaces are offered, one SAX-like, the other similar to StAX. @@ -170,54 +112,4 @@Omit -D to get the latest version, which may not work with cxml yet. The ant step is necessary to run the DOM @@ -144,7 +87,7 @@ $ cd 2001/DOM-Test-Suite && ant dom1-dtd dom2-dtd
fixme domtest.lisp does not understand the current - testsuite driver anymore. To fix this problem, revert the + testsuite driver anymore. To fix this problem, revert the affected files manually after check-out:
@@ -153,10 +96,9 @@ xmltest$ patch -p0 -R </path/to/cxml/test/xmlconf-base.diffThe log message for the changes reads "Removed unnecessary - xml:base attribute". If I understand correctly, only - DOM 3 parsers provide the baseURI attribute necessary for - understanding xmlconf.xml now. We don't have that + xml:base attribute". If I understand correctly, only + DOM 3 parsers provide the baseURI attribute necessary for + understanding xmlconf.xml now. We don't have that yet.
- - +The Klacks parser provides an alternative parsing interface, @@ -115,7 +50,7 @@ NIL To parse using Klacks, create an XML source first.
-
Keyword arguments have the same meaning as with the SAX parser, please refer to the documentation of parse-file for more information: + href="sax.html#parser">parse-file for more information:
Events are read from the stream using the following functions:
-
=> :start-document
or => :start-document, version, encoding, standalonep
@@ -275,11 +209,10 @@ NIL
Close all streams referred to by source.
-
- Make sure to install and load cxml first. -
- -Create a test file called example.xml:
-* (with-open-file (s "example.xml" :direction :output) - (write-string "<test a='b'><child/></test>" s))- -
Parse example.xml into a DOM tree (read - more):
-* (cxml:parse-file "example.xml" (cxml-dom:make-dom-builder)) -#<DOM-IMPL::DOCUMENT @ #x72206172> -;; save result for later: -* (defparameter *example* *) -*EXAMPLE*- -
Inspect the DOM tree (read more):
-* (dom:document-element *example*) -#<DOM-IMPL::ELEMENT test @ #x722b6ba2> -* (dom:tag-name (dom:document-element *example*)) -"test" -* (dom:child-nodes (dom:document-element *example*)) -#(#<DOM-IMPL::ELEMENT child @ #x722b6d8a>) -* (dom:get-attribute (dom:document-element *example*) "a") -"b"- -
Serialize the DOM document back into a file (read more):
-(with-open-file (out "example.out" :direction :output :element-type '(unsigned-byte 8)) - (dom:map-document (cxml:make-octet-stream-sink out) *example*))- -
As an alternative to DOM, parse into xmls-compatible list - structure (read more):
-* (cxml:parse-file "example.xml" (cxml-xmls:make-xmls-builder))
-("test" (("a" "b")) ("child" NIL))
-
- Use klacks to read events from the parser incrementally. The - following example looks only for :start-element and :end-element - events and prints them (read more):
-* (klacks:with-open-source
- (s (cxml:make-source #p"example.xml"))
- (loop
- for key = (klacks:peek s)
- while key
- do
- (case key
- (:start-element
- (format t "~A {" (klacks:current-qname s)))
- (:end-element
- (format t "}")))
- (klacks:consume s)))
-test {child {}}
-
-
diff --git a/doc/quickstart.xml b/doc/quickstart.xml
new file mode 100644
index 0000000..bdb47f5
--- /dev/null
+++ b/doc/quickstart.xml
@@ -0,0 +1,56 @@
++ Make sure to install and load cxml first. +
+ +Create a test file called example.xml:
+* (with-open-file (s "example.xml" :direction :output) + (write-string "<test a='b'><child/></test>" s))+ +
Parse example.xml into a DOM tree (read + more):
+* (cxml:parse-file "example.xml" (cxml-dom:make-dom-builder)) +#<DOM-IMPL::DOCUMENT @ #x72206172> +;; save result for later: +* (defparameter *example* *) +*EXAMPLE*+ +
Inspect the DOM tree (read more):
+* (dom:document-element *example*) +#<DOM-IMPL::ELEMENT test @ #x722b6ba2> +* (dom:tag-name (dom:document-element *example*)) +"test" +* (dom:child-nodes (dom:document-element *example*)) +#(#<DOM-IMPL::ELEMENT child @ #x722b6d8a>) +* (dom:get-attribute (dom:document-element *example*) "a") +"b"+ +
Serialize the DOM document back into a file (read more):
+(with-open-file (out "example.out" :direction :output :element-type '(unsigned-byte 8)) + (dom:map-document (cxml:make-octet-stream-sink out) *example*))+ +
As an alternative to DOM, parse into xmls-compatible list + structure (read more):
+* (cxml:parse-file "example.xml" (cxml-xmls:make-xmls-builder))
+("test" (("a" "b")) ("child" NIL))
+
+ Use klacks to read events from the parser incrementally. The + following example looks only for :start-element and :end-element + events and prints them (read more):
+* (klacks:with-open-source
+ (s (cxml:make-source #p"example.xml"))
+ (loop
+ for key = (klacks:peek s)
+ while key
+ do
+ (case key
+ (:start-element
+ (format t "~A {" (klacks:current-qname s)))
+ (:end-element
+ (format t "}")))
+ (klacks:consume s)))
+test {child {}}
+- CXML is implemented as a SAX parser. (Refer to make-dom-builder for information about - DOM.) + This chapter describes CXML's SAX-like parser interface.
-
+ However, SAX events are easier to generate than to process. That + is why CXML offers Klacks, a "pull-based" API in addition to SAX. + Klacks events are generally easier to process than to generate. + Please refer to the Klacks documentation + for details. +
+ ++
-
Simulate parsing a document with a document element qname @@ -185,9 +163,9 @@
- Serialization is performed using sink objects. A sink - is an output stream for runes. There are different kinds of sinks - for output to lisp streams, vectors, etc. + Serialization is performed using sink objects. There are + different kinds of sinks for output to lisp streams and vectors in + various flavours.
Technically, sinks are SAX handlers that write XML output for SAX @@ -205,17 +183,17 @@
Return a SAX serialization handle. @@ -298,22 +276,22 @@ An internal subset will be included in the result regardless of the canonical setting. It is the responsibility of the caller to not report an internal subset for - canonical <= 1, or only notations as required for - canonical = 2. For example, the + canonical <= 1, or only notations as required for + canonical = 2. For example, the include-doctype argument to dom:map-document should be set to nil for the former behaviour and :canonical-notations for the latter.
With an indentation level, pretty-print the XML by - inserting additional whitespace. Note that indentation + inserting additional whitespace. Note that indentation changes the document model and should only be used if whitespace does not matter to the application.
-
-
-
-
@@ -579,9 +557,9 @@ NIL
A SAX handler is an arbitrary objects that implements some of the - generic functions in the SAX package. Note that no default + generic functions in the SAX package. Note that no default handler class is necessary, because all generic functions have default - methods which do nothing. SAX functions are: + methods which do nothing. SAX functions are:
fixme: For more information on these functions refer to the docstrings.
- - +Like other XML parsers written in Lisp, CXML can work with @@ -74,8 +16,8 @@ DOM functions cannot be implemented on them.
-
(cxml:parse-file "test.xml" (cxml-xmls:make-xmls-builder))
-
(defun write-xml (stream node &key indent) +(defun write-xml (stream node &key indent) (let ((sink (cxml:make-character-stream-sink stream :canonical nil :indentation indent))) (cxml-xmls:map-node sink node)))-
Function CXML-XMLS:MAKE-NODE (&key name ns attrs +Function CXML-XMLS:MAKE-NODE (&key name ns attrs children) => xmls nodeBuild a list node of the form - (name ((name value)*) child*). + (name ((name value)*) child*).The node list's car can also be a cons of local name @@ -129,5 +71,4 @@
- - +