Beruflich Dokumente
Kultur Dokumente
MODULE 1
Namespaces: Organizing Elements with Namespaces
1. Namespaces and URI
2. Namespace Declarations
3. Examples
4. Types: Default and Explicit Namespaces
UDAY BABU P
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
VIDYA ACADEMY OF SCIENCE AND TECHNOLOGY
NAMESPACE in detail
For example, consider the element 'name' in an XML document. The
name element could contain the name of a person, an organization, a
country and so on. One of the name element in the XML document
could store customer name, while another name element could store
product names. This conflict can be resolved using namespaces.
Namespaces can be used to uniquely identify each name element.
Namespaces help the applications using XML documents to clearly
identify its elements and attributes, resolving any conflicts with
identically named elements and attributes in other XML documents.
Namespaces are thus used to organize the elements and attributes of
an XML documents into separate collections.
NAMESPACE declaration
The form of a namespace declaration for an element is
<element_name xmlns[:prefix] = URI>
NAMESPACE DECLARATION
Within the birds element, including all of its children elements, the
names from the given namespace must be prefixed with bd, as
in the following element:
<bd:lark>
DEFAULT NAMESPACE
Default namespace is applied to all the elements and nested
elements beneath the element that declares the namespace.
Prefix may be omitted.
A default namespace for an entire XML document can be
selected by using the xmlns attribute in the documents root
element.
Explicit NAMESPACE
Namespaces that are assigned to individual elements in an XML
document are called explicit namespaces.
To explicitly declare a namespace for a specific element in an XML
document, you must assign a prefix to the namespace declaration using
the following syntax
<element_name xmlns:prefix=URI>
Prefix and colon is needed for the opening as well as ending tags
for each element.