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

  • View
    225

  • Download
    4

Embed Size (px)

Text of Chapter 3: XML Namespaces. Chapter 3 Objectives Why you need namespaces What namespaces are,...

  • Slide 1

Chapter 3: XML Namespaces Slide 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 Slide 3 Why Do We Need Namespaces? Sir John Fitzgerald Johansen Doe Vice President of Marketing Resume of John Doe John Doe Johns a great guy, you know? Slide 4 Using Prefixes Sir John Fitzgerald Johansen Doe Vice President of Marketing Resume of John Doe John Doe Johns a great guy, you know? Slide 5 So Why Doesnt XML Just Use These Prefixes? Sir Slide 6 How XML Namespaces Work Sir Slide 7 Default Namespaces SirThis is XHTML Default except for the tag Default Slide 8 Declaring Namespaces on Descendants Example 1 This is XHTML Example 2 This is XHTML Slide 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 Slide 10 Canceling Default Namespaces Jane Doe Ive worked with Jane Doe for over a year now. Slide 11This 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"> 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 Slide 12 Namespaces and Attributes Example 1 Sir Example 2 Sir Slide 13 Try It Out Namespaces in Action Slide 14 What Exactly Are URIs? http://www.wileycom/default/home.htm ProtocolURI Slide 15 URNs urn:foo:a123,456 Examples Social security numbers Serial numbers NIC mac addresses Slide 16 Why Use URLs for Namespaces, Not URNs? Slide 17 RDDL Resource Directory Description Language Slide 18 When Should You Use Namespaces? Remember that a namespace is just a bag of namesthat is, its 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. Slide 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 Ive worked with Jane Doe for over a year now. Assuming that this document is for Wileys HR department, create a namespace for employees, and use it in this document. Be sure to keep the XHTML elements in their namespace. Slide 20 Exercise Questions Question 2 Imagine that Wiley has been going through the employee records and realized that they dont 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. Slide 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. Slide 22 Try It Out Adding XML Namespaces to Your Document Default Namespaces in Action Default Namespaces for Children Adding Attributes