XSD 个自定义命名空间
XSD custom namespaces
我开始玩XML和XSD;我有一个名为 narrative.xsd 的简单 xsd 文件和另一个名为 goal.xsd 的文件 其中包括叙述。
问题是在 goal.xsd 中对于 Timescale
类型我得到这个错误:
the http://mdmw.co.uk:Timescale is not declared.
如果我省略了名称空间,它就可以正常工作。
如何让它与名称空间一起使用?
提前致谢。
这是narrative.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="narrative"
elementFormDefault="qualified"
targetNamespace="http://mdmw.co.uk"
xmlns="http://mdmw.co.uk"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="Timescale">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="1 Month" />
<xs:enumeration value="2 Months" />
<xs:enumeration value="3 Months" />
<xs:enumeration value="6 Months" />
<xs:enumeration value="9 Months" />
<xs:enumeration value="1 Year" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
这是goal.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="goal"
elementFormDefault="qualified"
targetNamespace="http://mdmw.co.uk"
xmlns="http://mdmw.co.uk"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:include schemaLocation="narrative.xsd"/>
<xs:element name="goals">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="goalType" type="xs:string" />
<xs:element name="timeScale" type="Timescale" />
<xs:element name="currentResult" type="xs:decimal"/>
<xs:element name="currentResultDate" type="xs:date"/>
<xs:element name="comments" type="xs:string"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
timeScale
元素声明引用类型 Timescale
,但 Timescale
是一个元素,而不是类型。
如果 Timescale
元素内的匿名简单类型在 narrative.xsd 中变成具有此名称的顶级简单类型,错误应该消失.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="narrative"
elementFormDefault="qualified"
targetNamespace="http://mdmw.co.uk"
xmlns="http://mdmw.co.uk"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:simpleType name="Timescale">
<xs:restriction base="xs:string">
<xs:enumeration value="1 Month" />
<xs:enumeration value="2 Months" />
<xs:enumeration value="3 Months" />
<xs:enumeration value="6 Months" />
<xs:enumeration value="9 Months" />
<xs:enumeration value="1 Year" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
我开始玩XML和XSD;我有一个名为 narrative.xsd 的简单 xsd 文件和另一个名为 goal.xsd 的文件 其中包括叙述。
问题是在 goal.xsd 中对于 Timescale
类型我得到这个错误:
the http://mdmw.co.uk:Timescale is not declared.
如果我省略了名称空间,它就可以正常工作。
如何让它与名称空间一起使用?
提前致谢。
这是narrative.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="narrative"
elementFormDefault="qualified"
targetNamespace="http://mdmw.co.uk"
xmlns="http://mdmw.co.uk"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:element name="Timescale">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="1 Month" />
<xs:enumeration value="2 Months" />
<xs:enumeration value="3 Months" />
<xs:enumeration value="6 Months" />
<xs:enumeration value="9 Months" />
<xs:enumeration value="1 Year" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:schema>
这是goal.xsd:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="goal"
elementFormDefault="qualified"
targetNamespace="http://mdmw.co.uk"
xmlns="http://mdmw.co.uk"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:include schemaLocation="narrative.xsd"/>
<xs:element name="goals">
<xs:complexType>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="goalType" type="xs:string" />
<xs:element name="timeScale" type="Timescale" />
<xs:element name="currentResult" type="xs:decimal"/>
<xs:element name="currentResultDate" type="xs:date"/>
<xs:element name="comments" type="xs:string"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
timeScale
元素声明引用类型 Timescale
,但 Timescale
是一个元素,而不是类型。
如果 Timescale
元素内的匿名简单类型在 narrative.xsd 中变成具有此名称的顶级简单类型,错误应该消失.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="narrative"
elementFormDefault="qualified"
targetNamespace="http://mdmw.co.uk"
xmlns="http://mdmw.co.uk"
xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<xs:simpleType name="Timescale">
<xs:restriction base="xs:string">
<xs:enumeration value="1 Month" />
<xs:enumeration value="2 Months" />
<xs:enumeration value="3 Months" />
<xs:enumeration value="6 Months" />
<xs:enumeration value="9 Months" />
<xs:enumeration value="1 Year" />
</xs:restriction>
</xs:simpleType>
</xs:schema>