Results 1 to 2 of 2

Thread: XML - Document Type Definitions [DTD]

  1. #1
    Join Date
    Nov 2009
    Posts
    76,596

    Default XML - Document Type Definitions [DTD]

    XML - Document Type Definitions (DTD)


    In this totuorial you will learn about XML - Document Type Definitions (DTD) - Need, DTD, Types Of DTD’s , Internal DTD , External DTD.

    NEED


    XML documents can contain many different types of markups including elements, attributes and entity references. Whatever maybe the application it is desirable that the XML document conforms to a certain set of rules governing the data structure it contains. DTD and Schema’s are used for this purpose.
    For Example,


    < name >12233< /name >


    If a DTD defines that data in name tags should contain only characters and if it contains numbers , as shown above, the document is invalidated by the XML parser using the Document Type Definition (DTD) as reference.
    DTD

    DTD stands for Document Type Definitions. It describes syntax that explains which elements may appear in the XML document and what are the element contents and attributes.
    A valid XML document must include the reference to DTD which validates it. When a DTD is absent the validating parser can’t verify the data format but can attempt to interpret the data.

    TYPES OF DTD

    • Internal DTD: DTD can be embedded into XML document
    • External DTD: DTD can be in a separate file

    INTERNAL DTD

    Internal DTD are embedded in the XML document itself. They are convenient when constraints are applied to a single document. They are also used while designing a complex DTD for testing a sample document. Also, modifications becomes relatively simpler since the DTD and markup are in the same document.

    Syntax : < ! DOCTYPE root_name[assignments] >

    It begins with the DOCTYPE keyword (after < less than and ! exclamation mark) followed by the name of the root element. The root is followed by a square bracket which signifies beginning of declaration assignments. The last entry is a less than symbol ( >).


    In the assignments section elements are declared as follows -
    < !ELEMENT child_name(child_name or data type) >
    Detailed explanation on this is covered in the next tutorial.

    E.g.

    < ?xml version='1.0' encoding='utf-8'? >
    < !-- DTD for a AddressBook.xml -- >
    < !DOCTYPE AddressBook [
    < !ELEMENT AddressBook (Address+) >
    < !ELEMENT Address (Name, Street, City) >
    < !ELEMENT Name (#PCDATA) >
    < !ELEMENT Street (#PCDATA) >
    < !ELEMENT City (#PCDATA) >
    ] >
    < AddressBook >
    < Address >
    < Name >samson< /Name >
    < Street >Line Street < /Street >
    < City >Bengaluru< /City >
    < /Address >
    < /AddressBook >


    Keywords:XML,Document Type Definitions ,DTD, Types Of DTD’s , Internal DTD , External DTD,XML documents , markups ,including elements, attributes , entity references, data structure, Schema,DTD defines , XML parser ,describes syntax , element contents , attributes,DOCTYPE keyword ,ELEMENT AddressBook .

    Last edited by sherlyk; 11-24-2011 at 06:51 AM.

  2. #2
    Join Date
    Nov 2011
    Posts
    5

    Default


Tags for this Thread

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
  •