Presentation is loading. Please wait.

Presentation is loading. Please wait.

XML Namespaces Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University.

Similar presentations


Presentation on theme: "XML Namespaces Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University."— Presentation transcript:

1 XML Namespaces Kanda Runapongsa (krunapon@kku.ac.th)krunapon@kku.ac.th Dept. of Computer Engineering Khon Kaen University

2 168493: XML and Web Services (II/2546) 2 What are Namespaces? Namespaces are a simple and straightforward way to distinguish names used in XML documents, no matter where they come from [W3C Definition] An XML namespace is a collection of names, identified by a URI reference, which are used in XML documents as element types and attribute names. element typesattribute names

3 168493: XML and Web Services (II/2546) 3 Book Review XML

4 168493: XML and Web Services (II/2546) 4 Namespaces by Example In the example, the elements prefixed with xdc are associated with a namespace whose name is http://abc.com/books http://abc.com/books Those prefixed with h are associated with a namespace whose name is http://www.w3.org/HTML

5 168493: XML and Web Services (II/2546) 5 Prefixes Prefixes are linked to the full names using the attributes on the top element whose names begin xmlns: Prefixes are just shorthand placeholders for the full names The full names are URLs, i.e. Web addresses

6 168493: XML and Web Services (II/2546) 6 Why Namespaces? Book-review tags and HTML tags are all mixed up together Need to be sure that we’re finding the book titles, not the HTML page titles Can be done by processing only tags that are in the http://abc.com/books namespace http://abc.com/books

7 168493: XML and Web Services (II/2546) 7 Namespace Defaulting Previously, we have all those prefixes and colons cluttering up the tags We can declare a default namespace and leave out some prefixes Anything without a prefix is assumed to be in the default namespace A default namespace is considered to apply to the element where it is declared and to all elements with no prefix

8 168493: XML and Web Services (II/2546) 8 <html xmlns:xdc="http://abc.com/books" xmlns="http://www.w3.org/HTML"> Book Review XML

9 168493: XML and Web Services (II/2546) 9 Namespace Defaulting (Cont.) The default namespace can be set to the empty string This has the same effect as having no default namespace Note that default namespaces do not apply directly to attributes

10 168493: XML and Web Services (II/2546) 10 Default Namespaces Name Huntsman …

11 168493: XML and Web Services (II/2546) 11 Attributes: Example 1 http://www.w3.org Is the start tag of e1 legal? Is the start tag of e2 legal?

12 168493: XML and Web Services (II/2546) 12 Attributes: Example 2 Is the start tag of e3 legal? Is the start tag of e4 legal?


Download ppt "XML Namespaces Kanda Runapongsa Dept. of Computer Engineering Khon Kaen University."

Similar presentations


Ads by Google