Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 3: XML Namespaces. Chapter 3 Objectives Why you need namespaces What namespaces are, conceptually and how they solve the problem of naming clashes.

Similar presentations


Presentation on theme: "Chapter 3: XML Namespaces. Chapter 3 Objectives Why you need namespaces What namespaces are, conceptually and how they solve the problem of naming clashes."— Presentation transcript:

1 Chapter 3: XML Namespaces

2 Chapter 3 Objectives Why you need namespaces What namespaces are, conceptually and how they solve the problem of naming clashes The syntax for using namespaces in XML documents What is a URI, URL, and URN

3 Why Do We Need Namespaces? Sir John Fitzgerald Johansen Doe Vice President of Marketing Resume of John Doe John Doe John’s a great guy, you know?

4 Using Prefixes Sir John Fitzgerald Johansen Doe Vice President of Marketing Resume of John Doe John Doe John’s a great guy, you know?

5 So Why Doesn’t XML Just Use These Prefixes? Sir

6 How XML Namespaces Work Sir

7 Default Namespaces Sir This is XHTML Default except for the tag Default

8 Declaring Namespaces on Descendants Example 1 This is XHTML Example 2 This is XHTML

9 Namespaces Look at Example 1 on p 73 of the book. Then look at example 1 on p 79 Both documents have the same semantic content

10 Canceling Default Namespaces Jane Doe I’ve worked with Jane Doe for over a year now.

11 Do Different Notations Make Any Difference? You can fully qualify every name, like this: This is XHTML Or, you can use one namespace as the default, and just qualify any names from other namespaces, like this: This is XHTML Or, you can just use defaults everywhere, like this: This is XHTML

12 Namespaces and Attributes Example 1 Sir Example 2 Sir

13 Try It Out Namespaces in Action

14 What Exactly Are URIs? ProtocolURI

15 URNs urn:foo:a123,456 Examples Social security numbers Serial numbers NIC mac addresses

16 Why Use URLs for Namespaces, Not URNs?

17 RDDL Resource Directory Description Language

18 When Should You Use Namespaces? Remember that a namespace is just a “bag of names”—that is, it’s a group of element names that belong together, and that are distinct from element names in other namespaces. The key is the phrase belong together.

19 Exercise Questions Question 1 In this chapter you saw the following XML document, in which you had to cancel the default namespace: Jane Doe I’ve worked with Jane Doe for over a year now. Assuming that this document is for Wiley’s HR department, create a namespace for employees, and use it in this document. Be sure to keep the XHTML elements in their namespace.

20 Exercise Questions Question 2 Imagine that Wiley has been going through the employee records and realized that they don’t have a good unique way to identify each employee. Create a global id attribute that can be attached to any XML element in the employee namespace you created earlier. Put this attribute into effect by modifying the XML you created in Question 1, and marking the Jane Doe employee as employee number x125.

21 Exercise Questions Question 3 Create a new XML file for an employee named Alfred Neuman, with employee number x393. In the notes for Alfred mention that he has worked closely with Jane Doe, being sure to use the element to refer to her.

22 Try It Out Adding XML Namespaces to Your Document Default Namespaces in Action Default Namespaces for Children Adding Attributes


Download ppt "Chapter 3: XML Namespaces. Chapter 3 Objectives Why you need namespaces What namespaces are, conceptually and how they solve the problem of naming clashes."

Similar presentations


Ads by Google