Namespaces are used to avoid name conflicts through the use of prefixes.
In an XML they are usually defined in the main tag:
<?xml version="1.0" encoding="ISO-8859-1"?> <ord:order xmlns:ord="http://davisfiore.co.uk/xml/orders" xmlns:prod="http://davisfiore.co.uk/xml/products" xmlns="http://davisfiore.co.uk/xml/base" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://davisfiore.co.uk/xml/products products.xsd http://davisfiore.co.uk/xml/orders orders.xsd http://davisfiore.co.uk/xml/base base.xsd">
The xmlns:xxx=URI attribute defines the name of a namespace.
xmlns=URI defines the default namespace.
Note that the URI is not used to retrieve information but to give a unique name.
xsi:schemaLocation tells where to find the XSD. The pairs of values represent the namespace and the schema definition path.
This is the first section of the schema definition orders.xsd:
<?xml version="1.0" encoding="ISO-8859-1"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://davisfiore.co.uk/xml/orders" xmlns="http://davisfiore.co.uk/xml/orders" xmlns:prod="http://davisfiore.co.uk/xml/products" elementFormDefault="qualified">
targetNamespace specifies which namespace the elements defined come from.
elementFormDefault="qualified" indicates that the elements defined must be namespace qualified.
Note that the targetNamespace in the xsd must be compliant with the default xmlns defined in the xml.
noNamespaceSchemaLocation can be used to reference XSD not defined in a target-namespace.
xsi:noNamespaceSchemaLocation="orders.xsd">
Copyright © 2013 Welcome to the website of Davis Fiore. All Rights Reserved.