Presentation is loading. Please wait.

Presentation is loading. Please wait.

DTD Document Type Definition. Agenda Introduction to DTD DTD Building Blocks DTD Elements DTD Attributes DTD Entities DTD Exercises DTD Q&A.

Similar presentations


Presentation on theme: "DTD Document Type Definition. Agenda Introduction to DTD DTD Building Blocks DTD Elements DTD Attributes DTD Entities DTD Exercises DTD Q&A."— Presentation transcript:

1 DTD Document Type Definition

2 Agenda Introduction to DTD DTD Building Blocks DTD Elements DTD Attributes DTD Entities DTD Exercises DTD Q&A

3 Introduction to DTD What is DTD?  DTD stands for Document Type Definition  DTD is a schema specification method for XML documents.  DTD states what elements and attributes are used to describe content in an XML document, where each element is allowed, and which elements can appear within other elements.

4 Introduction to DTD Why use a DTD?  Each of your XML files can carry a description of its own format.  Independent groups of people can agree to use a standard DTD for interchanging data.  Application can use a standard DTD to verify that the data you receive from the outside world is valid.

5 Introduction to DTD Internal DTD Declaration  A DTD which declare inside an XML document call inline DTD declaration.  It should be wrapped in a DOCTYPE definition. <!DOCTYPE root-element [ element-declarations ]> <!DOCTYPE note [ ]> Welcome to the DTD world

6 Introduction to DTD External DTD Declaration  A DTD which declare in an external file (.dtd file) and call it inside an XML document. Welcome to the DTD world

7 DTD Building Blocks Building blocks in an XML document  Elements Elements are the main building blocks of both XML and HTML documents.  Attributes Attributes provide extra information about elements.  Entities Special characters in XML  PCDATA PCDATA is text that WILL be parsed by a parser.  CDATA CDATA is text that will NOT be parsed by a parser.

8 DTD Elements Declaring Elements  In DTD, elements are declared with an ELEMENT declaration. or Empty Elements  Empty elements are declared with the category keyword EMPTY. Example: XML example:

9 DTD Elements Elements with Parsed Character Data  Elements with only parsed character data are declared with #PCDATA inside parentheses. Example: PCDATA - Parsed Character Data  PCDATA is text that WILL be parsed by a parser.  The text will be examined by the parser for entities and markup.

10 DTD Elements Elements with any Contents  Elements declared with the category keyword ANY, can contain any combination of parsable data Example: Elements with sub-elements (Children)  Elements with one or more children are declared with the name of the children elements inside parentheses or Example:

11 DTD Elements Declaring Only One Occurrence of an Element  The + sign in the example bellow declares that the child element "message" must occur one or more times inside the "note" element Example: Declaring Zero or More Occurrences of an Element  The * sign in the example bellow declares that the child element "message" can occur zero or more times inside the "note" element. Example:

12 DTD Elements Declaring Zero or One Occurrences of an Element  The ? sign in the example bellow declares that the child element "message" can occur zero or one time inside the "note" element. Example: Declaring either/or Content  The example bellow declares that the "note" element must contain a "to" element, a "from" element, a "header" element, and either a "message" or a "body" element. Example:

13 DTD Elements Declaring Mixed Content  The example above declares that the "note" element can contain zero or more occurrences of parsed character data, "to", "from", "header", or "message" elements. Example:

14 DTD Elements DescriptionSyntax Empty Elements Elements with Parsed Character Data Elements with any Contents Elements with Children or Declaring Only One Occurrence Declaring Minimum One Occurrence + Declaring Zero or More Occurrences * Declaring Zero or One Occurrences ? Declaring either/or Content |

15 DTD Attributes Declaring Attributes  In a DTD, attributes are declared with an ATTLIST declaration. DTD example: XML example:

16 DTD Attributes attribute-type TypeDescription CDATAThe value is character data (en1|en2|..)The value must be one from an enumerated list IDThe value is a unique id IDREFThe value is the id of another element IDREFSThe value is a list of other ids NMTOKENThe value is a valid XML name NMTOKENSThe value is a list of valid XML names ENTITYThe value is an entity ENTITIESThe value is a list of entities NOTATIONThe value is a name of a notation xml:The value is a predefined xml value

17 DTD Attributes default-value ValueExplanation valueThe default value of the attribute #REQUIREDThe attribute is required #IMPLIEDThe attribute is not required #FIXED valueThe attribute value is fixed

18 DTD Attributes A Default Attribute Value DTD: Valid XML:  If no width is specified, it has a default value of 0.

19 DTD Attributes #REQUIRED  Use the #REQUIRED keyword if you don't have an option for a default value, but still want to force the attribute to be present. DTD: Valid XML: Invalid XML:

20 DTD Attributes #IMPLIED  Use the #IMPLIED keyword if you don't want to force the author to include an attribute, and you don't have an option for a default value. DTD: Valid XML: Valid XML:

21 DTD Attributes #FIXED  Use the #FIXED keyword when you want an attribute to have a fixed value without allowing the author to change it.  If an author includes another value, the XML parser will return an error. DTD: Valid XML: Invalid XML:

22 DTD Attributes Enumerated Attribute Values  Use enumerated attribute values when you want the attribute value to be one of a fixed set of legal values. DTD: XML example: or

23 DTD Entities Entities are variables used to define shortcuts to standard text or special characters. Entity references are references to entities Entities can be declared internal or external An entity has three parts: an ampersand (&), an entity name, and a semicolon (;).

24 DTD Entities An Internal Entity Declaration DTD Example: XML example: &writer;&copyright; An External Entity Declaration DTD Example: <!ENTITY writer SYSTEM "http://www.w3schools.com/entities.dtd"> <!ENTITY copyright SYSTEM "http://www.w3schools.com/entities.dtd"> XML example: &writer;&copyright;

25 DTD Exercises Write an XML document for following DTD.  Note: Consider this DTD as an external DTD.

26 DTD Exercises Write a DTD for following XML document. Computer Parts Motherboard ASUS P3B-F 123.00 Video Card ATI All-in-Wonder Pro 160.00

27 DTD Q&A


Download ppt "DTD Document Type Definition. Agenda Introduction to DTD DTD Building Blocks DTD Elements DTD Attributes DTD Entities DTD Exercises DTD Q&A."

Similar presentations


Ads by Google