我不确定为什么XML和XSD代码都在浏览器中显示错误消息。我试图根据错误纠正两者,但仍然没有正确
浏览器中的XML显示:“第16行第11行的错误:打开和结束标记不匹配:元行0和头部”
浏览器中的XSD显示:“第15行第31行的错误:打开和结束标记不匹配:元素行0和所有”
<?xml version = "1.0"?>
<?xml-stylesheet type = "text/xsl" href = "nutrition.xsl"?>
<nutrition:items xmlns:nutrition = "http://www.grandmascookies.com/nutrition">
<product name = "Grandma White's Cookies">
<item>
<servingsize>
<amount> 1 </amount>
<unit> package </unit>
</servingsize>
<calories>
<amount> 260 </amount>
<unit> calories </unit>
</calories>
<caloriesFat>
<amount> 100 </amount>
<unit> grams </unit>
</caloriesFat>
</item>
</product>
</nutrition:item>
<?xml version = "1.0"?>
<schema xmlns = "http://wwww.w3.org/2001/XMLSCHEMA"
xmlns:nutrition = "http://wwww.grandmascookies.com/nutrition"
targetNamespace = "http://www.grandmascookies.com/nutrition">
<simpleType name = "amount"> <restriction base = "int"/> </simpleType>
<simpleType name = "unit"> <restriction base = "string"/> </simpleType>
<complexType name = "nutritionFact">
<all>
<element name = "amount" type = "nutrition:amount"/>
<element name = "unit" type = "nutrition:unit"/>
</all>
</complexType>
<complexType name = "productType">
<all>
<element name = "product" type = "string">
<element name = "servingsize" type = "nutrition:nutritionFact"/>
<element name = "calories" type = "nutrition:nutritionFact"/>
<element name = "caloriesFat" type = "nutrition:nutritionFact"/>
</all>
</complexType>
<complexType name = "productType1">
<element name = "item" type = "nutrition:productType"/>
<element name = "items" type = "nutrition:productType1"/>
</complexType>
</schema>
答案 0 :(得分:0)
答案在评论中,你真的应该使用XML解析器,但要明确:
在XML文件中,最后一行应为
</nutrition:items>
注意:商品 s 不是商品
在XSD文件中定义的第三行
<complexType name = "productType">
应该是
<element name = "product" type = "string"/>
注意:/>
不仅仅是>
。