对下面的schema :
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://data.library.j2c.test" xmlns:data="http://data.library.j2c.test">
<element name="getAuthorRequest" type="data:BookName"></element>
<complexType name="BookName">
<sequence minOccurs="1" maxOccurs="1">
<element name="Name" type="string"></element>
</sequence>
</complexType>
<element name="getAuthorResponse" type="data:AuthorName"></element>
<complexType name="AuthorName">
<sequence minOccurs="1" maxOccurs="1">
<element name="Name" type="string"></element>
</sequence>
</complexType>
</schema>
xmlns="http://www.w3.org/2001/XMLSchema" 表示默认的命名空间,element,complexType,sequence,schema属于此命名空间。
targetNamespace="http://data.library.j2c.test" 表示schema定义的元素的命名空间,包括BookName,AuthorName,这里,xmlns:data="http://data.library.j2c.test" 和targetNamespace相同,所以,当引用schema定义的元素时,使用data来标志命令空间。
对如下schema
<?xml version="1.0"?><note xmlns="http://www.w3schools.com"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.w3schools.com note.xsd">
<to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>
默认命名空间为xmlns=http://www.w3schools.com,to、from、heading、body、note来自该命令空间,这里, xsi:schemaLocation=http://www.w3schools.com note.xsd 指明了该命名空间来自note.xsd文件
include 用同一目标名称空间把多项schema添加到文件
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:bo="http://data.library.j2c.test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://data.library.j2c.test">
<xsd:annotation>
<xsd:appinfo source="wid.federated.schema"/>
</xsd:annotation>
<xsd:include schemaLocation="../test/j2c/library/TestName.xsd"/>
<xsd:include schemaLocation="../test/j2c/library/library.xsd"/>
</xsd:schema>
import 用不同的目标名称空间把多项schema添加到一份文件
<xsd:schema targetNamespace="http://tempuri.org/library/" xmlns:bons1="http://data.library.j2c.test" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://data.library.j2c.test" schemaLocation="../../../xsd-includes/http.data.library.j2c.test.xsd"/>
<xsd:element name="getAuthorResponse" type="bons1:AuthorName"/>
<xsd:element name="getAuthorRequest" type="bons1:BookName"/>
</xsd:schema>
参考:
http://www.w3pop.com/tech/school/schema/schema_elements_ref.asp
http://www.w3pop.com/tech/school/wsdl/default.asp
http://www-128.ibm.com/developerworks/cn/xml/theme/x-schema.html