Next: , Previous: , Up: XML Support   [Contents][Index]


14.15.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 Uniform Resource Identifier (URI), which identifies an optional namespace.

procedure: make-xml-name qname uri

Creates and returns an XML name. Qname must be a symbol whose name satisfies string-is-xml-name?. Uri must satisfy either absolute-uri? or null-xml-namespace-uri?. The returned value is an XML name that satisfies xml-name?.

If uri is the null namespace (satisfies null-xml-namespace-uri?), 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, uri may be any object that ->uri is able to convert to a URI record, provided the resulting URI meets the above restrictions.

procedure: xml-name? object

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

procedure: xml-name->symbol xml-name

Returns the symbol part of xml-name.

procedure: xml-name-uri xml-name

Returns the URI of xml-name. The result always satisfies absolute-uri? or null-xml-namespace-uri?.

procedure: xml-name-string xml-name

Returns the qname of xml-name as a string. Equivalent to

(symbol->string (xml-name->symbol 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 URIs, then the names are equal if and only if their local parts are equal and their URIs 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-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.

The namespace URI of an XML name may be null, meaning that there is no namespace associated with the name. This namespace is represented by a relative URI record whose string representation is the null string.

procedure: null-xml-namespace-uri

Returns the null namespace URI record.

procedure: null-xml-namespace-uri? object

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

The following values are two distinguished URI records.

variable: xml-uri

xml-uri is the URI reserved for use by the XML recommendation. This URI must be used with the ‘xml’ prefix.

variable: xmlns-uri

xmlns-uri is the URI reserved for use by the XML namespace recommendation. This URI must be used with the ‘xmlns’ prefix.

procedure: make-xml-nmtoken string
procedure: xml-nmtoken? object
procedure: string-is-xml-name? string
procedure: string-is-xml-nmtoken? string

Next: XML Structure, Previous: XML Output, Up: XML Support   [Contents][Index]