Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2003 Pearson Education, Inc. Slide 5-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide.

Similar presentations


Presentation on theme: "Copyright © 2003 Pearson Education, Inc. Slide 5-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide."— Presentation transcript:

1

2 Copyright © 2003 Pearson Education, Inc. Slide 5-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide to XML by Cheryl M. Hughes

3 Copyright © 2003 Pearson Education, Inc. Slide 5-2 CHAPTER 5 Namespaces in XML

4 Copyright © 2003 Pearson Education, Inc. Slide 5-3 Overview of Namespaces A namespace is a group, or set, of element and attribute names that belong to or describe a document type Each name in a namespace must be unique within that namespace A naming collision occurs when an element name has two different meanings within a document XML namespaces are used to avoid naming collisions and to assign elements to different groupings within a document

5 Copyright © 2003 Pearson Education, Inc. Slide 5-4 Naming Collision Example 1 2 3 Introduction to XML 4 Jane Smith 5 Monday, 5:30-7:30 6 This course covers the basics of XML… 9 The Web Wizards Guide to XML 10 C Hughes 11 Addison Wesley 14 15

6 Copyright © 2003 Pearson Education, Inc. Slide 5-5 Namespace Syntax Namespaces must be declared before they are used Namespaces are declared on elements in the start tag Two types of namespace declarations: Default: xmlns=URI xmlns=http://www.w3c.org/1999/xlink Prefixed: xmlns:prefix=URI xmlns:xlink=http://www.w3c.org/1999/xlink Prefixed namespaces are referred to as qualified names Both default and prefixed declarations can exist within a single document

7 Copyright © 2003 Pearson Education, Inc. Slide 5-6 Uniform Resource Identifier (URI) URIs can take two forms: Uniform Resource Locator (URL) Example: http://www.w3c.org/1999/xlink Uniform Resource Name (URN) Example: urn:local.gov:book Either form of URI can be used with both default and prefixed namespaces

8 Copyright © 2003 Pearson Education, Inc. Slide 5-7 Scope of a Namespace The scope of a namespace determines which elements can belong to a namespace Namespace scope cannot ascend above the element it is declared on within the document hierarchy Namespaces can be declared on sibling and child elements of the element on which it is declared When namespaces are declared on elements outside of the proper hierarchy, and out-of- scope error occurs

9 Copyright © 2003 Pearson Education, Inc. Slide 5-8 Default Namespace Example 1 2 ACME Company Newsletter 3 4 Company Employees Participate in 5K Run 5 J. Fraser 6 7 July, 2001 8 All elements in this document belong to the http://chughes.com/firstnamespace namespace

10 Copyright © 2003 Pearson Education, Inc. Slide 5-9 Prefixed Namespace Example 1 2 ACME Company Newsletter 3 4 Company Employees Participate in 5K Run 5 J. Frasier 6 7 July, 2001 8 Only the and elements belong to the http://chughes.com/secondnamespace namespace because they include the prefix flag


Download ppt "Copyright © 2003 Pearson Education, Inc. Slide 5-1 Created by Cheryl M. Hughes, Harvard University Extension School Cambridge, MA The Web Wizards Guide."

Similar presentations


Ads by Google