- (source) namespace is like package declaration in java i.e.
package com.exampl
, used in schema creation.
- targetNamespace is like package import in java, this is generally use for re-using one schema inside another schema.
targetNamespace is an XML Schema "artifact".User-defined data types may have possibility of name clashes when we work with different team. This an attribute of schema
element defines namespace i.e. package. By convention we use URI/URLs, but we could use any string..
<?xml version="1.0" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="namespace">
...
</xs:schema>
for example:
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/beans/spring-mvc.xsd" xmlns:mvc="http://www.springframework.org/schema/mvc"
// or if the schema exist in current directory we can declare as follows
xsi:schemaLocation="http://www.springframework.org/schema/mvc spring-mvc.xsd" xmlns:mvc="http://www.springframework.org/schema/mvc"
//for import xml schema
<xsd:import schemaLocation="http://localhost:9999/ws/hello?xsd=1" namespace="http://ws.peter.com/"/>
Note: xsi:schemaLocation
mean the namespace and URL are separated with whitespace. And xmlns:mvc
mean the namespace http://www.springframework.org/schema/mvc
define as mvc
alias.
namespace analogy:
+---------+--------------------------------------------------------+------------------------------+------------------------+
| Context | Name | Namespace identifier | Local name |
+---------+--------------------------------------------------------+------------------------------+------------------------+
| Path | /home/user/readme.txt | /home/user (path) | readme.txt (file name) |
| XML | xmlns:xhtml="http://www.w3.org/1999/xhtml"<xhtml:body> | http://www.w3.org/1999/xhtml | body |
| Java | java.util.Date | java.util | Date |
+---------+--------------------------------------------------------+------------------------------+------------------------+
for more details