Are You Recruiter/Hiring Manager

*Filter candidates using TestYourCandidate.com and save 80% time ( saving time for recruiters and interviewers)
*More than 50% candidates can be filtered on Candidate Screening online tests
*Inbuilt exams are available in library, created and tested by experts Try Today...

Describe the use of namespaces in an XML document.

The XML namespaces recommendation defines a way to distinguish between duplicate element type and attribute names. Such duplication might occur, for example,
in an XSLT stylesheet or in a document that contains element types and attributes from two different DTDs.

An XML namespace is a collection of element type and attribute names. The namespace is identified by a unique name, which is a URI. Thus, any element type
or attribute name in an XML namespace can be uniquely identified by a two-part name: the name of its XML namespace and its local name. This two-part
naming system is the only thing defined by the XML namespaces recommendation.

XML namespaces are declared with an xmlns attribute, which can associate a prefix with the namespace.
You can declare an XML namespace on any element in an XML document. The declaration is in scope
for the element containing the attribute and all its descendants (unless it is overridden or undeclared on one of those descendants).
It is a common practice to declare all namespaces within the root element. For example:

You may override the prefix used in an XML namespace declaration, simply declare another XML namespace with the same prefix.
For example, in the following, the foo prefix is associated with the http://www.foo.org/
namespace on the
aaa element and the http://www.bar.org/ namespace on the bbb element.
That is, the name aaa
is in the http://www.foo.org/ namespace and the name bbb is in
the http://www.bar.org/ namespace.

This practice leads to documents that are confusing to read and should be avoided.

When an XML namespace declaration goes out of scope, it simply no longer applies. For example, in the following, the declaration of
the http://www.foo.org/ namespace does not apply to the bbb element because
this is outside its scope.

<!-- 'bbb' does NOT belong to any namespace. -->
<aaa xmlns="http://www.foo.org/">abcd</aaa>
<bbb>abcd</bbb>

You may undeclare the default XML namespace - declare a default XML namespace with an empty (zero-length) name (URI). Within the
scope of this declaration,
unprefixed element type names do not belong to any XML namespace. For example, in the following, the default XML namespace is the
http://www.foo.org/ for the aaa and there is no default XML namespace for
the bbb elements.
The name aaa is in the http://www.foo.org/ namespace and the
name bbb is not in any
XML namespace.

You may NOT undeclare XML namespace prefix. It remains in scope until the end of the element on which it was declared unless it is
overridden. Furthermore, trying to undeclare a prefix by redeclaring it with an empty (zero-length) name (URI) results in a namespace error.
For example: