为了简单起见,我想在同一个命名空间中有一组文件,因为它们在概念上是相关的。我有一个主要或中心的xsd,将包含其他模式文件,基本上作为全局根元素。我的问题是最好的例子说明,但我基本上不能让我的非中心架构验证,这是一个命名空间的问题:如何创建同名命名空间设计一致的XSD?
模式1(支持):
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns="http://www.person.org"
elementFormDefault="qualified">
<xsd:simpleType name="test">
<xsd:restriction base="xsd:string">
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="PersonType">
<xsd:sequence>
<xsd:element name="Name" type="test" />
<xsd:element name="SSN" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
模式2(中心):
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.company.org"
xmlns="http://www.company.org"
elementFormDefault="qualified">
<xsd:include schemaLocation="http://www.person.org"/>
<xsd:element name="Company">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Person" type="PersonType"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
模式2很好,模式1不验证。 “test”没有命名空间,我不知道如何在不破坏我的意图的情况下为我的所有文件使用1个命名空间。