Like other XML parsers written in Lisp, CXML can work with documents represented as list structures. The specific model implemented by cxml is compatible with the xmls parser. Xmls list structures are a simpler and faster alternative to full DOM document trees. They also serve as an example showing how to implement user-defined document models as an independent layer over the the base parser (c.f. xml/xmls-compat.lisp in the cxml distribution). However, note that the list structures do not include all information available in DOM documents (notably, things like dom:parent-node) and are sometimes more difficult to work with because of that since many DOM functions cannot be implemented on them.
New namespace handling: XMLS compatibility is not bug-for-bug-compatible with XMLS any more. There is now a mode using pairs of local name and namespace URI, and a second mode using qualified names only. The old behaviour using pairs of prefix and local names was removed.
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.
If include-namespace-uri is true (the default), node names and attribute names are pairs of local name and namespace URI. (Except for attributes without a namespace, which are named using a string.) Otherwise, nodes and attributes are named by their qualified name.
Example:
(cxml:parse-file "test.xml" (cxml-xmls:make-xmls-builder))
Use this function to serialize XMLS data. For example, we could define a replacement for xmls:write-xml like this:
(defun write-xml (stream node &key indent) (let ((sink (cxml:make-character-stream-sink stream :canonical nil :indentation indent))) (cxml-xmls:map-node sink node)))
The node list's car can also be a cons of local name and namespace prefix ns.