From scaekenberghe at common-lisp.net Sun Nov 6 11:55:12 2005 From: scaekenberghe at common-lisp.net (Sven Van Caekenberghe) Date: Sun, 6 Nov 2005 12:55:12 +0100 (CET) Subject: [s-xml-cvs] CVS update: s-xml/debian/README.Debian s-xml/debian/changelog s-xml/debian/control s-xml/debian/copyright s-xml/debian/postinst s-xml/debian/prerm s-xml/debian/rules Message-ID: <20051106115512.5BE9688555@common-lisp.net> Update of /project/s-xml/cvsroot/s-xml/debian In directory common-lisp.net:/tmp/cvs-serv14665 Removed Files: README.Debian changelog control copyright postinst prerm rules Log Message: removing since the debian maintainer tells me they are no longer needed Date: Sun Nov 6 12:55:09 2005 Author: scaekenberghe From scaekenberghe at common-lisp.net Sun Nov 6 12:44:48 2005 From: scaekenberghe at common-lisp.net (Sven Van Caekenberghe) Date: Sun, 6 Nov 2005 13:44:48 +0100 (CET) Subject: [s-xml-cvs] CVS update: s-xml/ChangeLog Message-ID: <20051106124448.F03D888555@common-lisp.net> Update of /project/s-xml/cvsroot/s-xml In directory common-lisp.net:/tmp/cvs-serv17887 Modified Files: ChangeLog Log Message: added CDATA support (patch contributed by Peter Van Eynde pvaneynd at mailworks.org) Date: Sun Nov 6 13:44:47 2005 Author: scaekenberghe Index: s-xml/ChangeLog diff -u s-xml/ChangeLog:1.3 s-xml/ChangeLog:1.4 --- s-xml/ChangeLog:1.3 Tue Aug 30 15:05:09 2005 +++ s-xml/ChangeLog Sun Nov 6 13:44:47 2005 @@ -1,3 +1,8 @@ +2005-11-06 Sven Van Caekenberghe + + * removed Debian packaging directory (on Luca's request) + * added CDATA support (patch contributed by Peter Van Eynde pvaneynd at mailworks.org) + 2005-08-30 Sven Van Caekenberghe * added Debian packaging directory (contributed by Luca Capello luca at pca.it) @@ -48,4 +53,4 @@ * release 0 * as part of an XML-RPC implementation -$Id: ChangeLog,v 1.3 2005/08/30 13:05:09 scaekenberghe Exp $ +$Id: ChangeLog,v 1.4 2005/11/06 12:44:47 scaekenberghe Exp $ From scaekenberghe at common-lisp.net Sun Nov 6 12:44:50 2005 From: scaekenberghe at common-lisp.net (Sven Van Caekenberghe) Date: Sun, 6 Nov 2005 13:44:50 +0100 (CET) Subject: [s-xml-cvs] CVS update: s-xml/test/test-lxml-dom.lisp s-xml/test/test-xml.lisp Message-ID: <20051106124450.EA0FD88555@common-lisp.net> Update of /project/s-xml/cvsroot/s-xml/test In directory common-lisp.net:/tmp/cvs-serv17887/test Modified Files: test-lxml-dom.lisp test-xml.lisp Log Message: added CDATA support (patch contributed by Peter Van Eynde pvaneynd at mailworks.org) Date: Sun Nov 6 13:44:49 2005 Author: scaekenberghe Index: s-xml/test/test-lxml-dom.lisp diff -u s-xml/test/test-lxml-dom.lisp:1.1.1.1 s-xml/test/test-lxml-dom.lisp:1.2 --- s-xml/test/test-lxml-dom.lisp:1.1.1.1 Mon Jun 7 20:49:59 2004 +++ s-xml/test/test-lxml-dom.lisp Sun Nov 6 13:44:48 2005 @@ -1,6 +1,6 @@ ;;;; -*- mode: lisp -*- ;;;; -;;;; $Id: test-lxml-dom.lisp,v 1.1.1.1 2004/06/07 18:49:59 scaekenberghe Exp $ +;;;; $Id: test-lxml-dom.lisp,v 1.2 2005/11/06 12:44:48 scaekenberghe Exp $ ;;;; ;;;; Unit and functional tests for lxml-dom.lisp ;;;; @@ -66,5 +66,15 @@ (assert (string-equal (print-xml-string '(:|foo| :|bar|) :input-type :lxml) "")) + +(assert (string-equal (second + (with-input-from-string (stream "Hello, world!]]>") + (parse-xml stream :output-type :lxml))) + "Hello, world!")) + +(assert (string-equal (second + (with-input-from-string (stream "Hello, < world!]]>") + (parse-xml stream :output-type :lxml))) + "Hello, < world!")) ;;;; eof Index: s-xml/test/test-xml.lisp diff -u s-xml/test/test-xml.lisp:1.2 s-xml/test/test-xml.lisp:1.3 --- s-xml/test/test-xml.lisp:1.2 Fri Oct 22 12:37:00 2004 +++ s-xml/test/test-xml.lisp Sun Nov 6 13:44:48 2005 @@ -1,6 +1,6 @@ ;;;; -*- mode: lisp -*- ;;;; -;;;; $Id: test-xml.lisp,v 1.2 2004/10/22 10:37:00 scaekenberghe Exp $ +;;;; $Id: test-xml.lisp,v 1.3 2005/11/06 12:44:48 scaekenberghe Exp $ ;;;; ;;;; Unit and functional tests for xml.lisp ;;;; @@ -36,15 +36,6 @@ (char= (with-input-from-string (stream "ABC") (skip-whitespace stream)) #\A)) - -;; CDATA is currently skipped -(with-input-from-string (stream "Hello, world!]]>") - (start-parse-xml stream)) - -;; unbalanced CDATA fails however (thanks to Frank Sonnemans) -#+NIL -(with-input-from-string (stream "Hello, < world!]]>") - (start-parse-xml stream)) (assert (string-equal (with-output-to-string (stream) (print-string-xml "" stream)) From scaekenberghe at common-lisp.net Sun Nov 6 12:44:49 2005 From: scaekenberghe at common-lisp.net (Sven Van Caekenberghe) Date: Sun, 6 Nov 2005 13:44:49 +0100 (CET) Subject: [s-xml-cvs] CVS update: s-xml/src/xml.lisp Message-ID: <20051106124449.254AB8855E@common-lisp.net> Update of /project/s-xml/cvsroot/s-xml/src In directory common-lisp.net:/tmp/cvs-serv17887/src Modified Files: xml.lisp Log Message: added CDATA support (patch contributed by Peter Van Eynde pvaneynd at mailworks.org) Date: Sun Nov 6 13:44:48 2005 Author: scaekenberghe Index: s-xml/src/xml.lisp diff -u s-xml/src/xml.lisp:1.12 s-xml/src/xml.lisp:1.13 --- s-xml/src/xml.lisp:1.12 Thu Sep 8 17:39:29 2005 +++ s-xml/src/xml.lisp Sun Nov 6 13:44:48 2005 @@ -1,6 +1,6 @@ ;;;; -*- mode: lisp -*- ;;;; -;;;; $Id: xml.lisp,v 1.12 2005/09/08 15:39:29 scaekenberghe Exp $ +;;;; $Id: xml.lisp,v 1.13 2005/11/06 12:44:48 scaekenberghe Exp $ ;;;; ;;;; This is a Common Lisp implementation of a basic but usable XML parser. ;;;; The parser is non-validating and not complete (no CDATA). @@ -446,7 +446,32 @@ (if (char/= (read-char stream nil nil) #\>) (error (parser-error "expected > ending comment" nil stream)))) -(defun skip-special-tag (stream) +(defun read-cdata (stream state &optional (string (make-extendable-string))) + "Reads in the CDATA and calls the callback for CDATA if it exists" + ;; we already read the + (let ((char #\space) + (last-3-characters (list #\[ #\A #\T)) + (pattern (list #\> #\] #\]))) + (loop + (setf char (read-char stream nil nil)) + (when (null char) (error (parser-error "encountered unexpected eof in text"))) + (push char last-3-characters) + (setf (cdddr last-3-characters) nil) + (cond + ((equal last-3-characters + pattern) + (setf (fill-pointer string) + (- (fill-pointer string) 2)) + (setf (get-seed state) + (funcall (get-text-hook state) + (copy-seq string) + (get-seed state))) + (return-from read-cdata)) + (t + (vector-push-extend char string)))))) + +(defun skip-special-tag (stream state) "Skip an XML special tag (comments and processing instructions) in stream, positioned after the opening '<', unexpected eof is an error" ;; opening < has been read, consume ? or ! @@ -458,6 +483,15 @@ (when (char= char #\-) (skip-comment stream) (return-from skip-special-tag))) + ;; maybe we are dealing with CDATA? + (when (and (char= char #\[) + (loop :for pattern :across "CDATA[" + :for char = (read-char stream nil nil) + :when (null char) :do + (error (parser-error "encountered unexpected eof in cdata")) + :always (char= char pattern))) + (read-cdata stream state (get-buffer state)) + (return-from skip-special-tag)) ;; loop over chars, dealing with strings (skipping their content) ;; and counting opening and closing < and > chars (let ((taglevel 1) @@ -510,7 +544,7 @@ (declare (special *namespaces*)) ;; opening < has been read (when (char= (peek-char nil stream nil nil) #\!) - (skip-special-tag stream) + (skip-special-tag stream state) (return-from parse-xml-element)) (let (char buffer open-tag parent-seed has-children) (setf parent-seed (get-seed state)) @@ -589,7 +623,7 @@ (setf char (peek-char nil stream nil nil)) (if (or (char= char #\!) (char= char #\?)) ;; deal with special tags - (skip-special-tag stream) + (skip-special-tag stream state) (progn ;; read the main element (parse-xml-element stream state) From scaekenberghe at common-lisp.net Sun Nov 20 14:24:35 2005 From: scaekenberghe at common-lisp.net (Sven Van Caekenberghe) Date: Sun, 20 Nov 2005 15:24:35 +0100 (CET) Subject: [s-xml-cvs] CVS update: s-xml/ChangeLog Message-ID: <20051120142435.5839588554@common-lisp.net> Update of /project/s-xml/cvsroot/s-xml In directory common-lisp.net:/tmp/cvs-serv14436 Modified Files: ChangeLog Log Message: added xml prefix namespace as per REC-xml-names-19990114 (by Rudi Schlatte) Date: Sun Nov 20 15:24:34 2005 Author: scaekenberghe Index: s-xml/ChangeLog diff -u s-xml/ChangeLog:1.4 s-xml/ChangeLog:1.5 --- s-xml/ChangeLog:1.4 Sun Nov 6 13:44:47 2005 +++ s-xml/ChangeLog Sun Nov 20 15:24:33 2005 @@ -1,3 +1,7 @@ +2005-11-20 Sven Van Caekenberghe + + * added xml prefix namespace as per REC-xml-names-19990114 (by Rudi Schlatte) + 2005-11-06 Sven Van Caekenberghe * removed Debian packaging directory (on Luca's request) @@ -53,4 +57,4 @@ * release 0 * as part of an XML-RPC implementation -$Id: ChangeLog,v 1.4 2005/11/06 12:44:47 scaekenberghe Exp $ +$Id: ChangeLog,v 1.5 2005/11/20 14:24:33 scaekenberghe Exp $ From scaekenberghe at common-lisp.net Sun Nov 20 14:24:36 2005 From: scaekenberghe at common-lisp.net (Sven Van Caekenberghe) Date: Sun, 20 Nov 2005 15:24:36 +0100 (CET) Subject: [s-xml-cvs] CVS update: s-xml/src/package.lisp s-xml/src/xml.lisp Message-ID: <20051120142436.1910288554@common-lisp.net> Update of /project/s-xml/cvsroot/s-xml/src In directory common-lisp.net:/tmp/cvs-serv14436/src Modified Files: package.lisp xml.lisp Log Message: added xml prefix namespace as per REC-xml-names-19990114 (by Rudi Schlatte) Date: Sun Nov 20 15:24:35 2005 Author: scaekenberghe Index: s-xml/src/package.lisp diff -u s-xml/src/package.lisp:1.5 s-xml/src/package.lisp:1.6 --- s-xml/src/package.lisp:1.5 Wed Sep 21 19:06:24 2005 +++ s-xml/src/package.lisp Sun Nov 20 15:24:34 2005 @@ -1,9 +1,9 @@ ;;;; -*- mode: lisp -*- ;;;; -;;;; $Id: package.lisp,v 1.5 2005/09/21 17:06:24 scaekenberghe Exp $ +;;;; $Id: package.lisp,v 1.6 2005/11/20 14:24:34 scaekenberghe Exp $ ;;;; ;;;; This is a Common Lisp implementation of a very basic XML parser. -;;;; The parser is non-validating and not at all complete (no CDATA). +;;;; The parser is non-validating. ;;;; The API into the parser is pure functional parser hook model that comes from SSAX, ;;;; see also http://pobox.com/~oleg/ftp/Scheme/xml.html or http://ssax.sourceforge.net ;;;; Different DOM models are provided, an XSML, an LXML and a xml-element struct based one. Index: s-xml/src/xml.lisp diff -u s-xml/src/xml.lisp:1.13 s-xml/src/xml.lisp:1.14 --- s-xml/src/xml.lisp:1.13 Sun Nov 6 13:44:48 2005 +++ s-xml/src/xml.lisp Sun Nov 20 15:24:34 2005 @@ -1,6 +1,6 @@ ;;;; -*- mode: lisp -*- ;;;; -;;;; $Id: xml.lisp,v 1.13 2005/11/06 12:44:48 scaekenberghe Exp $ +;;;; $Id: xml.lisp,v 1.14 2005/11/20 14:24:34 scaekenberghe Exp $ ;;;; ;;;; This is a Common Lisp implementation of a basic but usable XML parser. ;;;; The parser is non-validating and not complete (no CDATA). @@ -154,15 +154,29 @@ :initform nil)) (:documentation "Describes an XML namespace and how it is handled")) +(defmethod print-object ((object xml-namespace) stream) + (print-unreadable-object (object stream :type t :identity t) + (format stream "~A - ~A" (get-prefix object) (get-uri object)))) + (defvar *local-namespace* (make-instance 'xml-namespace :uri "local" :prefix "" :package (find-package :keyword)) "The local (global default) XML namespace") -(defvar *known-namespaces* (list *local-namespace*) +(defvar *xml-namespace* (make-instance 'xml-namespace + :uri "http://www.w3.org/XML/1998/namespace" + :prefix "xml" + :package (or (find-package :xml) + (make-package :xml :nicknames '("XML")))) + "REC-xml-names-19990114 says the prefix xml is bound to the namespace http://www.w3.org/XML/1998/namespace.") + +(defvar *known-namespaces* (list *local-namespace* *xml-namespace*) "The list of known/defined namespaces") +(defvar *namespaces* `(("xml" . ,*xml-namespace*) ("" . ,*local-namespace*)) + "Ordered list of (prefix . XML-namespace) bindings currently in effect - special variable") + (defun find-namespace (uri) "Find a registered XML namespace identified by uri" (find uri *known-namespaces* :key #'get-uri :test #'string-equal)) @@ -179,9 +193,6 @@ :package (find-package package))) *known-namespaces*)) namespace)) - -(defvar *namespaces* `(("" . ,*local-namespace*)) - "Ordered list of (prefix . XML-namespace) bindings currently in effect - special variable") (defun find-namespace-binding (prefix namespaces) "Find the XML namespace currently bound to prefix in the namespaces bindings" From scaekenberghe at common-lisp.net Sun Nov 20 14:34:16 2005 From: scaekenberghe at common-lisp.net (Sven Van Caekenberghe) Date: Sun, 20 Nov 2005 15:34:16 +0100 (CET) Subject: [s-xml-cvs] CVS update: s-xml/src/lxml-dom.lisp s-xml/src/sxml-dom.lisp Message-ID: <20051120143416.817DE88554@common-lisp.net> Update of /project/s-xml/cvsroot/s-xml/src In directory common-lisp.net:/tmp/cvs-serv15528 Modified Files: lxml-dom.lisp sxml-dom.lisp Log Message: fixed a type in a special declaration Date: Sun Nov 20 15:34:15 2005 Author: scaekenberghe Index: s-xml/src/lxml-dom.lisp diff -u s-xml/src/lxml-dom.lisp:1.5 s-xml/src/lxml-dom.lisp:1.6 --- s-xml/src/lxml-dom.lisp:1.5 Tue Sep 20 11:57:44 2005 +++ s-xml/src/lxml-dom.lisp Sun Nov 20 15:34:15 2005 @@ -1,6 +1,6 @@ ;;;; -*- mode: lisp -*- ;;;; -;;;; $Id: lxml-dom.lisp,v 1.5 2005/09/20 09:57:44 scaekenberghe Exp $ +;;;; $Id: lxml-dom.lisp,v 1.6 2005/11/20 14:34:15 scaekenberghe Exp $ ;;;; ;;;; LXML implementation of the generic DOM parser and printer. ;;;; @@ -50,7 +50,7 @@ (plist->alist (rest (rest plist)))))) (defmethod print-xml-dom (dom (input-type (eql :lxml)) stream pretty level) - (declare (special *namespaces)) + (declare (special *namespaces*)) (cond ((symbolp dom) (print-solitary-tag dom stream)) ((stringp dom) (print-string-xml dom stream)) ((consp dom) Index: s-xml/src/sxml-dom.lisp diff -u s-xml/src/sxml-dom.lisp:1.4 s-xml/src/sxml-dom.lisp:1.5 --- s-xml/src/sxml-dom.lisp:1.4 Tue Sep 20 11:57:48 2005 +++ s-xml/src/sxml-dom.lisp Sun Nov 20 15:34:15 2005 @@ -1,6 +1,6 @@ ;;;; -*- mode: lisp -*- ;;;; -;;;; $Id: sxml-dom.lisp,v 1.4 2005/09/20 09:57:48 scaekenberghe Exp $ +;;;; $Id: sxml-dom.lisp,v 1.5 2005/11/20 14:34:15 scaekenberghe Exp $ ;;;; ;;;; LXML implementation of the generic DOM parser and printer. ;;;; @@ -40,7 +40,7 @@ :text-hook #'sxml-text-hook)))) (defmethod print-xml-dom (dom (input-type (eql :sxml)) stream pretty level) - (declare (special *namespaces)) + (declare (special *namespaces*)) (cond ((stringp dom) (print-string-xml dom stream)) ((consp dom) (let ((tag (first dom))