XML namespace
XML Namespaces (English " XML namespaces " ) can be used to identify the vocabulary of an XML document clearly and to mix multiple XML languages in a single document. Their function is to be compared with prefix in phone numbers.
For example describes the
element in XHTML a paragraph; in an XML language for a personnel database could represent
an element for a person. Namespaces allow to distinguish these elements clearly.
The namespace mechanism for XML data has been developed by the W3 Consortium and is since 8 December, 2009 the third edition both XML 1.0 and XML 1.1 before. The first version of the specification is dated 14 January 1999, about a year after the XML specification was adopted. For this reason, one finds, for example, in the Recommendation MathML 1.0 no namespace specified. The second version was published on 16 August 2006.
- 4.1 colons in element names
- 4.2 URLs as namespaces
- 4.3 Document Type Definitions and Namespaces
Structure of XML namespaces
Namespaces are represented by URIs, so mostly by normal web addresses. It should be noted that the corresponding address does not need to exist. It can be defined arbitrarily. It is also important that must be in the namespace information is case- sensitive, even in the host portion, as well as any URL encoding, eg% C3% A4 instead of ä, respected.
If a URL is used as a namespace, but it usually makes sense to offer at this address additional information about the XML language, such as a document type definition (DTD) or an XML schema.
Use namespaces
For namespaces attribute xmlns is ( for eng. XML namespace ) is used:
Rest of the HTML file ... html> The element and all its child elements, ie elements within ... html> belong here for namespace W3C XHTML namespace. Namespaces can also be nested:
XHTML elements ...
In addition to the above-described method, there exists a prefix mechanism: Items can be set by a string that is separated by a colon from the element name, in any namespace. The prefix must have no relationship to the namespace, but first be " bound" to the namespace:
< html xmlns = " http://www.w3.org/1999/xhtml "
xmlns: m = " http://www.w3.org/1998/Math/MathML " >
XHTML elements ...
< html xmlns = " http://www.w3.org/1999/xhtml "
xmlns: m = " http://www.w3.org/1998/Math/MathML " >
XHTML elements ...
The prefix xmlns
Technically speaking, a construct of the type xmlns: m an attribute with a namespace prefix. There is therefore in the case of using an additional prefix namespace
Xmlns: xmlns = " http://www.w3.org/2000/xmlns/ " in the document. However, this is not explicitly specified, but assumed XML processing programs. As the following xml is firmly linked with the namespace given above also this prefix.
The prefix xml
XML elements can not begin with the string xml. It follows that also XML namespace prefixes must not start with xml. In fact, to a xml namespace for elements and attributes is bound, the reserved, the W3 Consortium for extensions of XML.
The URI for this namespace is the XML namespace. You need not be specified explicitly, but is inserted by the processing programs themselves.
Currently the following attributes exist with prefix xml (April 2010 ):
Attributes in XML are called associated nodes. You are not treated like normal child elements of an element. With namespaces, this means that attributes are not in the namespace of the element in which they are listed, but by default in the null namespace.
There are cases in which one wants to explicitly change. For example, links are included in SVG of the XLink language provides a set of attributes with which links can be described. In this case, the individual attributes must be prefixed with:
< svg xmlns = " http://www.w3.org/2000/svg " xmlns: xlink = " http://www.w3.org/1999/xlink " > link to Figure 2 a> svg > There is no way to put it without prefix in a particular namespace for attributes.
Example
The following example elements or attributes from the XML languages XHTML (blue), MathML (red), SVG ( green) and without namespace ( black) mixed. In particular, note that the attribute is xmlns itself in no namespace, its value is only colored to indicate which elements are affected by it.
< html xmlns = " http://www.w3.org/1999/xhtml " xmlns: svg = " http://www.w3.org/2000/svg " >