Zum Inhalt springen
uencoder

XML Namespace Referenz

XML namespaces, prefixes, default namespace, und QName resolution per W3C Namespaces in XML 1.0.

Namespace Declaration

An XML namespace is identified by a URI reference and declared using the xmlns attribute. A prefix is bound to the namespace URI with xmlns:prefix and used to qualify element and attribute names. The default namespace declared with xmlns applies to elements without a prefix but does not apply to attributes. Prefixes are local to the element where they are declared and visible to all descendants.

xmlns
Default namespace for unqualified elements
xmlns="http://ns"
xmlns:prefix
Binds a prefix to a namespace URI
xmlns:xs="..."
QName
Qualified name: prefix plus local name
xs:schema

URI Identity

The namespace URI is an opaque identifier, not a locator, and need not resolve to a retrievable resource. Two namespaces are equal only if their URI strings are character-for-character identical, including trailing slashes and case. This strict equality means common mistakes like adding a trailing slash break namespace matching. Prefixes are purely syntactic sugar and can be renamed without changing semantics as long as the bound URI stays the same.

Default Namespace and Attributes

The default namespace does not apply to attributes, so unprefixed attributes belong to no namespace. This asymmetry exists for backward compatibility with pre-namespace XML. An attribute that needs a namespace must use an explicit prefix. Mixing prefixed elements with a default namespace is legal but can confuse readers, so consistent style is recommended within a document.

Verwandte Tools

参考链接