Zum Inhalt springen
uencoder

XML Namespace Leitfaden

Referenz für XML namespaces, prefix binding, und default namespace handling.

Namespace Basics

XML namespaces disambiguate element and attribute names by associating them with URIs. The xmlns attribute declares a default namespace; xmlns:prefix binds a prefix. Namespaces are URIs, not URLs; they need not be resolvable. The same local name in different namespaces are distinct elements. Namespaces enable mixing vocabularies (e.g., XHTML + SVG + MathML) in one document.

xmlns
Default namespace
no prefix needed
xmlns:prefix
Prefix binding
ns:element
URI
Identifier not address
need not resolve

Practical Issues

Default namespaces do not apply to attributes; attributes are unprefixed or use a prefix. Namespace prefixes are arbitrary; only the URI matters for identity. QNames in attribute values (e.g., xsi:type) require prefix-to-URI mapping. The XML Namespaces 1.1 spec allows undeclaring prefixes. Correct namespace handling is essential for schema validation and XPath/XSLT.

attributes
No default namespace
must use prefix
QName
Prefix in value
xsi:type="ns:Type"
identity
URI matters, not prefix
prefix is alias

Verwandte Tools

参考链接