Download presentation
Presentation is loading. Please wait.
Published byΚαλλιγένεια Αβραμίδης Modified over 5 years ago
1
CMP 051 XML Introduction Session IV Chapter 12 – XML Namespaces
Chapter 13 – Using Namespaces
2
Outline Name Conflicts Uniform Resource Identifier (URI)
Designing a Namespace Declaring a Default Namespace - The xmlns Attribute Solving the Name Conflict Using a Prefix Populating a XML Namespace Referencing XML Schema Components Locally Defined Elements Multiple Files Multiple Namespaces Schema of Schemas XSLT and Namespaces 8/1/2014 Copyright © Carl M. Burnett
3
Name Conflicts HTML Table XML
<table> <tr> <td>Apples</td> <td>Bananas</td> </tr> </table> <table> <name>African Coffee Table</name> <width>80</width> <length>120</length> </table> 8/1/2014 Copyright © Carl M. Burnett
4
Uniform Resource Identifier (URI)
URI - Uniform Resource Identifier URL - Uniform Resource Locator URN - Uniform Resource Name URL URN Directories File Name Domain Name Protocol 8/1/2014 Copyright © Carl M. Burnett
5
Designing a Namespace Use your own domain name Must be Unique
Must be Persistent Add Versioning Use a URL 8/1/2014 Copyright © Carl M. Burnett
6
Declaring a Default Namespace The xmlns Attribute
syntax. xmlns:prefix="URI". <course xmlns:” <course> <title>XML Intro </title> <CRN>35108</CRN> <dept> WDCE</dept> </course> 8/1/2014 Copyright © Carl M. Burnett
7
Solving the Name Conflict Using a Prefix
<root xmlns:h=" xmlns:f=" <h:table> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table> <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> <root> <h:table xmlns:h=" <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table> <f:table xmlns:f=" <f:name>African Coffee Table</f:name> <f:width>80</f:width> <f:length>120</f:length> </f:table> </root> 8/1/2014 Copyright © Carl M. Burnett
8
Populating a XML Namespace
XSD <?xml version="1.0"?> <xs:schema xmlns:xs=" targetNamespace=" <xs:element name="ancient_wonders"> <xs:complexType> <xs:sequence> <xs:element name="wonder" type="wonderType" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="wonderType"> <xs:element name="name" type="nameType" <xs:element name="location" type="xs:string"/> <xs:element name="height" type="heightType"/> 8/1/2014 Copyright © Carl M. Burnett
9
XML Schema and Documents
<?xml version="1.0"?> <ancient_wonders xmlns=" xmlns:xsi=" xsi:schemaLocation=" xsd"> <wonder> <name language="English">Colossus of Rhodes</name> <name language="Greek">Κολοσσός της Ρόδου</name> <location>Rhodes, Greece</location> <height units="feet">107</height> <history> <year_built era="BC">282</year_built> <year_destroyed era="BC">226</year_destroyed> <how_destroyed>earthquake</how_destroyed> 8/1/2014 Copyright © Carl M. Burnett
10
Referencing XML Schema Components
To declare a default Namespace for XML Schema Components xmlns=“URI” To declare a Namespace with a prefix for XML Schema Components xmlns:prefix=“URI” To then reference those component in the XML Schema Prefix:component_name 8/1/2014 Copyright © Carl M. Burnett
11
Locally Defined Elements
To add all locally defined elements to the targeted Namespace In the xs:schema element elementFormDefault=”qualified” To add all locally defined attributes to the targeted Namespace In the xs:schema element attributeFormDefault=”qualified” 8/1/2014 Copyright © Carl M. Burnett
12
Locally Defined Elements
To add all particular locally defined element to the targeted Namespace In the element definition form=”qualified” To keep a particular locally all locally defined element from being associated with the targeted Namespace In the element definition form=”unqualified” 8/1/2014 Copyright © Carl M. Burnett
13
Multiple Files To include XML Schema components in multiple files
Directly after the xs:schema element add: <xs:includeschemaLocation=”includefile.uri”/> 8/1/2014 Copyright © Carl M. Burnett
14
Multiple Namespaces To import components from XML Schemas with different target namespaces Directly after the xs:schema element in the imported document add: <xs:inport namespace=“URI” schemaLocation=”schema.uri”/> 8/1/2014 Copyright © Carl M. Burnett
15
Schema of Schemas To declare the Schema of Schemas as the default namespace: After the XML Declaration: <schema xmlns=“ Continue to identify target namespaces, then end the shema declaration tag with a > Copyright © Carl M. Burnett 8/1/2014
16
XSLT and Namespaces To use a XML namespace in an XSLT style sheet:
Within the opening tag of the root element xsl:stylesheet type: xmlns:prefix=“URI” Label individual elements by typing: <prefix:element> 8/1/2014 Copyright © Carl M. Burnett
17
Review Name Conflicts Uniform Resource Identifier (URI)
Designing a Namespace Declaring a Default Namespace - The xmlns Attribute Solving the Name Conflict Using a Prefix Populating a XML Namespace Referencing XML Schema Components Locally Defined Elements Multiple Files Multiple Namespaces Schema of Schemas XSLT and Namespaces Next – Chapter 16 – XQuery 1.0 8/1/2014 Copyright © Carl M. Burnett
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.