• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Document type definitions part 1

Document type definitions part 1






Total Views
Views on SlideShare
Embed Views



1 Embed 174

http://angel.spscc.edu 174


Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Document type definitions part 1 Document type definitions part 1 Presentation Transcript

    • Document Type Definitions - Overview
    • DTD stands for Document Type Definition
      Allows an XML document to go further than meeting the requirements of being well-formed
      Specifies requirements to be valid
      A valid XML document matches definitions of allowable elements, attributes
      DTD Overview
    • Validation can be done in code (i.e. using javascript, VB and DOM)
      DTD’s allow use of a validating parser that compares the document against specifications
      Typically makes application changes and maintenance easier
      Less tied to a particular programming language/environment
    • Declarations are used to specify document requirements
      Document type declaration
      Element declaration
      Attribute List declaration
      Entity declaration
    • Includes name of root element
      Allows specification of where the DTD is located
      DTD can be embedded in the XML file (local)
      DTD can refer to external file, Uniform Resource Identifier (URI)
      Local takes precedence over external
      Document Type Declaration
    • Element Declaration has 3 parts:
      Element name
      Element content
      Element content can include a list of child elements or data
      Element Declaration
    • DTD included in XML document
      Definition of a student:
      <!DOCTYPE student[
      <!ELEMENT student(first, last, studentID)>
      <!ELEMENT first (#PCDATA)>
      <!ELEMENT last(#PCDATA)>
      <ELEMENT studentID(#PCDATA)>
      Document Type Declaration
      Element Declaration
      A student element is made up of first name, last name, and student id elements
    • DTD exists in external file/location
      Must use keyword to specify type of location
      SYSTEM is a reference to local file system
      PUBLIC is reference to DTD accessed through a catalog
      Can use both together
      If can’t find catalog reference can use specified file
      External Definition
    • Reference in XML file:
      <!DOCTYPE student SYSTEM “student.dtd”>
      External file:
      <!ELEMENT student(first, last, studentID)>
      <!ELEMENT first (#PCDATA)>
      <!ELEMENT last(#PCDATA)>
      <ELEMENT studentID(#PCDATA)>
      Sample External Definition
      Document Type Declaration
      Element Declaration
    • Element name must match name in XML document
      If using namespaces, prefixes must match
      Content Model defines what the element can store
      An element
      Mixed (i.e. data and element)
      Working With Elements
    • One element can contain another
      Can specify the elements contained by sequence
      Can specify the elements contained as a choice
      Element Content
    • Error raised if an element is missing
      Error raised if there are extra elements
      Error raised if elements in a different order
      For a student, our content must be in firstname, lastname, studentID order
      If find an element “major”, error
      If order varies, error
      If missing first, last, or studentID, error
      Content by Sequence
    • Can allow content to vary between elements
      | (vertical bar or pipe) indicates OR
      If add a Grade element to a student that can be a letter or percent:
      <!ELEMENT grade (letter | percent)>
      <!ELEMENT letter (#PCDATA)>
      <!ELEMENT percent (#PCDATA)
      Indicates that must have letter or percent element
      Content by Choice
    • A name may be a full name (first, middle, last) or just first and last:
      <!ELEMENT name (fullName | (first, last))>
      <!ELEMENT fullName (first, middle, last)>
      <!ELEMENT first (#PCDATA)>
      <!ELEMENT middle (#PCDATA)>
      <!ELEMENT last (#PCDATA)>
      By Choice: Example
    • Allows combination of elements and parsed character data
      Can include additional information within an element, eg. how to display
      Managed by using Choice (or)
      PCDATA must appear first in list of elements
      List cannot include inner content model (only simple elements)
      If there are child elements, include *
      * Indicates that may appear zero or more times
      Mixed Content
    • If want to include emphasis with the letter grade
      Data: <letter><em>4</em></letter>
      <!ELEMENT letter (#PCDATA | em)*>
      Describes a letter element as the content (pcdata) plus emphasis element
      Mixed Content -2
    • An element can be empty
      <br /> (never has child, content)
      Declaration includes EMPTY:
      <!ELEMENT br EMPTY>
      Means that the element CANNOT contain content
      Empty Content
    • An element can contain any kind of value (or be empty)
      Any elements declared in the DTD can occur, any number of times
      Only elements that are part of the DTD can be part of the document!
      May be empty
      May contain PCDATA
      Least restrictive model
      Any Content