【发布时间】:2023-03-09 19:20:01
【问题描述】:
我一直在试图解决这个问题,此时我不确定我是否弄乱了导致问题的命名空间,或者代码的语法是否有问题,但 itemName 的所有实例都是声明相同并且都正确关闭。
试图找出这个错误:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'itemName'. One of '{itemName}' is expected.
我的 xsd 文件:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.com/chestershartland/recipe"
xmlns="http://example.com/chestershartland/recipe"
>
<xs:element name="recipe">
<xs:complexType>
<xs:sequence>
<xs:element name="itemName" type="xs:string" />
<xs:element name="ingredients">
<xs:complexType>
<xs:sequence>
<xs:element name="ingredient" type="xs:string" />
<xs:element name="ingredient" type="xs:string" />
<xs:element name="ingredient" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="directions" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
XML 代码是:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<recipe
xmlns="http://example.com/chestershartland/recipe"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://example.com/chestershartland/recipe recipe.xsd"
>
<itemName>Oatmeal Breakfast</itemName>
<ingredients>
<ingredient>1/3 c steel cut oats</ingredient>
<ingredient>1-1/4 c water</ingredient>
<ingredient>1/4 t salt</ingredient>
</ingredients>
<directions>
<![CDATA[Bring water to a boil. Add salt and oats, stir, and lower heat
to lowest setting. Cover and let stand 2 hours.
]]>
</directions>
</recipe>
【问题讨论】:
标签: xml xsd namespaces