In this example, <title> tag can be ambiguous. It can mean a person's name for the name from the résumé
<?xml version="1.0"?>
<person>
<name>
<title>Sir</title>
<first>John</first>
<middle>Fitzgerald Johansen</middle>
<last>Doe</last>
</name>
<position>Vice President of Marketing</position>
<résumé>
<html>
<head><title>Resume of John Doe</title></head>
<body>
<h1>John Doe</h1>
<p>John's a great guy, you know?</p>
</body>
</html>
</résumé>
</person>
Namespace
To use XML namespaces, elements are given qualified names.
Qualified name is abbreviated to QName.
These QName consist of two parts.
The local part is the same as the names we have been giving elements.
The namespace prefix specifies to which namespace this name belongs.
Qualified name is abbreviated to QName.
These QName consist of two parts.
The local part is the same as the names we have been giving elements.
The namespace prefix specifies to which namespace this name belongs.
When namespace is applied to the xml document:
<?xml version="1.0"?>
<pers:person xmlns:pers="http://www.wiley.com/pers"
xmlns:html="http://www.w3.org/1999/xhtml">
<pers:name>
<pers:title>Sir</pers:title>
<pers:first>John</pers:first>
<pers:middle>Fitzgerald Johansen</pers:middle>
<pers:last>Doe</pers:last>
</pers:name>
<pers:position>Vice President of Marketing</pers:position>
<pers:resume>
<html:html>
<html:head><html:title>Resume of John Doe</html:title></html:head>
<html:body>
<html:h1>John Doe</html:h1>
<html:p>John's a great guy, you know?</html:p>
</html:body>
</html:html>
</pers:resume>
</pers:person>
Notice you can distinguish which the titles with namespace now.
The pers is the default namespace
Default Namespace
A default namespace is like a regular namespace. You don't have to specify a prefix for all of the elements that use it.
In this example http://www.wiley.com/pers is the default namespace
The namespace will only apply to itself and its descendant. So "http://www.w3.org/1999/xhtml" will be the namespace for the html part of the person.xml
<?xml version="1.0"?>
<person xmlns="http://www.wiley.com/pers">
<name>
<title>Sir</title>
<first>John</first>
<middle>Fitzgerald Johansen</middle>
<last>Doe</last>
</name>
<position>Vice President of Marketing</position>
<résumé>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Resume of John Doe</title></head>
<body>
<h1>John Doe</h1>
<p>John's a great guy, you know?</p>
</body>
</html>
</résumé>
</person>
Namespace and attribute
<person xmlns="http://www.wiley.com/pers">
<name id="25">
<title>Sir</title>
</name>
</person>
In the preceding example, although name is in the default namespace, id="25" is NOT in the same namespace as name
to make id="25" in the same namespace as name, explicitly specify it:
<a:person xmlns:a="http://www.wiley.com/pers">
<a:name a:id="25">
<a:title>Sir</a:title>
</a:name>
</a:person>