www.webdeveloper.com
Results 1 to 3 of 3

Thread: New to dtd & xml help

  1. #1
    Join Date
    Apr 2013
    Posts
    3

    New to dtd & xml help

    Hi there,

    I'm trying to code a cookbook, I've done the XML for a recipe but am really struggling to get the correct DTD valid.

    Any help would be MASSIVELY appreciated for a noob. Eventually the DTD and XML will have two recipes, hence why there is mention of recipetwo in the DTD.

    I keep facing errors such as document element does not allow element 'ingredient' here.
    Also error element "prep_ingredient" undefined.

    Like I said, any help would be appreciated for a beginner. Thanks!!

    This is the DTD so far followed by the XML
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE cookbook [
    <!ELEMENT cookbook (frontcover+,body+)>
    <!ELEMENT frontcover (title,byline,author)>
    <!ELEMENT title (#PCDATA)>
    <!ELEMENT byline (#PCDATA)>
    <!ELEMENT author (#PCDATA)>
    <!ELEMENT body (recipeone+,recipetwo+)>
    <!ENTITY PUBLISHER "Quadrille Publishing">
    <!ENTITY COPYRIGHT "Copyright 2010 Quadrille Publishing">

    <!ELEMENT recipeone (recipe_title,prep_time,cook_time,recipe_blurb,ingredients_list,ingredient*,quantity*,food_item*)>
    <!ELEMENT recipe_title (#PCDATA)>
    <!ELEMENT prep_time (#PCDATA)>
    <!ELEMENT cook_time (#PCDATA)>
    <!ELEMENT recipe_blurb (#PCDATA)>
    <!ELEMENT ingredients_list (#PCDATA)>
    <!ELEMENT ingredient (#PCDATA)>
    <!ELEMENT quantity (#PCDATA)>
    <!ELEMENT food_item (#PCDATA)>
    <!ELEMENT method (prep_ingredient,step_one,step_two,step_three,step_four,step_five,step_six)>
    <!ELEMENT step_one (#PCDATA)>
    <!ELEMENT step_two (#PCDATA)>
    <!ELEMENT step_three (#PCDATA)>
    <!ELEMENT step_four (#PCDATA)>
    <!ELEMENT step_five (#PCDATA)>
    <!ELEMENT step_six (#PCDATA)>
    ]>
    <cookbook>


    <frontcover>

    <title> Alice's Cookbook </title>
    <byline> "I love this book. I love everything about it: the recipes, the tone and, as importantly, Alice's warmth." </byline>
    <author> Alice Hart </author>

    </frontcover>

    <body>
    <recipeone>
    <recipe_title> Honey's Raspberry Turnover </recipe_title>
    <prep_time> Hands on Time: 15 mins </prep_time>
    <cook_time> 20 mins </cook_time>
    <recipe_blurb> Honey, my baker-extraordinaire, puff-pastry-making gradnmother, has been a dab hand with a turnover for as long as I can remember, churning out batches of apple, apricot or raspberry from a handsome blue Aga. Make sure you use all-butter puff pastry; it tastes better and has a much more wholesome ingredient
    list. </recipe_blurb>

    <ingredients_list>
    <ingredient> flour, to dust </ingredient>
    <ingredient> <quantity> 500g </quantity> of <food_item> all-butter puff pastry </food_item> </ingredient>
    <ingredient> <quantity> 500g </quantity> of <food_item> fresh raspberries </food_item>
    </ingredient>
    <ingredient> <quantity> 125g </quantity> of <food_item> vanilla sugar or caster sugar
    </food_item> </ingredient>
    <ingredient> <quantity> 1 </quantity> of <food_item> free-range egg yolk </food_item>
    mixed with <quantity> 1 tbsp </quantity> <food_item> milk </food_item> </ingredient>
    </ingredients_list>


    <method>
    <prep_ingredient> Pastry </prep_ingredient>
    <step_one> Flour surface. </step_one>
    <step_two> Roll out pastry to form a 1/2 thick rectangle. </step_two>
    <step_three> Straighten raggedy edges with a sharp knife. </step_three>
    <step_four> Cut pastry into eight even squares of 15x15cm. </step_four>

    <prep_ingredient> Raspberries </prep_ingredient>
    <step_one> Place a pile of respberries in each square, slightly off centre. </step_one>
    <step_two> Add a heaped teaspoon of sugar. </step_two>
    <step_three> Using a pastrry brucsh, paint a little water around the edge and bring one
    corner to meet its diaganol opposite. </step_three>
    <step_four> Press the edges together firmly to seal using the tines of a fork.
    </step_four>
    <step_five> Repeat to make eight pastries. </step_five>
    <step_six> Place pastries on a baking tray. </step_six>

    <prep_ingredient> oven time </prep_ingredient>
    <step_one> Preheat oven to 200 degrees/fan 190 degrees/gas mark 6. </step_one>
    <step_two> Brush pastry with egg wash (yolk and milk mixture). </step_two>
    <step_three> Sprinkle with a little more sugar. </step_three>
    <step_four> Cut a small vent in the top of each to let the steam out. </step_four>
    <step_five> Bake for 20 minutes, until exuberantly plump and golden. </step_five>
    <step_six> Cool on a wire rack and serve warm. </step_six>

    </method>
    </recipeone>


    </body>

    </cookbook>

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,270
    You've declared that the ingredients_list element contains parsed character data but no ingredient elements. I think that what you want is:
    Code:
    <!ELEMENT ingredients_list (ingredient *)>
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Apr 2013
    Posts
    3
    That's definitely helped, thanks for such a quick response! So simple too!

    I've still got errors such as document type does not allow element "quantity" here

    This is the same for food _item as well.

    Any ideas?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles