Download presentation
Presentation is loading. Please wait.
Published byWilfred Grant Modified over 9 years ago
1
www.monash.edu.au CSE3201 XML Namespace
2
www.monash.edu.au 2 What is a namespace? An XML namespace is a collection of element type and attribute names. It defines a way to distinguish between duplicate element type and attribute names.
3
www.monash.edu.au 3 Example Dandenong Rd Caulfield East Victoria Australia 3145 aWebServer 130.194.225.1
4
www.monash.edu.au 4 Example Computer Science http://www.csse.monash.edu.au/xml/address Dandenong Rd Caulfield East Victoria Australia 3145 http://www.csse.monash.edu.au/xml/servers aWebServer 130.194.225.1
5
www.monash.edu.au 5 The Purpose of Namespace Combine fragments from different document without naming conflict. Write reusable code modules that can be invoked for specific elements and attributes. Universally unique names guarantee that such modules are invoked only for the correct elements and attributes. Define elements and attributes that can be re-used in a number of different schema or instance document without naming conflict XML Namespace FAQ (http://www.)
6
www.monash.edu.au 6 Declaring a Namespace A namespace is declared using the xmlns attribute. The value of the attribute is the name of the namespace being declared. http://www.csse.monash.edu.au/xml/address Default namespace xmlns=URI or URL Target namespace xmlns:prefix=URI or URL Namespace can be used in XML instance, DTD, Schema, XSLT.
7
www.monash.edu.au 7 Namespace in XML Schema <schema xmlns=“http://www.w3.org/2001/XMLSchema”http://www.w3.org/2001/XMLSchema xlmns:addr=“http://www.csse.monash.edu.au/xml/address”http://www.csse.monash.edu.au/xml/address targetNamespace:=“http://www.csse.monash.edu.au/xml/address”http://www.csse.monash.edu.au/xml/address elementFormDefault=“unqualified” attributeFormDefault=“unqualified”>
8
www.monash.edu.au 8 XML Instance <adept:department xsi:schemaLocation="http://www.csse.monash.edu.au/xml/address file:namespaceUnqualified.xsd" xmlns:adept="http://www.csse.monash.edu.au/xml/address" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> CSSE 900 Dandenong Rd Caulfield East Victoria Australia The prefix “adept” is applied only to the global element as the schema is declared with unqualified elements and attributes.
9
www.monash.edu.au 9 Qualified Elements/Attributes <schema xmlns=“http://www.w3.org/2001/XMLSchema”http://www.w3.org/2001/XMLSchema xlmns:addr=“http://www.csse.monash.edu.au/xml/address”http://www.csse.monash.edu.au/xml/address targetNamespace:=“http://www.csse.monash.edu.au/xml/address”http://www.csse.monash.edu.au/xml/address elementFormDefault=“qualified” attributeFormDefault=“unqualified”>
10
www.monash.edu.au 10 Qualified – XML Instance Explicit used of namespace. <adept:department xsi:schemaLocation="http://www.csse.monash.edu.au/xml/address file:namespaceQualified.xsd" xmlns:adept="http://www.csse.monash.edu.au/xml/address" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> Computer Science 900 Dandenong Rd Caulfield East Victoria Australia
11
www.monash.edu.au 11 Qualified – XML Instance Implicit used of namespace => default namespace <department xsi:schemaLocation="http://www.csse.monash.edu.au/xml/address file:namespaceQualified.xsd" xmlns="http://www.csse.monash.edu.au/xml/address" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> CSSE 900 Dandenong Rd Caulfield East Victoria Australia
12
www.monash.edu.au 12 Multiple Schemas It is sometime desirable to divide the schema into a number of small parts when a schema is large. The division will help: –Maintenance –Readability –Access control
13
www.monash.edu.au 13 Include Two or more schemas from the same namespace can be combined using the include declaration. All the included parts of the schema have to declared with the same target namespace.
14
www.monash.edu.au 14 Examples Check the bottom.xsd, department.xsd, server.xsd and faculty.xsd.
15
www.monash.edu.au 15 Import The import declaration can be used to combine two or more schemas from different namespaces. Only global elements and named Types can be imported.
16
www.monash.edu.au 16 Example See the newFaculty.xsd
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.