Presentation is loading. Please wait.

Presentation is loading. Please wait.

Beginning XML 4th Edition. Chapter 3: XML Namespaces.

Similar presentations


Presentation on theme: "Beginning XML 4th Edition. Chapter 3: XML Namespaces."— Presentation transcript:

1 Beginning XML 4th Edition

2 Chapter 3: XML Namespaces

3 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

4 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?

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

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

7 How XML Namespaces Work Sir

8 Try It Out Adding XML Namespaces to Your Document

9 Default Namespaces Sir <person xmlns=“http://www.wiley.com/pers” xmlns:xhtml=“http://www.w3.org/1999/xhtml”> This is XHTML Default except for the tag Default

10 Try It Out Default Namespaces in Action

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

12 Try It Out Default Namespaces for Children

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

14 Do Different Notations Make Any Difference? You can fully qualify every name, like this: <pers:person xmlns:pers="http://www.wiley.com/pers" xmlns:xhtml="http://www.w3.org/1999/xhtml"> This is XHTML Or, you can use one namespace as the default, and just qualify any names from other namespaces, like this: <person xmlns="http://www.wiley.com/pers" xmlns:xhtml="http://www.w3.org/1999/xhtml"> This is XHTML Or, you can just use defaults everywhere, like this: This is XHTML

15 Do Different Notations Make Any Difference?

16 Namespaces and Attributes Example 1 Sir Example 2 Sir

17 Namespaces and Attributes Do namespaces work the same for attributes as they do for elements?

18 Try It Out Adding Attributes

19 What Exactly Are URIs? http://www.wileycom/default/home.htm ProtocolURI

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

21 Why Use URLs for Namespaces, Not URNs?

22

23 RDDL Resource Directory Description Language

24 When Should You Use Namespaces?

25 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.

26 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.

27 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.

28 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.

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


Download ppt "Beginning XML 4th Edition. Chapter 3: XML Namespaces."

Similar presentations


Ads by Google