Document Type Definitions DTDs - PowerPoint PPT Presentation


PPT – Document Type Definitions DTDs PowerPoint presentation | free to view - id: 2444de-ZTU0N


The Adobe Flash plugin is needed to view this content

Get the plugin now

View by Category
About This Presentation

Document Type Definitions DTDs


DTD explains precisely which elements and entities may appear where in the ... You can Validate whether your ... ENTITIES ... – PowerPoint PPT presentation

Number of Views:128
Avg rating:3.0/5.0
Slides: 27
Provided by: ccNct


Write a Comment
User Comments (0)
Transcript and Presenter's Notes

Title: Document Type Definitions DTDs

Document Type Definitions (DTDs)
Whats DTD for?
  • DTD explains precisely which elements and
    entities may appear where in the document and
    what the elements' contents and attributes are
  • DTD defines the valid structure of a XML document
  • Valid element names
  • ltBOOKgtltTITLEgtltAUTHORgtltPRICEgtltISBNgt
  • Valid attribute names and values
  • ltAUTHOR id234 sexFgt
  • Relationship between elements
  • ltBOOKgtltTITLEgtlt/TITLEgtlt/BOOKgt
  • Different XML applications can use different DTDs
    to specify what they do and do not allow

Its Complex, but More Powerful
  • With DTD you can
  • Define your own meaningful tags
  • You can Validate whether your document is
    structure correct
  • An XML document is valid if it has an DTD and the
    document conforms with the DTD
  • The document type declaration must appear before
    the first element in an XML

Getting Started with DTD
  • 3-1.dtd, 3-1.txt
  • DTD can be stored in a separate file from the
    document it describes
  • DTD can be included inside the document it
  • DTDs allow forward, backward, and circular
    references to other declarations

Document Type Declaration
  • A valid document includes a reference to the DTD
    to which it should be compared
  • lt!DOCTYPE person SYSTEM "http//../person.dtd"gt
  • The root element is person
  • The DTD of this document can be found in
  • The document type declaration is included in the
    prolog of the XML document after the XML
    declaration but before the root element
  • You can use a relative URL (or just the filename)
    instead of the absolute form, if the document
    resides in the same server (or directory) as the

Internal DTD Subsets
  • DTD can be included inside the document it
  • 3-4.xml
  • Some document type declarations contain some
    declarations directly but link in others
  • The part of the DTD between the brackets is
    called the internal DTD subset
  • All the parts that come from outside this
    document are called the external DTD subsets
  • As a general rule, the two subsets must be
    compatible. Neither can override the element
    declarations the other makes
  • When you use an external DTD subset, you should
    give the standalone attribute of the XML
    declaration the value no

Internal and External DTD
  • Internal DTD Put DTD and XML in one file
  • lt!DOCTYPE RootElement lt!ELEMENT author

Element Declaration
  • DTD is a mechanism to describe every object
    (element, attribute,) that can appear in an XML
  • Element Declaration
  • lt!ELEMENT element-name content-specification gt
  • Content specification specifies what children the
    element may or must have in what order
  • lt!ELEMENT address-book (entry)gt
  • Parentheses are used to group elements in content
  • lt!ELEMENT name (lname, (fname title))gt

Special Keywords in Content Model
  • Special Keywords in Content Model
  • PCDATA parsed character data (text)
  • lt!ELEMENT phone_number (PCDATA)gt
  • CDATA sections appear anywhere PCDATA appears
  • EMPTY empty element
  • ANY can contain any other elements declared in
    the DTD (including mixed content, child elements)
  • Mixed Content
  • Element contents that have PCDATA
  • Element Content
  • Element contents that contain only elements

