[s-xml-devel] XML Namespace Support Added

Sven Van Caekenberghe sven at beta9.be
Tue Aug 30 13:51:47 UTC 2005

Hi All,

I recently added XML namespace support to S-XML.
I need this to support the CL-SOAP implementation that I am working on.

This code is 'experimental', only available in CVS and not yet released.

Here is a short description of how things were designed/implemented  
(most of it is internal stuff).

The XML Namespace spec is http://www.w3.org/TR/REC-xml-names/

Although the spec is simple, real life interoperability is tricky.

First of all, there is a variable s-xml:*ignore-namespaces* which can  
be used
to switch off all namespace support (S-XML should behave like before).

XML Namespaces are identified by URIs (unique strings actually).
The idea is to map XML Namespaces 1-1 to Common Lisp packages.
This is done by adding to (or editing) the info stored under s- 

(s-xml:find-namespace <uri>) is used to find known namespaces

(s-xml:register-namespace <uri> <prefix> <package>) is used to add/ 
edit known namespaces.
The prefix is the default prefix used when no other is specified/ 
active (see further).

The s-xml:*local-namespace* is always known (and maps unqualified  
identifiers to the keyword package).

For example, the following code defines/installs a namespace:

(defconstant +soapenv-ns-uri+ "http://schemas.xmlsoap.org/soap/ 

(defpackage :soapenv
   (:nicknames "soapenv")
   (:export "Envelope" "Header" "Body" "Fault" "encodingStyle")
   (:documentation "Package for symbols in the SOAP Envelope XML  

(defparameter *soapenv-ns* (s-xml:register-namespace +soapenv-ns-uri+  
"soap-env" :soapenv))

Now, there is a difference between the known XML namespaces (as  
described above),
and the current prefix to namespace bindings used during XML parsing  
or printing.
The bindings are controlled by xmlns[:prefix] attributes.

The bindings are held in the special variable s-xml:*namespaces*  
which starts with the empty
prefix bound to *local-namespace* (see above).

There are 3 major operations:

1. (s-xml:resolve-identifier identifier namespaces &optional as- 

Given a possibly qualified XML identifier string and current  
namespace bindings (typically s-xml:*namespaces*),
intern the identifier as a symbol in the correct CL package

2. (s-xml:print-identifier identifier stream &optional as-attribute)

Given a CL symbol, print it as a possibly qualified XML identifier on  
using the value of the s-xml:*namespaces*

[Writing this, I now see this is inconsistent API: add as parameter  
or remove in others]

3. (s-xml:extend-namespaces attributes namespaces)

Given an alist (name . value) of the attributes of the current XML tag,
search for xmlns[:prefix] attributes and possibly extend the current  
namespace bindings
as necessary (and possibly creating CL packages and registering new  
XML namespaces).

While resolving XML identifiers, either known namespaces and CL  
packages are used,
or new ones are created if necessary. Newly interned symbols can be  
exported automatically.

Note that XML identifiers are case sensitive which leads to  
'unprintable' CL symbols like :|Foo|

The following variables control some of the automatic, behind-the- 
scenes behavior:




The net result is that apart from predefining some namespaces for  
most namespace stuff is handled automatically during parsing and dom  
Note that for printing to be correct, the xmlns[:prefix] attributes  
have to be preserved.

Some XML namespace examples and tests will be added (much) later.

When the CL-SOAP project starts to release some code,
example usages will be found there too.

All comments are welcome,


Sven Van Caekenberghe - http://homepage.mac.com/svc
Beta Nine - software engineering - http://www.beta9.be

"Lisp isn't a language, it's a building material." - Alan Kay

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2355 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/s-xml-devel/attachments/20050830/ecd518aa/attachment.bin>

More information about the s-xml-devel mailing list