我知道我已多次发布此问题。但我现在得到一个新的错误,我需要帮助。这是我收到的错误。 “s4s-elt-invalid-content.1:'#Annode_orders'的内容无效。元素'元素'无效,放错位置或过于频繁发生。”
这是我的xsd文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="reach">
<xs:restriction base = "xs:integer">
<xs:enumeration value = "50" />
<xs:enumeration value = "75" />
<xs:enumeration value = "100" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name = "language">
<xs:restriction base = "xs: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:simpleType name="caseColor">
<xs:restriction base="xs:string">
<xs:enumeration value="Lemonde" />
<xs:enumeration value="Strawberry" />
<xs:enumeration value="Lime" />
<xs:enumeration value="Blueberry" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="numOfBat">
<xs:restriction base="xs:integer">
<xs:enumeration value="1" />
<xs:enumeration value="2" />
<xs:enumeration value="3" />
<xs:enumeration value="4" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="numOfCam">
<xs:restriction base="xs:string">
<xs:pattern value="1|2" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="volt">
<xs:restriction base="xs:string">
<xs:enumeration value="110-120" />
<xs:enumeration value="220-240" />
</xs:restriction>
</xs:simpleType>
<xs:element name="orders">
<xs:complexType>
<xs:element name ="order" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="custName" type ="xs:string" />
<xs:attribute name ="custID" />
<xs:element name="case" type="xs:caseColor" >
</xs:element>
<xs:element name="batteries" type="xs:numOfBat" default =
"1">
</xs:element>
<xs:element name="recharger" type="xs:volt" />
<xs:element name="arm">
<xs:element name ="reaches" minOccurs="2" maxOccurs="3"
type="xs:reach" />
</xs:element>
<xs:element name ="camera" type="xs:numOfCam" />
<xs:element name = "speech" type="xs:language" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:complexType>
</xs:element>
</xs:schema>
这是我的xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<orders>
<order>
<custName custID="11223"> John Doe </custName>
<case> Strawberry </case>
<batteries> 2 </batteries>
<recharger> 110-120 V </recharger>
<arm>
<reach> 50 </reach>
<reach> 100 </reach>
</arm>
<camera> 2 </camera>
<speech> Spanish </speech>
</order>
<order>
<custName custID="45392"> Jane Camp </custName>
<case> Lime </case>
<batteries> 4 </batteries>
<recharger> 220-240 V </recharger>
<arm> 3
<reach> 75 </reach>
<reach> 75 </reach>
<reach> 100 </reach>
</arm>
<camera> 1 </camera>
<speech> Chinese </speech>
</order>
<order>
<custName custID="69482"> George Carlton </custName>
<case> Blueberry </case>
<batteries> 1 </batteries>
<recharger> 110-120 V </recharger>
<arm>
<reach> 75 </reach>
<reach> 100 </reach>
</arm>
<camera> 2 </camera>
<speech> French </speech>
</order>
</orders>
答案 0 :(得分:3)
您的xsd
格式不正确,特别是您的orders
元素。您还引用了自定义类型的错误命名空间。我会解决我看到的问题。
首先:您的orders
节点被定义为xs:complexType
,并且您有一个order
元素作为complexType
的子元素,但元素不是允许的子节点。您需要将xs:sequence
或xs:all
置于其间:
<xs:element name="orders">
<xs:complexType>
<xs:sequence>
<xs:element name ="order" maxOccurs="unbounded">
<!-- existing nodes -->
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
下一步:您的arm
元素有1个子元素,但在此上下文中不允许xs:element
。您需要将其定义为complexType
,然后再将sequence
或all
定义为。{/ p>
<xs:element name="arm">
<xs:complexType>
<xs:sequence>
<xs:element name ="reaches" minOccurs="2" maxOccurs="3" type="reach" />
</xs:sequence>
</xs:complexType>
</xs:element>
第三:您的custId
属性未在正确的位置定义。必须将xs:attributes
定义为将其定义为属性的元素下的子节点,但xs:simpleType不能具有属性节点,因此您需要将其定义为complexType。以下是您的问题的可能解决方案:
<xs:element name="custName">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="custID" type="xs:int" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
最后:当您引用所有自定义类型(reach
,numOfBat
,volt
等)时,您将它们作为xs:
命名空间的一部分引用但是,xs:
命名空间中未定义这些类型。由于您没有为XSD定义targetNamespace,因此您的自定义类型将成为默认命名空间的一部分。您只需要从类型中删除xs:
即可。
例如,您应该声明它们:type="reach"
,type="numOfBat"
,type="caseColor"
等
答案 1 :(得分:0)
我不知道你使用什么工具进行验证,但它产生的信息似乎相当无益。有关信息,以下是Saxon生成的消息:
Saxon-EE 9.5.0.1J from Saxonica
Java version 1.6.0_27
Using license serial number M008277
Loading schema document file:/Users/mike/Desktop/temp/test.xsd
Error at xs:element on line 48 column 49 of test.xsd:
Element xs:element cannot appear here: expected one of {choice, sequence, assert,
openContent, annotation, attributeGroup, anyAttribute, simpleContent, all, attribute,
group, complexContent}
Error at xs:attribute on line 52 column 48 of test.xsd:
Element <xs:attribute> is not allowed as a child of <xs:sequence>
Error at xs:element on line 61 column 19 of test.xsd:
Element xs:element cannot appear here: expected one of {annotation, simpleType, key,
complexType, keyref, unique, alternative}
Error at xs:element on line 61 column 19 of test.xsd:
Element <xs:element> is not allowed as a child of <xs:element>
Schema processing failed: 4 errors were found while processing the schema
我希望你能更清楚地发现这些。本质上,问题是xs:element不能作为xs:complexType的子项出现:你可能需要像xs:sequence之类的东西。