SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: DTDs

  1. #1
    SitePoint Guru momos's Avatar
    Join Date
    Apr 2004
    Location
    Belgium
    Posts
    919
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DTDs

    I know there is a way to validate an xml-file against a DTD in IE, but forgot how it work, can anyone refresh my memory?

  2. #2
    SitePoint Zealot
    Join Date
    Sep 2004
    Location
    Belfast, Ireland
    Posts
    155
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Here you go

    Hi momos,

    here is an example of a DTD:

    Code:
    <!ELEMENT recipe (recipe_name, author, meal,
                      ingredients, directions)>
    <!ELEMENT ingredients (item+)>
    <!ELEMENT meal (#PCDATA, course?)>
    <!ELEMENT item (#PCDATA)>
    <!ATTLIST item
        measure (cups|tsps|number|ozs) #REQUIRED
        amount CDATA #REQUIRED>
    <!ELEMENT recipe_name (#PCDATA)>
    <!ELEMENT author (#PCDATA)>
    <!ELEMENT directions (#PCDATA)>
    <!ELEMENT course (#PCDATA)>
    and here is an example of an XML file using the DTD:

    Code:
    <!DOCTYPE X SYSTEM "/dtd/recipe.dtd">
    
    <recipe>
      <recipe_name>Pasta Origino</recipe_name>
      <author>Giuseppe Verdi</author>
      <meal>Dinner<course>starter</course></meal>
      <ingredients>
        <item measure = "cups" amount = "3">Tagliatelle</item>
        <item measure = "tsps" amount = "6">Tomato Puree</item>
        <item measure = "ozs" amount = "8">Onions</item>
       ...
      </ingredients>
      <directions>Boil the pasta for ten minutes
            ...
      </directions>
    </recipe>
    Another example DTD (tutorial.dtd):

    Code:
    <!ELEMENT X (A?, B+)>
    <!ELEMENT A (C?, D*)>
    <!ELEMENT B (C, D)>
    <!ELEMENT C (#PCDATA)>
    <!ELEMENT D EMPTY>
    And an example valid document using the DTD:

    Code:
    <!DOCTYPE X SYSTEM "/dtd/tutorial.dtd">
    <X>
      <A>
        <C>some information</C>
        <D/>
      </A>
      <B>
        <C/><D/>
      </B>
    </X>

  3. #3
    SitePoint Guru momos's Avatar
    Join Date
    Apr 2004
    Location
    Belgium
    Posts
    919
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply...

    but if you write:
    Code:
    <!ELEMENT X (A?, Something+)>
    <!ELEMENT A (C?, D*)>
    <!ELEMENT B (C, D)>
    <!ELEMENT C (#PCDATA)>
    <!ELEMENT D EMPTY>
    and

    Code:
    <!DOCTYPE X SYSTEM "/dtd/tutorial.dtd">
    <X>
      <A>
        <C>some information</C>
        <D/>
      </A>
      <B>
        <C/><D/>
      </B>
    </X>
    This will still validate, while IE should reject it since this is not valid according to the DTD (I thought this used to happen, but now IE doesn't do this anymore - or maybe it never did and is my memory just clouded, anyway I wanted to know for shure)


Bookmarks

Posting Permissions

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