下面的代码在验证过程中给出了以下错误。这是否意味着我不能在simpleType元素中嵌套complexType元素?
Error - Line 18, 17: org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 17; s4s-elt-must-match.1: The content of 'sequence' must match (annotation?, (element | group | choice | sequence | any)*). A problem was found starting at: simpleType.
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/carType"
elementFormDefault="qualified">
<element name="carType">
<complexType>
<sequence>
<simpleType name="colour">
<restriction base="string">
<enumeration value="blue" />
<enumeration value="yellow" />
<enumeration value="green" />
<enumeration value="black" />
<enumeration value="white" />
</restriction>
</simpleType>
<simpleType name="body">
<restriction base="string">
<enumeration value="sedan" />
<enumeration value="hatchback" />
</restriction>
</simpleType>
</sequence>
</complexType>
</element>
</schema>发布于 2014-12-01 21:56:15
,你快到了。只需对XSD做两个小的调整:
<simpleType name="colour">的地方,应该声明一个colour元素:
<simpleType name="body">的地方,可以声明一个body元素:
那么,总共是:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/carType"
elementFormDefault="qualified">
<element name="carType">
<complexType>
<sequence>
<element name="colour">
<simpleType>
<restriction base="string">
<enumeration value="blue" />
<enumeration value="yellow" />
<enumeration value="green" />
<enumeration value="black" />
<enumeration value="white" />
</restriction>
</simpleType>
</element>
<element name="body">
<simpleType>
<restriction base="string">
<enumeration value="sedan" />
<enumeration value="hatchback" />
</restriction>
</simpleType>
</element>
</sequence>
</complexType>
</element>
</schema>https://stackoverflow.com/questions/27237607
复制相似问题