我有两个似乎无法解决的错误,也找不到适合我特定情况的解决方案...
所以我有错误:
s4s-elt-invalid-content.1:“ enginecapacityType”的内容无效。元素“限制”无效,放错位置或发生的次数过多。
s4s-elt-invalid-content.1:“ enginepowerType”的内容无效。元素“限制”无效,放错位置或发生的次数过多。
我的代码在下面。
能否请您帮我解决问题并解释为什么会发生?谢谢。
XSD文件:
<xsd:element name="carCollection">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="personalData" type="personalDataType" maxOccurs="1"/>
<xsd:element name="copyright"/>
<xsd:element name="car" type="carType" minOccurs="10" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="personalDataType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string" minOccurs="1" maxOccurs="2"/>
<xsd:element name="surname" type="xsd:string"/>
<xsd:element name="sex" type="sexType"/>
<xsd:element name="age" type="xsd:anyType"/>
<xsd:element name="city" type="xsd:anyType"/>
<xsd:element name="specialization" type="xsd:anyType"/>
<xsd:element name="group" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="sexType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="male"/>
<xsd:enumeration value="female"/>
</xsd:restriction>
</xsd:complexType>
<xsd:complexType name="carType">
<xsd:sequence>
<xsd:element name="brand" type="BrandType"/>
<xsd:element name="model" type="modelType"/>
<xsd:element name="enginecapacity" type="enginecapacityType"/>
<xsd:element name="color" type="colorType"/>
<xsd:element name="enginepower" type="enginepowerType"/>
<xsd:element name="production_year" type="production_yearType"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="BrandType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="BMW"/>
<xsd:enumeration value="Audi"/>
<xsd:enumeration value="Skoda"/>
<xsd:enumeration value="Citroen"/>
<xsd:enumeration value="Fiat"/>
<xsd:enumeration value="Kia"/>
<xsd:enumeration value="Focus"/>
<xsd:enumeration value="Skoda"/>
<xsd:enumeration value="Toyota"/>
<xsd:enumeration value="Lexus"/>
<xsd:enumeration value="Ford"/>
</xsd:restriction>
</xsd:complexType>
<xsd:complexType name="modelType">
<xsd:restriction base="xsd:string">
<xsd:minLength value="0"/>
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:complexType>
<xsd:simpleType name="enginecapacityType">
<xsd:simpleContent>
<xsd:restriction base="xsd:decimal">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="5.0"/>
</xsd:restriction>
</xsd:simpleContent>
</xsd:simpleType>
<xsd:complexType name="colorType">
<xsd:simpleContent>
<xsd:extension base="xsd:string">
<xsd:attribute name="tone" type="toneType"/>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:simpleType name="enginepowerType">
<xsd:simpleContent>
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="300"/>
</xsd:restriction>
</xsd:simpleContent>
</xsd:simpleType>
<xsd:complexType name="production_yearType">
<xsd:restriction base="xsd:integer">
<xsd:minInclusive value="1990"/>
<xsd:maxInclusive value="2018"/>
</xsd:restriction>
</xsd:complexType>
<xsd:complexType name="toneType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="mat"/>
<xsd:enumeration value="bright"/>
<xsd:minLength value="0"/>
<xsd:maxLength value="10"/>
</xsd:restriction>
</xsd:complexType>
XML文件:
<?xml version="1.0" encoding="utf-8" ?>
<carCollection>
<!--
W tym pliku xml jest opisana kolekcja wybranych samochodow
-->
<personalData>
<name>Łukasz</name>
<surname>Skiba</surname>
<sex>male</sex>
<age year_of_birth="1998">20</age>
<city region="Lesser Poland" motherland="Poland">Kraków</city>
<specialization semester="1">Informatyka Stosowana</specialization>
<group>WZISN1-1113</group>
</personalData>
<copyright xmlns:uek="https://www.uek.krakow.pl/">
Wydział zarządzania, Uniwersytet Ekonomiczny, Kraków
</copyright>
<car>
<brand>Ford</brand>
<model>Focus ST-Line Business</model>
<enginecapacity fuel="petrol">1.6</enginecapacity>
<color tone="mat">Black</color>
<enginepower power ="horsepower">125</enginepower>
<production_year>2018</production_year>
</car>
<car>
<brand>BMW</brand>
<model>2 Coupe</model>
<enginecapacity fuel="petrol">1.8</enginecapacity>
<color tone="mat">White</color>
<enginepower power ="horsepower">180</enginepower>
<production_year>2018</production_year>
</car>
<car>
<brand>Ford</brand>
<model>Mondeo</model>
<enginecapacity fuel="petrol">1.8</enginecapacity>
<color tone="mat">Grey</color>
<enginepower power ="horsepower">180</enginepower>
<production_year>2018</production_year>
</car>
<car>
<brand>Audi</brand>
<model>A7</model>
<enginecapacity fuel="petrol">2.8</enginecapacity>
<color tone="mat">Black</color>
<enginepower power ="horsepower">220</enginepower>
<production_year>2017</production_year>
</car>
<car>
<brand>Toyota</brand>
<model>Auris</model>
<enginecapacity fuel="petrol">2.8</enginecapacity>
<color tone="mat">Dark green</color>
<enginepower power ="horsepower">180</enginepower>
<production_year>2016</production_year>
</car>
<car>
<brand>Fiat</brand>
<model>126p</model>
<enginecapacity fuel="petrol">0.9</enginecapacity>
<color tone="mat">Red</color>
<enginepower power ="horsepower">25</enginepower>
<production_year>2000</production_year>
</car>
<car>
<brand>Citroen</brand>
<model>C3</model>
<enginecapacity fuel="petrol">1.4</enginecapacity>
<color tone="mat">Grey</color>
<enginepower power ="horsepower">70</enginepower>
<production_year>2007</production_year>
</car>
<car>
<brand>Lexus</brand>
<model>NX</model>
<enginecapacity fuel="petrol">3.0</enginecapacity>
<color tone="mat">White</color>
<enginepower power ="horsepower">160</enginepower>
<production_year>2017</production_year>
</car>
<car>
<brand>Skoda</brand>
<model>Superb</model>
<enginecapacity fuel="petrol">1.8</enginecapacity>
<color tone="mat">Blue</color>
<enginepower power ="horsepower">200</enginepower>
<production_year>2016</production_year>
</car>
<car>
<brand>Kia</brand>
<model>Cee'd</model>
<enginecapacity fuel="petrol">2.0</enginecapacity>
<color tone="mat">Navy Blue</color>
<enginepower power ="horsepower">200</enginepower>
<production_year>2017</production_year>
</car>
</carCollection>
答案 0 :(得分:0)
您需要将这些元素声明为具有“具有简单内容的复杂类型”。参见此处的示例:XML Schema Restriction With Attribute
也许是这样的:
<xs:simpleType name="capacityType">
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="5.0"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="fuelType">
<xs:restriction base="xsstring">
<xs:enumeration value="petrol"/>
<xs:enumeration value="diesel"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="engineCapacityType>
<xs:simpleContent>
<xs:extension base="capacityType">
<xs:attribute name="type" type="fuelType" use="required"/>
</xs:extension>
</xs:simpleContent
</xs:complexType>