14
Namespaces

2. XML-Namespaces

Embed Size (px)

Citation preview

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 1/14

Namespaces

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 2/14

Module Introduction

Welcome to the module, Namespaces.

This module introduces XML Namespaces

and the reasons for using Namespaces in

XML documents.

This module aims at giving a clear 

understanding of Namespaces syntax.

In this module, you will learn about:

XML Namespaces

Working with Namespaces Syntax

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 3/14

#1 - XML Namespaces Lesson Overview

Identify the need for a namespace.

Define and describe namespaces in XML.

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 4/14

Need for a Namespace

In XML, element names are

defined by the developer.

This often results in a conflict

when trying to mix XMLdocuments from different XML

applications.

XML Namespaces Provide a

method to avoid element nameconflicts.

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 5/14

Define Namespaces

In XML, elements are distinguished by using namespaces.

XML Namespaces provide a globally unique name for an elementor attribute so that they do not conflict one another.

A namespace is a collection of names that can be used aselement names or attribute names in XML document.

Namespaces allow the browser to:

Combine documents from different sources, and help identify thesource of elements or attributes.

 Access DTD or other description of the elements and attributesagainst which, the document is validated.

A Namespace is identified by the URI.

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 6/14

#2 - Working with Namespaces Syntax

Explain the syntax for XML namespaces.

Discuss attributes and namespaces.

Discuss how to use default namespaces.

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 7/14

Solving the Name Conflict

by Pref ixing element names 

There will be no conflict because the two <table> elements havedifferent names.

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 8/14

XML Namespaces Syntax- The “xmlns” Attribute 

When using prefixes in XML, aso-called namespace for theprefix must be defined.

The namespace is defined bythe “xmlns” attribute in the

start tag of an element.

Syntax:xmlns:prefix ="URI "

Prefix must not begin with

“xml” or “xmlns”

The namespace URI is not usedby the parser to look upinformation

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 9/14

XML Namespaces - The “xmlns” Attribute 

Namespaces can be declared:

1. In the elements where they are used

2. In the XML root element

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 10/14

Placing attributes in a namespaces

Attribute belong to particular elements and they are not a part

of namespaces, even if the element is within some

namespaces

If an attribute name has no prefix, it has no namespace.

An attribute without a prefix is in default namespaces.

If an attribute name has a prefix, its name is in the namespaces

indicated by the prefix.

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 11/14

Placing attributes in a namespaces

Syntax

Example

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 12/14

Default Namespaces

Defining a default namespace for an element saves us from usingprefixes in all the child elements.

Syntax: xmlns="URI "

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 13/14

Override default namespaces

The default namespaces applies to the element on which it wasdefined and all descendant of that elements

If one of the descendants has another default namespaces defineson it, this new namespace definition overrides the previous oneand become the default for that element and all its descendents.

7/30/2019 2. XML-Namespaces

http://slidepdf.com/reader/full/2-xml-namespaces 14/14

That’s all for today!  

XML Namespaces

Working with Namespaces Syntax

Thank you al l for yo ur at tent ion and pat ient !