Xml 内容模型-XSD不允许任何字符数据
尝试验证一个小xml时,我得到以下错误:内容模型不允许使用字符数据 这是我的xml示例:Xml 内容模型-XSD不允许任何字符数据,xml,xsd,Xml,Xsd,尝试验证一个小xml时,我得到以下错误:内容模型不允许使用字符数据 这是我的xml示例: <?xml version="1.0" encoding="UTF-8"?> <plats xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="1_e.xsd"> <primer codi='3'>Caldo de verdures</pri
<?xml version="1.0" encoding="UTF-8"?>
<plats xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="1_e.xsd">
<primer codi='3'>Caldo de verdures</primer>
<segon codi='4'>Pollastre al forn</segon>
<primer codi='7'>Spaguettis</primer>
<segon codi='12'>Llus a la planxa</segon>
</plats>
卡尔多德弗尔德斯酒店
波拉斯特尔福尔恩酒店
斯帕格蒂
拉普拉斯酒店
这是我的xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:complexType name="t_primer">
<xs:choice>
<xs:element name="primer" type="xs:string" />
</xs:choice>
<xs:attribute name="codi" type="xs:string" />
</xs:complexType>
<xs:complexType name="t_segon">
<xs:choice>
<xs:element name="segon" type="xs:string" />
</xs:choice>
<xs:attribute name="codi" type="xs:string" />
</xs:complexType>
<xs:element name="plats">
<xs:complexType>
<xs:choice>
<xs:sequence>
<xs:element name="primer" type="t_primer" />
</xs:sequence>
<xs:sequence>
<xs:element name="segon" type="t_segon" />
</xs:sequence>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
我无法找到我错在哪里,代码看起来很好…问题已解决:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:complexType name="t_primer">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="codi" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="t_segon">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="codi" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="plats">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="primer" type="t_primer" />
<xs:element name="segon" type="t_segon" />
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
您将同一类型嵌套两次:根据您的模式t\u primer
必须包含元素primer
,而不是字符串内容。最后我找到了解决方案,您的评论让我更好地理解了它。