o Add support for including the namespace URI in the element and attribute names.
o Add support for including the namespace URI in the element and attribute names.
Index: xml/xmls-compat.lisp =================================================================== RCS file: /project/cxml/cvsroot/cxml/xml/xmls-compat.lisp,v retrieving revision 1.3 diff -u -r1.3 xmls-compat.lisp --- xml/xmls-compat.lisp 15 May 2006 21:57:47 -0000 1.3 +++ xml/xmls-compat.lisp 13 Jun 2007 08:15:07 -0000 @@ -69,32 +69,56 @@ (root :initform nil :accessor root) (include-default-values :initform t :initarg :include-default-values - :accessor include-default-values))) - -(defun make-xmls-builder (&key (include-default-values t)) - (make-instance 'xmls-builder :include-default-values include-default-values)) + :accessor include-default-values) + (include-namespace-uri :initform nil + :initarg :include-namespace-uri + :accessor include-namespace-uri))) + +(defun make-xmls-builder (&key (include-default-values t) + (include-namespace-uri nil)) + "Make a XMLS style builder. When 'include-namespace-uri is true a modified + XMLS tree is generated that includes the element namespace URI rather than + the qualified name prefix and also includes the namespace URI for attributes." + (make-instance 'xmls-builder :include-default-values include-default-values + :include-namespace-uri include-namespace-uri))
(defmethod sax:end-document ((handler xmls-builder)) (root handler))
(defmethod sax:start-element ((handler xmls-builder) namespace-uri local-name qname attributes) - (declare (ignore namespace-uri)) (setf local-name (or local-name qname)) - (let* ((attributes + (let* ((include-default-values (include-default-values handler)) + (include-namespace-uri (include-namespace-uri handler)) + (attributes (loop for attr in attributes - when (or (sax:attribute-specified-p attr) - (include-default-values handler)) + for attr-namespace-uri = (sax:attribute-namespace-uri attr) + for attr-local-name = (sax:attribute-local-name attr) + when (and (or (sax:attribute-specified-p attr) + include-default-values) + (or (not include-namespace-uri) + (not attr-namespace-uri) + attr-local-name)) collect - (list (sax:attribute-qname attr) + (list (cond (include-namespace-uri + (cond (attr-namespace-uri + (cons attr-local-name attr-namespace-uri)) + (t + (sax:attribute-qname attr)))) + (t + (sax:attribute-qname attr))) (sax:attribute-value attr)))) + (namespace (cond (include-namespace-uri + namespace-uri) + (t + (let ((lq (length qname)) + (ll (length local-name))) + (if (eql lq ll) + nil + (subseq qname 0 (- lq ll 1))))))) (node (make-node :name local-name - :ns (let ((lq (length qname)) - (ll (length local-name))) - (if (eql lq ll) - nil - (subseq qname 0 (- lq ll 1)))) + :ns namespace :attrs attributes)) (parent (car (element-stack handler)))) (if parent
Quoting Douglas Crosher (dtc@scieneer.com):
o Add support for including the namespace URI in the element and attribute names.
Thanks, that was a long-standing issue.
Checked in with a few changes:
+(defun make-xmls-builder (&key (include-default-values t)
(include-namespace-uri nil))
Applied with default (include-namespace-uri t).
when (and (or (sax:attribute-specified-p attr)
include-default-values)
(or (not include-namespace-uri)
(not attr-namespace-uri)
attr-local-name))
What is the (or ..) test for? IIUC, it currently removes declarations for the default namespace (xmlns="a") but not declarations for other namespaces (xmlns:b="a"). If removal of namespace declarations was the idea of this test, it should probably affect all of them, but only if *include-xmlns-attributes* is false.
Applied without the OR.
(t
(let ((lq (length qname))
(ll (length local-name)))
(if (eql lq ll)
nil
(subseq qname 0 (- lq ll 1)))))))
Changed to use just qnames in this mode. The old mode with pairs of local name and prefix was useless.
Finally, I have changed serialization (CXML-XMLS:MAP-NODE) to also distinguish between the two representations. With namespace URI, we run the events through the namespace normalizer, which invents prefixes for us. Without namespaces, we continue to generate namespace-less SAX events, which are suitable for normal serialization purposes (but nothing else, really).
David Lichteblau wrote:
Quoting Douglas Crosher (dtc@scieneer.com):
o Add support for including the namespace URI in the element and attribute names.
Thank you committing these changes and for enhancing it further.
...
when (and (or (sax:attribute-specified-p attr)
include-default-values)
(or (not include-namespace-uri)
(not attr-namespace-uri)
attr-local-name))
What is the (or ..) test for? IIUC, it currently removes declarations for the default namespace (xmlns="a") but not declarations for other namespaces (xmlns:b="a"). If removal of namespace declarations was the idea of this test, it should probably affect all of them, but only if *include-xmlns-attributes* is false.
Applied without the OR.
Yes this was intended to just remove the default namespace attribute, with an attribute local-name of 'nil. Dropping this test does look like the right thing to do as the attribute will be needed when serializing, and *include-xmlns-attributes* can be set to false to avoid them. Cleanup patch attached.
Regards Douglas Crosher
Index: xml/xmls-compat.lisp =================================================================== RCS file: /project/cxml/cvsroot/cxml/xml/xmls-compat.lisp,v retrieving revision 1.4 diff -u -r1.4 xmls-compat.lisp --- xml/xmls-compat.lisp 16 Jun 2007 11:07:58 -0000 1.4 +++ xml/xmls-compat.lisp 17 Jun 2007 04:23:40 -0000 @@ -88,6 +88,7 @@
(defmethod sax:start-element ((handler xmls-builder) namespace-uri local-name qname attributes) + (declare (ignore qname)) (let* ((include-default-values (include-default-values handler)) (include-namespace-uri (include-namespace-uri handler)) (attributes @@ -95,24 +96,18 @@ for attr in attributes for attr-namespace-uri = (sax:attribute-namespace-uri attr) for attr-local-name = (sax:attribute-local-name attr) - when (and (or (sax:attribute-specified-p attr) - include-default-values) - #+(or) - (or (not include-namespace-uri) - (not attr-namespace-uri) - attr-local-name)) + when (or (sax:attribute-specified-p attr) + include-default-values) collect (list (cond (include-namespace-uri - (cond (attr-namespace-uri - (cons attr-local-name attr-namespace-uri)) - (t - (sax:attribute-qname attr)))) + (if attr-namespace-uri + (cons attr-local-name attr-namespace-uri) + (sax:attribute-qname attr))) (t (sax:attribute-qname attr))) (sax:attribute-value attr)))) - (namespace (when include-namespace-uri namespace-uri)) (node (make-node :name local-name - :ns namespace + :ns (and include-namespace-uri namespace-uri) :attrs attributes)) (parent (car (element-stack handler)))) (if parent