MIT/GNU Scheme implements XML names in a slightly complex way. Unfortunately, this complexity is a direct consequence of the definition of XML names rather than a mis-feature of this implementation.
The reason that XML names are complex is that XML namespace support, which was added after XML was standardized, is not very well integrated with the core XML definition. The most obvious problem is that names can't have associated namespaces when they appear in the DTD of a document, even if the body of the document uses them. Consequently, it must be possible to compare non-associated names with associated names.
An XML name consists of two parts: the qname, which is a symbol, possibly including a namespace prefix; and the Internationalized Resource Identifier (IRI), which identifies an optional namespace.
Creates and returns an XML name. Qname must be a symbol whose name satisfies
string-is-xml-name?
. Iri must be anxml-namespace-iri
record. The returned value is an XML name that satisfiesxml-name?
.If iri is the null namespace (satisfies
null-xml-name-prefix?
), the returned value is a symbol equivalent to qname. This means that an ordinary symbol can be used as an XML name when there is no namespace associated with the name.For convenience, qname may be a string, in which case it is converted to a symbol using
make-xml-qname
.For convenience, iri may be a string, in which case it is converted to an
xml-namespace-iri
record usingmake-xml-namespace-iri
.
Returns the qname of xml-name as a string. Equivalent to
(symbol-name (xml-name-qname xml-name))
The next two procedures get the prefix and local part of an XML name, respectively. The prefix of an XML name is the part of the qname to the left of the colon, while the local part is the part of the qname to the right of the colon. If there is no colon in the qname, the local part is the entire qname, and the prefix is the null symbol (i.e. ||).
The next procedure compares two XML names for equality. The rules for equality are slightly complex, in order to permit comparing names in the DTD with names in the document body. So, if both of the names have non-null namespace IRIs, then the names are equal if and only if their local parts are equal and their IRIs are equal. (The prefixes of the names are not considered in this case.) Otherwise, the names are equal if and only if their qnames are equal.
Returns
#t
if xml-name-1 and xml-name-2 are the same name, and#f
otherwise.
These next procedures define the data abstraction for qnames. While
qnames are represented as symbols, only symbols whose names satisfy
string-is-xml-name?
are qnames.
String must satisfy
string-is-xml-name?
. Returns the qname corresponding to string (the symbol whose name is string).
Returns a newly allocated string that is a copy of qname's string. Roughly equivalent to
symbol->string
.
The prefix of a qname or XML name may be absent if there is no colon in the name. The absent, or null, prefix is abstracted by the next two procedures. Note that the null prefix is a symbol, just like non-null prefixes.
Returns
#t
if object is the null prefix, otherwise returns#f
.
These next procedures define the data abstraction for namespace
IRIs. Conceptually, an IRI is a string with a
particular syntax, but this implementation uses an abstract
representation that speeds up type and equality testing. Two
IRIs are tested for equality using eq?
.
String must be a syntactically valid IRI encoded in UTF-8. Returns the corresponding IRI.
Iri must satisfy
xml-namespace-iri?
. Returns a newly allocated string that is a copy of the string used to create iri.
The IRI of an XML name may be null if there is no
namespace associated with the name. The null IRI is
abstracted by the following two procedures. Note that the null
IRI satisfies the predicate xml-namespace-iri?
.
Returns
#t
if object is the null IRI record, otherwise returns#f
.
The following values are two distinguished IRI records.
xml-iri
is the IRI reserved for use by the XML recommendation. This IRI must be used with the xml prefix.