·  XML – DTD – Examples - Complex


- Info:

  - This tutorial shows one complex example of using XML and DTD.


- Example:

  - <!DOCTYPE family [         

  - Defines that root element must be <family>

    It is not mandatory for .dtd to have <!DOCTYPE defined.

    Example: <title>My Family</title>


  - <!ELEMENT title  (#PCDATA)>   

  - Defines that tag <title> of data type "text" is allowed.


  - <!ELEMENT parent (#PCDATA)>

    <!ATTLIST parent role (mother | father) #required>

  - Defines that tag <parent> of data type "text" is allowed.

    Tag <parent> must have attribute "role" defined.

    Attribute role can only have one of folowing two values: "mother" or "father"

    Example: <parent role = "mother">Judy</parent>


  - <!ELEMENT phone   (home,mobile*)  >

    Defines that tag <phone> can have child tags <home> & <mobile>


  - <!ELEMENT image EMPTY>

  - Defines that tag <image> has no body.



    <!DOCTYPE family [


      <!ELEMENT title  (#PCDATA)>


      <!ELEMENT parent (#PCDATA)>

        <!ATTLIST parent role (mother | father) #required>


      <!ELEMENT child  (#PCDATA)>

        <!ATTLIST child role (daughter | son) #required>


      <!ELEMENT phone   (home,mobile*>


      <!ELEMENT home  (#PCDATA)   >


      <!ELEMENT mobile  (#PCDATA)   >


      <!ELEMENT image EMPTY>

        <!ATTLIST image source entity #required>


      <!ENTITY footer "Brought to you by Jennifer Kyrnin">


      <!NOTATION gif system "image/gif">


      <!ENTITY JENN system "http://images.about.com/sites/guidepics/html.gif" NDATA gif>





    <?xml version="1.0" standalone="yes"?>



      <title>My Family</title> 

      <parent role   = "mother"  >Judy</parent>

      <parent role   = "father"  >Layard</parent>

      <child  role   = "daughter">Jennifer</child>

      <image  source = "JENN" />

      <child  role   = "son"     >Brendan</child>