From 95b3f65a4b49d6df0bed22441f1829db40d95680 Mon Sep 17 00:00:00 2001
From: dlichteblau
Date: Sat, 7 Jul 2007 20:47:38 +0000
Subject: [PATCH] new function cxml:parse
---
doc/GNUmakefile | 1 +
doc/index.xml | 5 ++--
doc/sax.xml | 58 +++++++++++++++++++++++++++++++++++++++++-----
xml/package.lisp | 1 +
xml/xml-parse.lisp | 26 +++++++++++++++++++++
5 files changed, 83 insertions(+), 8 deletions(-)
diff --git a/doc/GNUmakefile b/doc/GNUmakefile
index bbabd6d..dfe2ad2 100644
--- a/doc/GNUmakefile
+++ b/doc/GNUmakefile
@@ -2,4 +2,5 @@ all: dom.html index.html installation.html klacks.html quickstart.html sax.html
%.html: %.xml html.xsl
xsltproc html.xsl $< >$@.tmp
+ chmod -w *.html
mv $@.tmp $@
diff --git a/doc/index.xml b/doc/index.xml
index 86df9a0..c91e5b4 100644
--- a/doc/index.xml
+++ b/doc/index.xml
@@ -63,6 +63,7 @@
Fixed build on non-Unicode lisps. Fixed parsing on
non-Unicode lisps. Fixed Unicode detection on OpenMCL.
+ New function cxml:parse.
Serialization no longer defaults to canonical form.
Fixed octet array argument to make-source.
@@ -83,11 +84,11 @@
rel-2007-05-26
- - cxml.asd has been split up into cxml.asd for the
+
- cxml.asd has been split up into cxml.asd for the
XML parser and runes.asd for the runes package, in
preparation of a complete split of the two systems. Future CXML
releases will use separate tarballs for runes
- and cxml.
+ and cxml.
xml:base support (SAX and Klacks only, not yet used in DOM).
See documentation here and here.
diff --git a/doc/sax.xml b/doc/sax.xml
index b32cd7e..a0c8103 100644
--- a/doc/sax.xml
+++ b/doc/sax.xml
@@ -43,17 +43,63 @@
Parsing and Validating
+
-
Function CXML:PARSE-FILE (pathname handler &key ...)
-
Function CXML:PARSE-STREAM (stream handler &key ...)
-
Function CXML:PARSE-OCTETS (octets handler &key ...)
-
Function CXML:PARSE-ROD (rod handler &key ...)
- Parse an XML document.
+ Old-style convenience functions:
+
+
Function CXML:PARSE-FILE (pathname handler &key ...)
+
Same as cxml:parse with a pathname argument.
+ (But note that cxml:parse-file interprets string
+ arguments as namestrings, while cxml:parse expects
+ literal XML documents.)
+
+
Function CXML:PARSE-STREAM (stream handler &key ...)
+
Same as cxml:parse with a stream argument.
+
Function CXML:PARSE-OCTETS (octets handler &key ...)
+
Same as cxml:parse with an octet vector argument.
+
Function CXML:PARSE-ROD (rod handler &key ...)
+
Same as cxml:parse with a string argument.
+
+
+
+ New all-in-one parser interface:
+
+ Function CXML:PARSE (input handler &key ...)
+
+ Parse an XML document, where input is a string, pathname, octet
+ vector, or stream.
Return values from this function depend on the SAX handler used.
Arguments:
- - pathname -- a Common Lisp pathname
+ -
+ input -- one of:
+
+ -
+ pathname -- a Common Lisp pathname.
+ Open the file specified by the pathname and create a source for
+ the resulting stream. See below for information on how to
+ close the stream.
+
+ - stream -- a Common Lisp stream with element-type
+ (unsigned-byte 8). See below for information on how to
+ close the stream.
+
+ -
+ octets -- an (unsigned-byte 8) array.
+ The array is parsed directly, and interpreted according to the
+ encoding it specifies.
+
+ -
+ string/rod -- a rod (or string on
+ unicode-capable implementations).
+ Parses an XML document from the input string that has already
+ undergone external-format decoding.
+
+
+
- stream -- a Common Lisp stream with element-type
(unsigned-byte 8)
- octets -- an (unsigned-byte 8) array
diff --git a/xml/package.lisp b/xml/package.lisp
index 580af19..bbd9d45 100644
--- a/xml/package.lisp
+++ b/xml/package.lisp
@@ -32,6 +32,7 @@
#:attribute-qname
#:attribute-value
+ #:parse
#:parse-file
#:parse-stream
#:parse-rod
diff --git a/xml/xml-parse.lisp b/xml/xml-parse.lisp
index 25939d8..94943b0 100644
--- a/xml/xml-parse.lisp
+++ b/xml/xml-parse.lisp
@@ -3094,6 +3094,32 @@
(setf (slot-value pathname 'lisp::host) "localhost"))
pathname))
+(defun parse
+ (input handler &rest args
+ &key validate dtd root entity-resolver disallow-internal-subset
+ recode pathname)
+ (declare (ignore validate dtd root entity-resolver disallow-internal-subset
+ recode))
+ (let ((args
+ (loop
+ for (name value) on args by #'cddr
+ unless (eq name :pathname)
+ append (list name value))))
+ (etypecase input
+ (xstream (apply #'make-xstream input handler args))
+ (pathname (apply #'parse-file input handler args))
+ (rod (apply #'parse-rod input handler args))
+ (array (apply #'parse-octets input handler args))
+ (stream
+ (let ((xstream (make-xstream input :speed 8192)))
+ (setf (xstream-name xstream)
+ (make-stream-name
+ :entity-name "main document"
+ :entity-kind :main
+ :uri (pathname-to-uri
+ (merge-pathnames (or pathname (pathname input))))))
+ (apply #'parse-xstream xstream handler args))))))
+
(defun parse-xstream (xstream handler &rest args)
(let ((*ctx* nil))
(handler-case