Tutorial by Examples

A namespace is a URI, but to avoid verbosity, prefixes are used as a proxy. In the following example, the prefix my-prefix is bound to the namespace http://www.example.com/my-namespace by using the special attribute xmlns:my-prefix (my-prefix can be replaced with any other prefix): <?xml versio...
In XML, element and attribute names live in namespaces. By default, they are in no namespace: <?xml version="1.0"?> <foo attr="value"> <!-- the foo element is in no namespace, neither is the attr attribute --> </foo>
These two documents are semantically equivalement, as namespaces matter, not prefixes. <?xml version="1.0"?> <myns:foo xmlns:myns="http://www.example.com/my-namespace"> </myns:foo> <?xml version="1.0"?> <ns:foo xmlns:ns="http://www...
The default namespace is the namespace corresponding to the absence of any prefix. It can be declared with the special xmlns attribute. <?xml version="1.0"?> <foo xmlns="http://www.example.com/my-namespace"> <!-- the element foo is in the namespace htt...
Elements and attributes behave differently with respect to default namespaces. This is often the source of confusion. An attribute whose name has no prefix lives in no namespace, also when a default namespace is in scope. <?xml version="1.0"?> <foo attr="value" xmlns=...
A namespace binding (special xmlns or xmlns:... attribute) is in scope for all the descendants of the enclosing element, including this element. <?xml version="1.0"?> <root> <my:element xmlns:my="http://www.example.com/ns1"> <!-- here, the prefix my...

Page 1 of 1