[s-xml-devel] *auto-create-prefixless-namespace-names*

Bill St. Clair wws at clozure.com
Fri Apr 9 20:48:34 UTC 2010


I find it confusing that when an XML stream defines a namespace, but no
name for that namespace that s-xml puts the tags in a package named
"ns-~d", where ~d is the first integer found that doesn't already have
an associated package. This is apparently how XML is specified, but it
makes it difficult to write code with static tag symbols. I have added a
variable, *auto-create-prefixless-namespace-names*, which when bound to
true causes the tags for namespaces with no name to be put in the
keyword package. This is NOT the default, so existing code will be
unaffected. Diff below:

-Bill St. Clair

Index: src/package.lisp
===================================================================
RCS file: /project/s-xml/cvsroot/s-xml/src/package.lisp,v
retrieving revision 1.8
diff -r1.8 package.lisp
40a41
>    #:*auto-create-prefixless-namespace-names*
Index: src/xml.lisp
===================================================================
RCS file: /project/s-xml/cvsroot/s-xml/src/xml.lisp,v
retrieving revision 1.16
diff -r1.16 xml.lisp
279a280,281
> (defvar *auto-create-prefixless-namespace-names* t)
>
282,297c284,301
<   (if prefix
<       (register-namespace uri
<                           prefix
<                           (or (find-package prefix)
<                               (if *auto-create-namespace-packages*
<                                   (make-package prefix :nicknames
`(,(string-upcase prefix)))
<                                 (error "Cannot find or create package
~s" prefix))))
<     (let ((unique-name (loop :for i :upfrom 0
<                              :do (let ((name (format nil "ns-~d" i)))
<                                    (when (not (find-package name))
<                                      (return name))))))
<       (register-namespace uri
<                           unique-name
<                           (if *auto-create-namespace-packages*
<                               (make-package (string-upcase
unique-name) :nicknames `(,unique-name))
<                             (error "Cannot create package ~s"
unique-name))))))
---
>   (cond (prefix
>          (register-namespace uri
>                              prefix
>                              (or (find-package prefix)
>                                  (if *auto-create-namespace-packages*
>                                      (make-package prefix :nicknames
`(,(string-upcase prefix)))
>                                      (error "Cannot find or create
package ~s" prefix)))))
>         (*auto-create-prefixless-namespace-names*
>          (let ((unique-name (loop :for i :upfrom 0
>                                :do (let ((name (format nil "ns-~d" i)))
>                                      (when (not (find-package name))
>                                        (return name))))))
>            (register-namespace uri
>                                unique-name
>                                (if *auto-create-namespace-packages*
>                                    (make-package (string-upcase
unique-name) :nicknames `(,unique-name))
>                                    (error "Cannot create package ~s"
unique-name)))))
>         (t (register-namespace uri "" (find-package :keyword)))))




More information about the s-xml-devel mailing list