错误:元素对内容模型无效

时间:2013-05-12 11:25:44

标签: xml xml-dtd

帮助:验证错误:元素'ingred'对内容模型无效:'(frontmatter,ingred,prep,comment)'[xml]

有人可以告诉我我错过了什么吗?

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE lovefood [
<!ELEMENT lovefood (frontmatter,ingred,prep,comment)>
<!ELEMENT frontmatter (publisher,title,date,isbn,blurb)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT isbn (#PCDATA)>
<!ELEMENT date (#PCDATA)>
<!ELEMENT blurb (#PCDATA)>

<!ELEMENT ingred ((recipe|subrecipe)*)>
<!ATTLIST recipe title CDATA #IMPLIED>
<!ELEMENT recipe (section,ing*)>
<!ELEMENT section (#PCDATA)>
<!ATTLIST subrecipe title CDATA #IMPLIED>
<!ELEMENT subrecipe (ing*)>
<!ATTLIST ing name CDATA #REQUIRED
   amount CDATA #IMPLIED
    unit CDATA #IMPLIED>
<!ELEMENT ing (#PCDATA)>

<!ELEMENT prep (step+)>
<!ELEMENT step (#PCDATA)>

<!ELEMENT comment (photo_of_dish,pagenumber)>
<!ELEMENT photo_of_dish (#PCDATA)>
<!ELEMENT pagenumber (#PCDATA)>
]>

<lovefood>

<frontmatter>
<publisher>Parragon Books Ltd</publisher>
<title>Love Food</title>
<date>2011</date>
<isbn>978-1-4454-4285-3</isbn>
<blurb>Clear and easy-to-follow ingredients lists and step-by-step methods</blurb>
</frontmatter>

<ingred>
<recipe title="Ingredients">
<section>fish and seafood</section>
<ing name="plain flour, for dusting olive oil, for oiling and drizzling"></ing>
<ing name="quantity tomato sauce" amount="1"></ing>
<ing name="mixed fresh seafood" amount="225" unit="g"></ing>
<ing name="red pepper and yellow pepper deseeded and chopped" amount="0.5"></ing>
<ing name="capers, rinsed" amount="1" unit="tbsp"></ing>
<ing name="Taleggio cheese, grated" amount="55" unit="g"></ing>
<ing name="freshly grated parmesan cheese" amount="3" unit="tbsp"></ing>
<ing name="dried oregano" amount="0.5" unit="tsp"></ing>
<ing name="anchovy fillets in oil, drained and sliced" amount="75" unit="g"></ing>
<ing name="black olivees, stoned" amount="10"></ing>
<ing name="salt and pepper"></ing>
</recipe>
</ingred>

<ingred>
<subrecipe title="Pizza Dough">
<ing name="plain flour, plus extra for dusting" amount="225" unit="g"></ing>
<ing name="salt" amount="1" unit="tsp"></ing>
<ing name="easy blend dried yeast" amount="1" unit="tsp"></ing>
<ing name="olive oil" amount="1" unit="tbsp"></ing>
<ing name="lukewarm water" amount="90" unit="ml"></ing>
</subrecipe>
</ingred>

<prep>
<step>
1. To make the pizza dough, sift the flour and salt into a bowl and stir in the         yeast.Make a wheel in the centre and pour in the oil and water. Incorporate the dry ingredients into the liquid, using floured hands.
</step> 
<step>
2. Turn out the dough onto a lightly floured work surface and knead well for 5 minutes,until smooth and elastic. Return to the clean bowl, cover with lightly oiled clingfilm and set aside to rise in a warm place for about 1 hour, or until doubled in size.
</step>
<step>
3. Turn out the dough again onto a lightly floured work surface and knock down. Knead briefly, then roll out the dough into a circle about 6mm/ 1/4 inch thick. Transfer to a lightly oiled baking sheet and push up the edge with your fingers to form a small rim.
</step>
<step>
4. Spread the tomato sauce over the pizza base, almost to the edge.Arrange the mixed seafood, red and yellow peppers and capers evenly on top.
</step>
<step>
5. Sprinkle the cheeses and oregano evenly over the topping. Add the anchovy fillets and olives, drizzle with olive oil.Season to taste with salt and pepper.
</step> 
<step>
6. Bake in a preheated oven, 220 C/ 425 F/ Gas Mark 7, for 20-25 minutes, until the crust is crisp and the cheese has melted.Serve immediately.
</step>
</prep>

<comment>
<photo_of_dish>input photo here</photo_of_dish>
<pagenumber>130</pagenumber>
</comment>

<ingred>
<recipe title="Scallops with porcini and cream sauce">
<section>fish and seafood</section>
<ing name="dried porcini mushrooms" amount="25"></ing>
<ing name="hot water" amount="500" unit="ml"></ing>
<ing name="olive oil" amount="3" unit="tbsp"></ing>
<ing name="butter" amount="40" unit="g"></ing>
<ing name="sliced scallops" amount="350" unit="g"></ing>
<ing name="garlic cloves, very finely chopped" amount="2"></ing>
<ing name="lemon juice" amount="2" unit="tbsp"></ing>
<ing name="double cream" amount="250" unit="ml"></ing>
<ing name="dried fettuccine or papardelle" amount="350" unit="g"></ing>
<ing name="chopped fresh flat leaf parsley, to serve" amount="2" unit="tbsp"></ing>
<ing name="salt and pepper"></ing>
</recipe>
</ingred>

<prep>
<step>
1. Put the porcini and hot water in a bowl and soak for 20 minutes. Strain the mushrooms, reserving the soaking water, and chop roughly. Line a sieve with kitchen paper and strain the mushroom water into a bowl
</step>
<step>
2. Heat the oil and butter in a large frying pan over a medium heat. Add the scallops and cook for 2 minutes, or unitl just golden. Add the garlic and mushrooms, then stir-fry for another minute
</step>
<step>
3. Stir in the lemon juice, cream and 150ml of the mushroom water. Bring to the boil, then simmer over a medium heat for 2-3 minutes, stirring constantly, until the liquid is reduced by half. Season with salt and pepper. Remove from heat.
</step>
<step>
4. Meanwhile, bring a large saucepan of lightly salted water to the boil. Add the pasta, bring back to the boil and cook for 8-10 minutes, until tender but firm. Drain and transfer to a warm serving dish. Briefly reheat the sauce and pour over the pasta. Sprinkle with the parsley and toss well to mix. Serve immediately.
</step>
</prep>

<comment>
<photo_of_dish>input photo here</photo_of_dish>
<pagenumber>126</pagenumber>
</comment>
</lovefood>

元素'ingred'对内容模型无效:'(frontmatter,ingred,prep,comment)'[xml]

2 个答案:

答案 0 :(得分:2)

您的DTD指定爱情食品必须按照确认顺序包含四个孩子:

<!ELEMENT lovefood (frontmatter,ingred,prep,comment)>

您有多个ingred。如果这是您想要的,您可以将DTD更改为:

<!ELEMENT lovefood (frontmatter,ingred+,prep,comment)>

[我同意错误信息并不总是易于解释,但这是因为很难确切地确定错误。因此,请使用该消息找出问题所在的位置。

答案 1 :(得分:1)

DTD表示lovefood的内容模型是(frontmatter, ingred, prep, comment)(每个中的一个,按此顺序)。 XML内容违反了该模型,因为它包含以下lovefood的直接子项:frontmatteringredingredprepcommentingredprepcomment.

所以需要修复。究竟是多么不明显,因为您刚刚粘贴了一个XML文档而没有说明您真正想要的结构。

看起来有点奇怪的一件事是让ingred作为recipe的父级。反过来似乎更自然;食谱包含成分列表。由于这似乎是一个食谱集合,因此我建议将recipes元素作为子元素添加recipe个元素,以便lovefood的内容模型变为(frontmatter, recipes)