The Secret of , , ?
  • , , ? Occurrence indicators
  • No occurrence indicator appear once and only
  • appear one or several times
  • appear zero or more times
  • ? appear once or not at all
  • Example
  • lt!ELEMENT entry (name,address,tel,fax,email)gt
  • lt!ELEMENT address (street,region?,postal-code,loca

The Secret of ,
  • , Connectors
  • , Elements must appear in the same order
  • Only one element must appear
  • Examples
  • lt!ELEMENT name (PCDATA fname lname)gt
  • lt!ELEMENT entry (name,address,tel,fax,email)gt
  • Mixed Content Components must always separated
    by a , and the model must repeat
  • lt!ELEMENT name (PCDATA, fname, lname)gt
  • lt!ELEMENT name (PCDATA fname lname)gt
  • PCDATA must be the first child in the list

More Examples
  • lt!ELEMENT cover (title, (author subtitle))gt
  • lt!ELEMENT circle (center, (radius diameter))gt
  • lt!ELEMENT name (last_name (first_name,
    ((middle_name, last_name) (last_name?)))gt
  • lt!ELEMENT paragraph (PADATA name profession
    footnote emphasize date) gt
  • lt!ELEMENT image EMPTY)
  • ltimage source"bus.jpg" width"152" /gt

Attribute Declaration
  • Attribute Declaration
  • lt!ATTLIST element-name attribute-name
    attribute-type default-valuegt
  • lt!ATTLIST tel preferred (truefalse) falsegt
  • lt!ATTLIST email href CDATA REQUIRED
    preferred (truefalse) falsegt
  • Can appear anywhere in the DTD
  • Best to list attributes immediately after the
    element declaration

Attribute Type
  • CDATA String
  • ID Identifier unique in the document
  • IDREF Value of an ID
  • IDREFS List of IDREF separated by space
  • ENTITY Name of an external entity
  • NMTOKEN Word without spaces
  • Enumerated-type list Closed list of NMTOKEN
    separated by
  • Notation name of a notation declared in the DTD

Attribute Types (Cont.)
  • Any text string acceptable in a well-formed XML
    attribute value
  • The most general attribute type
  • Can be used for prices, URIs, email addresses,
  • NMTOKEN (named token)
  • Consist of the same characters as an XML name,
    but any allowed characters can be the first
    character in a name token
  • 12, .cshrc
  • one ore more XML name tokens separated by
  • ltperformances dates"08-21-2001 08-23-2001
    08-27-2001"gt Kat and the Kings lt/performancesgt

Attribute Types (Cont.)
  • Enumeration
  • A list of all possible values for the attribute,
    separated by
  • Each possible value must be an XML name token
  • lt!ATTLIST date year (2000 2001 2002 2003)
  • ID assign unique identifiers to elements
  • An XML name that is unique within the XML
    document (no other ID type attribute in the
    document can have the same value)
  • Each element must have no more than one ID type
  • lt!ATTLIST employee ssn ID REQUIREDgt
  • ltemploy ssn"_078-05_123" /gt

Attribute Types (Cont.)
  • Refer to the ID type attribute of some element in
    the document
  • Used to establish relationships between elements
    when simple containment won't suffice
  • 3-6.xml
  • Do not constrain the person attribute of the
    team_member element to match only employee IDs or
    constrain the project_id attribute of the
    assignment element to match only project IDs
  • Contain a whitespace-separated list of XML names,
    each of which must be the ID of an element in the

Attribute Types (Cont.)
  • Contain the name of an unparsed entity declared
    elsewhere in DTD
  • lt!ATTLIST move source ENTITY REQUIREDgt
  • ltmove source"X-Men-trailer" /gt
  • Contain the name of one ore more unparsed
    entities declared elsewhere in the DTD, separated
    by whitespace
  • lt!ATTLIST slide_show slides ENTITIES REQUIREDgt
  • ltslide_show slides"slide1 slide2 slide3 slide4 /gt

Attribute Types (Cont.)
  • Contain the name of a notation declared in the
    document's DTD
  • It could be used to associate types with
    particular elements, as well as limiting the
    types associated with the element
  • lt!NOTATION gif SYSTEM "image/gif"gt
  • lt!NOTATION tiff SYSTEM "image/tiff"gt
  • lt!NOTATION jpeg SYSTEM "image/jpeg"gt
  • lt!NOTATION png SYSTEM "image/png"gt
  • lt!ATTLIST image type NOTATION (gif tiff jpeg
    png) REQUIREDgt

Default Value
  • The attribute is required. Each instance of the
    element must provide a value for the attribute
  • No default value is provided
  • lt!ATTLIST person name CDATA REQUIREDgt
  • The attribute is optional. Each instance of the
    element may or may not provide a value for the
  • No default value is provided
  • lt!ATTLIST person born CDATA IMPLIEDgt

Default Value (Cont.)
  • FIXED (follow by a value)
  • The attribute value is constant and immutable.
    The attribute has the specified value regardless
    of whether the attribute is explicitly noted on
    an individual instance of the element
  • If it is included, it must have the specified
  • lt!ATTLIST biography xmlnsxlink CDATA FIXED
  • Literal Value
  • The attribute will take this value if no value is
    given in the document
  • lt!ATTLIST web_page protocol NMTOKEN "http"gt

General Entity Declaration
  • Replace texts in XML documents defined by the DTD
  • lt!ENTITY entity_name "replacement_text"gt
  • lt!ENTITY super "superman in the jungle"gt
  • super ? superman in the jungle

Limitation of DTD
  • Limitations of DTD
  • Content is limited to textual
  • Difficult to put in repetition constraints
  • DTD does not use XML syntax
  • DTD does not say the following
  • What the root element of the document is
  • How many of instances of each kind of element
    appear in the document
  • What the character data inside the elements looks
  • The semantic meaning of an element
  • A DTD never says anything about the length,
    structure, meaning, allowed values, or other
    aspects of the text content of an element

Advanced DTD
  • General Entity Declaration
  • External Parsed General Entities
  • External Unparsed Entities and Notations
  • Parameter Entities
  • Conditional Inclusion

  • A validating parser compares a document to its
    DTD and lists any places where the document
    differs from the constraints specified in the DTD
  • The parser can decide what it wants to do about
    any violations
  • A validity error is not necessarily a fatal error
  • Validation is an optional step in processing XML
  • Everything not permitted in the DTD is forbidden

Validating a Document
  • Online validating parsers
  • http//
  • http//
  • Validating parser software
  • Most XML parser class libraries include a simple
    program to validate documents
  • http//
  • http//