我已经制作了这个食谱列表,但由于某些原因,当我尝试在Oxygen XML Editor中验证文档时,我收到了大量的错误消息。 氧气给了我以下错误:
元素类型"成分"不得多次申报 元素类型"名称"不得多次申报 元素类型"数量"不得多次申报 意想不到的元素"成分"。父元素的内容必须匹配: (名称+,成分+,数量+,装饰,说明,必要性,准备)
这是我的代码:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE recipes SYSTEM "recipes.dtd">
<recipes>
<cocktail>
<name>Hells Bells</name>
<ingredients>Batida de Coco</ingredients>
<quantity> 4cl </quantity>
<ingredients>caramel sirup</ingredients>
<quantity> 2 cl </quantity>
<ingredients>Milk</ingredients>
<quantity> 8 cl </quantity>
<ingredients>Strawberry puree</ingredients>
<quantity> 4 cl </quantity>
<decoration>Decoration: Strawberry blood with spiders.</decoration>
<instructions>Instructions: All ingredients should be shaken.</instuctions>
</cocktail>
<cocktail>
<name>Feuerzangenbowle</name>
<ingredients>red wine</ingredients>
<quantity> 1000 ml </quantity>
<ingredients>cinnamon</ingredients>
<quantity> 1 </quantity>
<ingredients>Carnations</ingredients>
<quantity> 3 </quantity>
<necessity>500 ml Pott</necessity>
<preparation>Season with cinnamon stick and cloves.</preparation>
</cocktail>
<appetizer>
<name>Fresh glass</name>
<ingredients>avocado</ingredients>
<quantity> 1 </quantity>
<ingredients>salmon</ingredients>
<quantity> 100 g </quantity>
<ingredients>chives</ingredients>
<quantity> stems </quantity>
<ingredients>lemon</ingredients>
<quantity> 1 </quantity>
</appetizer>
<appetizer>
<name>Merceiles Hummus</name>
<ingredients>Chickpeas</ingredients>
<quantity> 400 g </quantity>
<ingredients>olive oil</ingredients>
<quantity> 2 TS </quantity>
<ingredients>salt</ingredients>
<quantity> 1 TS </quantity>
<ingredients>Pepper powder</ingredients>
<quantity> 1 TS </quantity>
</appetizer>
<maindish>
<name>Pickled salmon</name>
<ingredients>salmon</ingredients>
<quantity> 2,5 kg </quantity>
<ingredients>pepper</ingredients>
<quantity> 1 TS </quantity>
<ingredients>salt</ingredients>
<quantity> 4 TS </quantity>
<ingredients>honey</ingredients>
<quantity> 4 TS </quantity>
</maindish>
<maindish>
<name>Beef fillet</name>
<ingredients>Beef fillet</ingredients>
<quantity> 1,5 kg </quantity>
<ingredients>Butterfelt</ingredients>
<quantity> 20 g </quantity>
<ingredients>thyme</ingredients>
<quantity> 4 branches </quantity>
</maindish>
<dessert>
<name>Chocolate Muffins</name>
<ingredients>chocolate</ingredients>
<quantity> 225 g </quantity>
<ingredients>butter</ingredients>
<quantity> 115 g </quantity>
<ingredients>vanillasuger</ingredients>
<quantity> 1 TS </quantity>
<ingredients>sugar</ingredients>
<quantity> 100 g </quantity>
</dessert>
<dessert>
<name>Tiramisu</name>
<ingredients>sugar</ingredients>
<quantity> 100 g </quantity>
<ingredients>yolk</ingredients>
<quantity> 4 </quantity>
<ingredients>egg whites</ingredients>
<quantity> 2 </quantity>
<ingredients>Amaretto</ingredients>
<quantity> 2 cl </quantity>
</dessert>
</recipes>
这是DTD:
<!-- DTD document recipes.xml -->
<!ELEMENT recipes (cocktail+, appetizer+, maindish+, dessert+)>
<!ELEMENT cocktail (name+, ingredients+, quantity+, decoration, instructions, neccessity, preparation)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT ingredients (#PCDATA)>
<!ELEMENT quantity (#PCDATA)>
<!ELEMENT decoration (#PCDATA)>
<!ELEMENT instructions (#PCDATA)>
<!ELEMENT neccessity (#PCDATA)>
<!ELEMENT preparation (#PCDATA)>
<!ELEMENT appetizer (name+, ingredients+, quantity+)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT ingredients (#PCDATA)>
<!ELEMENT quantity (#PCDATA)>
<!ELEMENT maindish (name+, ingredients+, quantity+)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT ingredients (#PCDATA)>
<!ELEMENT quantity (#PCDATA)>
<!ELEMENT dessert (name+, ingredients+, quantity+)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT ingredients (#PCDATA)>
<!ELEMENT quantity (#PCDATA)>
我真的不知道该怎么做了,非常感谢你的帮助! 提前感谢您的回答!
P.S - XML新手
答案 0 :(得分:1)
element type "ingredients" must not be declared more than once element type "name" must not be declared more than once element type "quantity" must not be declared more than once
这些错误非常自我解释;你只能在DTD中声明一次元素(<!ELEMENT
声明)。
unexpected element "ingredients". The content of the parent element must match: (name+, ingredients+, quantity+, decoration, instructions, neccessity, preparation)
此错误表示ingredients
元素不合适。 ingredients
(cocktail
)的父级必须与DTD中的模型匹配。在这种情况下,cocktail
必须具有:
name
元素,后跟ingredients
元素,后跟quantity
元素,后跟decoration
元素,后跟instructions
元素,后跟neccessity
元素,后跟preparation
元素查看您的XML,这看起来并不像您想要的那样。你可能想要看起来更像这样的东西:
(name+, (ingredients, quantity)+, decoration?, instructions?, necessity?, preparation?)
这是:
name
元素,后跟ingredients
元素,后跟quantity
元素decoration
元素后跟instructions
元素后跟necessity
元素后跟preparation
元素您在DTD和XML中拼写necessity
的方式不同;他们需要匹配。
您还拼错了第一个instructions
中的cocktail
结束标记。
ingredients
,quantity
和appetizer
的模型中还应更新maindish
后跟dessert
一次或多次的部分。< / p>
这是一个更新的DTD:
<!ELEMENT recipes (cocktail+, appetizer+, maindish+, dessert+)>
<!ELEMENT cocktail (name+, (ingredients, quantity)+, decoration?, instructions?, necessity?, preparation?)>
<!ELEMENT appetizer (name+, (ingredients, quantity)+)>
<!ELEMENT maindish (name+, (ingredients, quantity)+)>
<!ELEMENT dessert (name+, (ingredients, quantity)+)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT ingredients (#PCDATA)>
<!ELEMENT quantity (#PCDATA)>
<!ELEMENT decoration (#PCDATA)>
<!ELEMENT instructions (#PCDATA)>
<!ELEMENT necessity (#PCDATA)>
<!ELEMENT preparation (#PCDATA)>
和XML文件:
<!DOCTYPE recipes SYSTEM "recipes.dtd">
<recipes>
<cocktail>
<name>Hells Bells</name>
<ingredients>Batida de Coco</ingredients>
<quantity> 4cl </quantity>
<ingredients>caramel sirup</ingredients>
<quantity> 2 cl </quantity>
<ingredients>Milk</ingredients>
<quantity> 8 cl </quantity>
<ingredients>Strawberry puree</ingredients>
<quantity> 4 cl </quantity>
<decoration>Decoration: Strawberry blood with spiders.</decoration>
<instructions>Instructions: All ingredients should be shaken.</instructions>
</cocktail>
<cocktail>
<name>Feuerzangenbowle</name>
<ingredients>red wine</ingredients>
<quantity> 1000 ml </quantity>
<ingredients>cinnamon</ingredients>
<quantity> 1 </quantity>
<ingredients>Carnations</ingredients>
<quantity> 3 </quantity>
<necessity>500 ml Pott</necessity>
<preparation>Season with cinnamon stick and cloves.</preparation>
</cocktail>
<appetizer>
<name>Fresh glass</name>
<ingredients>avocado</ingredients>
<quantity> 1 </quantity>
<ingredients>salmon</ingredients>
<quantity> 100 g </quantity>
<ingredients>chives</ingredients>
<quantity> stems </quantity>
<ingredients>lemon</ingredients>
<quantity> 1 </quantity>
</appetizer>
<appetizer>
<name>Merceiles Hummus</name>
<ingredients>Chickpeas</ingredients>
<quantity> 400 g </quantity>
<ingredients>olive oil</ingredients>
<quantity> 2 TS </quantity>
<ingredients>salt</ingredients>
<quantity> 1 TS </quantity>
<ingredients>Pepper powder</ingredients>
<quantity> 1 TS </quantity>
</appetizer>
<maindish>
<name>Pickled salmon</name>
<ingredients>salmon</ingredients>
<quantity> 2,5 kg </quantity>
<ingredients>pepper</ingredients>
<quantity> 1 TS </quantity>
<ingredients>salt</ingredients>
<quantity> 4 TS </quantity>
<ingredients>honey</ingredients>
<quantity> 4 TS </quantity>
</maindish>
<maindish>
<name>Beef fillet</name>
<ingredients>Beef fillet</ingredients>
<quantity> 1,5 kg </quantity>
<ingredients>Butterfelt</ingredients>
<quantity> 20 g </quantity>
<ingredients>thyme</ingredients>
<quantity> 4 branches </quantity>
</maindish>
<dessert>
<name>Chocolate Muffins</name>
<ingredients>chocolate</ingredients>
<quantity> 225 g </quantity>
<ingredients>butter</ingredients>
<quantity> 115 g </quantity>
<ingredients>vanillasuger</ingredients>
<quantity> 1 TS </quantity>
<ingredients>sugar</ingredients>
<quantity> 100 g </quantity>
</dessert>
<dessert>
<name>Tiramisu</name>
<ingredients>sugar</ingredients>
<quantity> 100 g </quantity>
<ingredients>yolk</ingredients>
<quantity> 4 </quantity>
<ingredients>egg whites</ingredients>
<quantity> 2 </quantity>
<ingredients>Amaretto</ingredients>
<quantity> 2 cl </quantity>
</dessert>
</recipes>