[cxml-devel] Bugs in namespace parsing.

David Lichteblau david at lichteblau.com
Tue May 22 09:04:24 UTC 2007


Quoting Peder Chr. N?rgaard (pcn at pogt.dk):
> There seems to be not one, but two problems.  First, the parser or the
> builder ignores the rule that the scope of an xmlns attribute starts
> from the tag of the element in which it is included.  Second, (and
> that is probably the builder) fail to apply the default namespace to
> internal elements.

The XML parser implements namespace handling correctly.

The XMLS-compatible builder is incorrect, because it is immitating XMLS
behaviour.

If I may quote from my own documentation:

	fixme: It is unclear to me how namespaces are meant to work in
	xmls, since xmls documentation differs from how xmls actually
	works in current releases. Usually applications need to know
	both the namespace prefix and the namespace URI. We currently
	follow the xmls implementation and use the namespace prefix
	instead of following its documentation which shows the URI. We
	do not follow xmls in munging xmlns attribute values.
	Attributes themselves have namespaces and it is not clear to me
	how that works in xmls.

> FYI, XMLS has the approximately the same kind of bug.  So has the PXML suite 
> from Franz.  It is evidently something that is a bit tough to get right.  
> Maybe because it involves two scans of a <> construction - you really don't 
> know the namespace of tags and attributes until you have parsed the entire <> 
> construction and located the zero-or-one "xmlns=" and the 
> zero-one-or-many "xmlns:<name>=" attributes.

Based on CXML's SAX parser, tt is not hard at all to write a builder
with correct namespace support, you just have to pick the format you
want and implement it.  The SAX parser already does all namespace
processing, so the events SAX:START-ELEMENT and SAX:END-ELEMENT include
all necessary information, as separate arguments (or slots in the case
of the attributes).

The XMLS builder source code in CXML is also meant as copy&paste
material in this regard, because it is a simple SAX handler that can
easily be adapted.


In fact, Edi Weitz has already done exactly that.  Download CL-WEBDAV
(http://weitz.de/cl-webdav/) and have a look at xml.lisp in that
tarball.  As Edi writes on his page:

	We're representing XML as XMLS nodes which are very similar to
	CXML's XMLS nodes but try to get namespaces right because they
	don't purport to be compatible with XMLS

Apparently there is some WebDav specific code in xml.lisp, but that
should be easy to remove.


Regards,
David



More information about the cxml-devel mailing list