cI有一个我需要阅读的XML文件,它看起来与此类似:
<?xml version="1.0" encoding="UTF-8"?>
<flowers>
<flower name="rose">
<soilType>Podzolic</soilType>
<visualParameters>
<stemColor>Green</stemColor>
<leafColor>Red</leafColor>
<averageSize>50</averageSize>
</visualParameters>
<growingTips>
<LightType>photophilous</LightType>
<temperature>38</temperature>
<watering>1200</watering>
</growingTips>
<multiplying>bySeeds</multiplying>
<origin>Belarus</origin>
<description>Classic Choice</description>
</flower>
</flowers>
在构建时,我使用JAXB
为XSD生成我的类(此xsd由几列修改)。当我尝试验证它时,它会抱怨
无法解析名字&#39;鲜花&#39;到A(n)&#39;类型定义&#39;成分
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="flowers" type="Flowers"></xs:element>
<xs:complexType name="flowers">
<xs:sequence>
<xs:element name="flower" type="flower" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
<xs:element name="flower" type="FlowerType"/>
<xs:complexType name="flower">
<xs:sequence>
<xs:element name="soilType" type="SoilType" minOccurs="0"/>
<xs:element name="visualParameters" type="VisualParameters" minOccurs="0"/>
<xs:element name="growingTips" type="growingTips" minOccurs="0"/>
<xs:element name="multiplyingType" type="multiplyingType" minOccurs="0"/>
<xs:element name="origin" type="xs:string" minOccurs="0"/>
<xs:element name="description" type="xs:string" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
<xs:complexType name="growingTips">
<xs:sequence>
<xs:element name="temperature" type="xs:int"/>
<xs:element name="watering" type="xs:int"/>
</xs:sequence>
<xs:attribute name="value" type="lightingType"/>
</xs:complexType>
<xs:complexType name="VisualParameters">
<xs:sequence>
<xs:element name="stemColor" type="xs:string" minOccurs="0"/>
<xs:element name="leafColor" type="xs:string" minOccurs="0"/>
<xs:element name="averageSize" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="multiplyingType">
<xs:restriction base="SoilName"/>
</xs:simpleType>
<xs:complexType name="SoilType">
<xs:sequence>
<xs:element name="value" type="Soil" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="lightingType">
<xs:restriction base="xs:string">
<xs:enumeration value="photophilous"/>
<xs:enumeration value="unphotophilous"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="SoilName">
<xs:restriction base="xs:string">
<xs:enumeration value="byLeafs"/>
<xs:enumeration value="byCutting"/>
<xs:enumeration value="bySeeds"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="Soil">
<xs:restriction base="xs:string">
<xs:enumeration value="podzolic"/>
<xs:enumeration value="dirt"/>
<xs:enumeration value="sodPodzolic"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
如何设置架构以成功验证xml?
答案 0 :(得分:0)
我怀疑flowers
元素定义是原因,它可能应该是:
<xs:complexType name="flowers">
<xs:sequence>
<xs:element name="flower" type="flower" maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>