The XML data model is similar to HTML, with one important addition: XML tags may be qualified names, which are similar to compound symbols.
Syntax: define-xml-namespace
prefix
"namespace-uri"
Defines a namespace with prefix
prefix
and URInamespace-uri
. This is similar todefine-namespace
but with two important differences:
Every symbol in the namespace automatically maps to an element-constructor-type, as with the
html
namespace.The
prefix
is a component of the namespace object, and hence indirectly of any symbols belongining to the namespace.
$ kawa --output-format xml #|kawa:1|# (define-xml-namespace na "Namespace1") #|kawa:2|# (define-xml-namespace nb "Namespace1") #|kawa:3|# (define xa (na:em "Info")) #|kawa:4|# xa <na:em xmlns:na="Namespace1">Info</na:em> #|kawa:5|# (define xb (nb:em "Info")) #|kawa:6|# xa <nb:em xmlns:nb="Namespace1">Info</nb:em>
Note that the prefix is part of the qualified name (it is actually part of the namespace object), and it is used when printing the tag. Two qualified names (symbols) that have the same local-name and the same namespace-name are considered equal, even if they have different prefix. You can think of the prefix as annotation used when printing, but not otherwise part of the “meaning” of a compound symbol. They are the same object if they also have the same prefix. This is an important different from traditional Lisp/Scheme symbols, but it is how XML QNames work.
#|kawa:7|# (instance? xb na:em) true #|kawa:8|# (eq? 'na:em 'nb:em) false #|kawa:9|# (equal? 'na:em 'nb:em) true #|kawa:10|# (eqv? 'na:em 'nb:em) true
(Note that #t
is printed as true
when using XML formatting.)
The predefined html
prefix could be defined thus:
(define-xml-namespace html "http://www.w3.org/1999/xhtml")
Function: make-element
tag
[attribute
...
] child
...
Create a representation of a XML element, corresponding to
<tag
attribute
...>child
...</tag
>The result is a
TreeList
, though if the result context is a consumer the result is instead "written" to the consumer. Thus nested calls tomake-element
only result in a singleTreeList
. More generally, whether anattribute
orchild
is includded by copying or by reference is (for now) undefined. Thetag
should currently be a symbol, though in the future it should be a qualified name. Anattribute
is typically a call tomake-attribute
, but it can be any attribute-valued expression.(make-element 'p "The time is now: " (make-element 'code (make <java.util.Date>)))
Function: make-attribute
name
value...
Create an "attribute", which is a name-value pair. For now,
name
should be a symbol.
You must do this to use the following types and functions:
(require 'xml)
Instances of this type represent comment values, specifically including comments in XML files. Comment nodes are currently ignored when printing using Scheme formatting, though that may change.
Instances of this type represent “processing instructions”, such as may appear in XML files. Processing-instruction nodes are currently ignored when printing using Scheme formatting, though that may change.