• +49-(0)721-402485-12
Your experts for XML, XQuery and XML Databases

The xml namespace

XML 1.0 specifies two special attributes, xml:lang and xml:space, from the http://www.w3.org/XML/1998/namespace namespace. For this namespace the xml prefix is always predefined.

The xml:lang attribute can be used in order to indicate the language in which the element and the attribute content are written. As with namespace definition, the indicated value applies for the element in which it appears and for all child elements, unless it is overwritten there. The value of the attribute depends on the identification of languages defined in "RFC 1766".

In the following example, the diagnosis is indicated once in German and once in Latin:

<Patient>
<Diagnosis xml:lang="de">Coronary heart vessel diseases</Diagnosis>
<Diagnosis xml:lang="la">Angina pectoris</Diagnosis>
</Patient>

If this attribute shall be used in a valid document, it must be declared in the DTD or the schema as any other attribute:

<!ATTLIST Diagnosis xml:lang CDATA #IMPLIED>

The examples already shown make it clear that it is often helpful to insert whitespace, such as line breaks, space characters, etc., to simplify the readability of XML documents. This whitespace does not contribute to the meaning of the documents: It can be ignored during the processing. However, in other places, the whitespace is significant (e.g. in poems) and must not be removed.

A XML processor has to pass on all characters (including whitespace) being outside the markup to an application. However, this application is free in the treatment of the characters. The special xml:space attribute can send a signal to the application that the whitespace shall be preserved (xml:space="preserve") or that the application shall proceed according to its default settings (xml:space="default"). This indication applies for the element in which it appears and for its child elements (provided it does not also appear there) as well as for all attributes appearing in these elements.

This attribute, too, must be declared in the DTD if it shall be used in a valid document. It must be declared as enumeration type, e.g.:

<!ATTLIST Poem xml:space (default | preserve) "preserve">
<!ATTLIST Code xml:space (preserve) #FIXED "preserve">

 

Source: "XQuery – Grundlagen und fortgeschrittene Methoden", dpunkt-Verlag, Heidelberg (2004)

<< backnext >>