1 / 17

Document Type Definition (DTD)

Document Type Definition (DTD). Eugenia Fernandez IUPUI. Why DTDs?. DTDs define the allowable structure for an XML document. A DTD defines a vocabulary for a particular type of XML document. DTDs are not required, but recommended to ensure document conformity.

odina
Download Presentation

Document Type Definition (DTD)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Document Type Definition(DTD) Eugenia Fernandez IUPUI

  2. Why DTDs? • DTDs define the allowable structure for an XML document. • A DTD defines a vocabulary for a particular type of XML document. • DTDs are not required, but recommended to ensure document conformity. • They are especially useful in business-to-business exchange. • Various industries have agreed upon a common vocabulary.

  3. Creating a DTD • A DTD describes every object (e.g. element, attribute) that can appear in an XML document. • It is a text file with a .dtd extension and can be created with any text editor: • Notepad • Visual Interdev • FrontPage

  4. Linking a DTD To attach a DTD to an XML document, add one of the following processing instructions: <!DOCTYPE dtdname SYSTEM “dtdfilename.dtd”> <!DOCTYPE dtdname PUBLIC “url”>

  5. What Can Be Validated: Structure • Elements • What elements are recognized? optional/required? • What are the relationships between elements? • How many child elements are allowed? What is their sequence? • What is the data type of each element? • Attributes • What attributes are recognized? optional/required? • What is the data type of each attribute? • Is there a restricted set of values for an attribute?

  6. Declaring Elements • Syntax • Content Specification • list of elements • #PCDATA • EMPTY • ANY <!ELEMENT element-name (entry+) > content specification

  7. Child Element List • When separated by commas • Elements must appear in the order given • Example • <!ELEMENT name (first, middle, last)> • Valid XML <name><first>Eugenia</first><middle/><last>Fernandez</last></name> • Invalid XML <name><last>Fernandez</last> <first>Eugenia</first><middle/></name>

  8. Child Element List • When separated by vertical bar (or pipe |) • Elements are mutually exclusive, only one must appear in the document • Example • <!ELEMENT name (#PCDATA | first | last)> • Valid XML <name><first>Eugenia</first></name> <name>Eugenia</name> • Invalid XML <name><last>Fernandez</last> <first>Eugenia</first> </name>

  9. Occurrence Indicator: + • plus, + • appears one or more times, i.e. element can repeat • Example • <!ELEMENT name (first, middle+, last)> • Valid XML <name><first>Eugenia</first><middle>Maria</middle><middle>Alicia</middle><last>Fernandez</last> </name> • Invalid XML <name><last>Fernandez</last> <first>Eugenia</first></name>

  10. Occurrence Indicator: * • asterisk, * • appears zero or more times, i.e. element is optional and can repeat • Example • <!ELEMENT name (first, middle*, last)> • Valid XML <name><first>Eugenia</first><last>Fernandez</last> </name> <name><first>Eugenia</first><middle>Maria</middle><middle>Alicia</middle><last>Fernandez</last> </name>

  11. Occurrence Indicator: ? • question mark, ? • appears zero or one times, i.e. element is optional and cannot repeat • Example • <!ELEMENT name (first, middle?, last)> • Valid XML <name><first>Eugenia</first><last>Fernandez</last> </name> • Invalid XML <name><first>Eugenia</first> <middle>Maria</middle><middle>Alicia</middle> <last>Fernandez</last></name>

  12. Declaring Attributes • Syntax • Can appear anywhere in DTD • Generally placed after the element declaration <!ATTLIST element-name attribute-name attribute-value default-value>

  13. Attribute Types • strings (CDATA) • enumerated e.g. (false | true) • tokenized • ID • IDREF • ENTITY • NMTOKEN

  14. Tokenized Attribute Types • Restricts the values used for attributes • ID • unique identifier for each element • IDREF/IDREFS • value of an ID elsewhere in document, used to create links within a document • ENTITY/ENTITIES • name of external entity, like &amp; for & • NMTOKEN/NMTOKENS • a word without spaces, used in enumerated values

  15. Default Values for Attributes • #REQUIRED • attribute value must be supplied • #IMPLIED • if no value is supplied, application uses its own default • #FIXED value • attribute value must match the one specified • a literal • attribute takes on this value if none supplied

  16. Entity Declarations • general or parameter • general entities act as shorthand or substitution macros like &gt; • parameter entities • internal or external • internal entities stored in the document • external entities point to system or public identifier • parsed or unparsed • parsed entities contain XML text and markup • unparsed entities used for non-XML content

  17. The End

More Related