Next: , Previous: XML Output, Up: XML Support



14.12.3 XML Names

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.

— procedure: make-xml-name qname iri

Creates and returns an XML name. Qname must be a symbol whose name satisfies string-is-xml-name?. Iri must be an xml-namespace-iri record. The returned value is an XML name that satisfies xml-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 using make-xml-namespace-iri.

— procedure: xml-name? object

Returns #t if object is an XML name, and #f otherwise.

— procedure: xml-name-qname xml-name

Returns the qname of xml-name as a symbol.

— procedure: xml-name-iri xml-name

Returns the IRI of xml-name as an xml-namespace-iri record.

— procedure: xml-name-string xml-name

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. ||).

— procedure: xml-name-prefix xml-name

Returns the prefix of xml-name as a symbol.

— procedure: xml-name-local xml-name

Returns the local part of xml-name as a symbol.

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.

— procedure: xml-name=? xml-name-1 xml-name-2

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.

— procedure: make-xml-qname string

String must satisfy string-is-xml-name?. Returns the qname corresponding to string (the symbol whose name is string).

— procedure: xml-qname? object

Returns #t if object is a qname, otherwise returns #f.

— procedure: xml-qname-string qname

Returns a newly allocated string that is a copy of qname's string. Roughly equivalent to symbol->string.

— procedure: xml-qname-prefix qname

Returns the prefix of qname as a symbol.

— procedure: xml-qname-local qname

Returns the local part of qname as a symbol.

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.

— procedure: null-xml-name-prefix

Returns the null prefix.

— procedure: null-xml-name-prefix? object

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?.

— procedure: make-xml-namespace-iri string

String must be a syntactically valid IRI encoded in UTF-8. Returns the corresponding IRI.

— procedure: xml-namespace-iri? object

Returns #t if object is an IRI record, otherwise returns #f.

— procedure: xml-namespace-iri-string 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?.

— procedure: null-xml-namespace-iri

Returns the null IRI record.

— procedure: null-xml-namespace-iri? object

Returns #t if object is the null IRI record, otherwise returns #f.

The following values are two distinguished IRI records.

— variable: xml-iri

xml-iri is the IRI reserved for use by the XML recommendation. This IRI must be used with the xml prefix.

— variable: xmlns-iri

xmlns-iri is the IRI reserved for use by the XML namespace recommendation. This IRI must be used with the xmlns prefix.

— procedure: make-xml-nmtoken string
— procedure: xml-nmtoken? object
— procedure: xml-nmtoken-string xml-nmtoken
— procedure: string-is-xml-name? string
— procedure: string-is-xml-nmtoken? string
— procedure: make-xml-name-hash-table [initial-size]
— procedure: xml-name-hash xml-name modulus