我有一個XML模式schema.xsd
與外部文件types.xsd
中的自定義類型。我不知道爲什麼我的複雜類型typeComplex
未正確驗證。簡單的類型,如typeSimple
工作正常。那有什麼不對?XSD:導入複雜類型不起作用
Eclipse中說:
CVC-複雜type.2.4.a:無效的含量被發現開始 元素a。預計會有'{「http://www.example.org/types":a}'之一。
schema.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/schema" elementFormDefault="qualified"
xmlns:t="http://www.example.org/types">
<xs:import schemaLocation="types.xsd" namespace="http://www.example.org/types" />
<xs:element name="root">
<xs:complexType>
<xs:all>
<xs:element name="simple" type="t:typeSimple" />
<xs:element name="complex" type="t:typeComplex" />
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
types.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/types" xmlns="http://www.example.org/types"
elementFormDefault="qualified">
<xs:simpleType name="typeSimple">
<xs:restriction base="xs:string">
<xs:length value="3" />
</xs:restriction>
</xs:simpleType>
<xs:complexType name="typeComplex">
<xs:sequence>
<xs:element name="a" type="xs:string" />
<xs:element name="b" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
text.xml - 不得與XSD - 爲什麼?
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.example.org/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.example.org/schema schema.xsd " xmlns:t="http://www.example.org/types">
<simple>XXX</simple>
<complex>
<a></a> <!-- not valid here; Eclipse say: cvc-complex-type.2.4.a: Invalid content was found starting with element 'a'. One of '{"http://www.example.org/types":a}' is expected. -->
<b></b>
</complex>
</root>
它可以在不使用'噸的做什麼?我需要驗證的XML將在一個名稱空間。 – marioosh 2012-04-26 11:24:34
如果您想使用來自導入的名稱空間的類型,請不要使用它。看到我的更新... – 2012-04-26 13:51:52