CSE3201 XML Namespace
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 Example Dandenong Rd Caulfield East Victoria Australia 3145 aWebServer
4 Example Computer Science Dandenong Rd Caulfield East Victoria Australia aWebServer
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 (
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. Default namespace xmlns=URI or URL Target namespace xmlns:prefix=URI or URL Namespace can be used in XML instance, DTD, Schema, XSLT.
7 Namespace in XML Schema <schema xmlns=“ xlmns:addr=“ targetNamespace:=“ elementFormDefault=“unqualified” attributeFormDefault=“unqualified”>
8 XML Instance <adept:department xsi:schemaLocation=" file:namespaceUnqualified.xsd" xmlns:adept=" xmlns:xsi=" 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 Qualified Elements/Attributes <schema xmlns=“ xlmns:addr=“ targetNamespace:=“ elementFormDefault=“qualified” attributeFormDefault=“unqualified”>
10 Qualified – XML Instance Explicit used of namespace. <adept:department xsi:schemaLocation=" file:namespaceQualified.xsd" xmlns:adept=" xmlns:xsi=" Computer Science 900 Dandenong Rd Caulfield East Victoria Australia
11 Qualified – XML Instance Implicit used of namespace => default namespace <department xsi:schemaLocation=" file:namespaceQualified.xsd" xmlns=" xmlns:xsi=" CSSE 900 Dandenong Rd Caulfield East Victoria Australia
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 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 Examples Check the bottom.xsd, department.xsd, server.xsd and faculty.xsd.
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 Example See the newFaculty.xsd