我正在尝试使用 xml 模式验证器,但我收到一条错误消息,提示“文件过早结束”,我似乎无法找到此错误的位置。这是我的 xsd 文件
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="orders">
<xs:element name ="order" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="case" type="xs:caseColor" >
<xs:simpleType name="caseColor">
<xs:restriction base="string">
<xs:enumeration value="Lemonde" />
<xs:enumeration value="Strawberry" />
<xs:enumeration value="Lime" />
<xs:enumeration value="Blueberry" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="batteries" type="xs:numOfBat" default =
"1">
<xs:simpleType name="numOfBat">
<xs:restriction base="integer">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
<xs:enumeration value="4" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="recharger" type="xs:volt">
<xs:simpleType name="volt">
<xs:restriction base="string">
<xs:enumeration value="110-120" />
<xs:enumeration value="220-240" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="arm">
<xs:element name ="reaches" minOccurs="2" maxOccurs="3"
type="xs:reach">
<xs:simpleType name="reach">
<xs:restriction base = "integer">
<xs:enumeration value = "50" />
<xs:enumeration value = "75" />
<xs:enumeration value = "100" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:element>
<xs:element name ="camera" type="numOfCam">
<xs:simpleType name="numOfCam">
<xs:restriction base="string">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name = "speech" type="xs:language">
<xs:simpleType name = "language">
<xs:restriction base = "string">
<xs:enumeration value = "Spanish" />
<xs:enumeration value = "Chinese" />
<xs:enumeration value = "English" />
<xs:enumeration value = "German" />
<xs:enumeration value = "French" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:element>
</xs:schema>
并且错误的位置说它在-1,-1行。
这是我的 dtd 文件以防万一
<?xml version="1.0"?>
<!DOCTYPE orders [
<!ELEMENT orders (order+)>
<!ELEMENT order (case, batteries, recharger, arm, camera,
speech)>
<!ELEMENT case (#PCDATA)>
<!ELEMENT batteries (#PCDATA)>
<!ELEMENT recharger (#PCDATA)>
<!ELEMENT arm (reach)>
<!ELEMENT reach (#PCDATA)>
<!ELEMENT camera (#PCDATA)>
<!ELEMENT speech (#PCDATA)>
]>
并且错误没有说明错误来自哪个文件。这是我正在使用的验证器。http://corefiling.com/opensource/schemaValidate.html
我想因为我不能使用我的 dtd,所以这是我的 xml 文件。
<?xml version="1.0" encoding="UTF-8"?>
<orders>
<order>
<case> Strawberry </case>
<batteries> 2 </batteries>
<recharger> 110-120 V </recharger>
<arm> 2
<length> 50 </length>
<length> 100 </length>
</arm>
<camera> 2 </camera>
<speech> Spanish </speech>
</order>
<order>
<case> Lime </case>
<batteries> 4 </batteries>
<recharger> 220-240 V </recharger>
<arm> 3
<length> 75 </length>
<length> 75 </length>
<length> 100 </length>
</arm>
<camera> 1 </camera>
<speech> Chinese </speech>
</order>
<order>
<case> Blueberry </case>
<batteries> 1 </batteries>
<recharger> 110-120 V </recharger>
<arm> 2
<length> 75 </length>
<length> 100 </length>
</arm>
<camera> 2 </camera>
<speech> French </speech>
</order>
</orders>