XML StudySession: Part II - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

XML StudySession: Part II

Description:

Title To Kill a Mockingbird /Title Author Harper Lee /Author ... To define the allowed nestings within a DTD, the following notation is used: ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 23
Provided by: qkc
Category:

less

Transcript and Presenter's Notes

Title: XML StudySession: Part II


1
XML Study-Session Part II
  • Validating XML Documents

2
Objectives
  • By completing this study-session, you should be
    able to
  • Validate XML documents against a DTD.
  • Understand basic DTD syntax.
  • Create simple DTDs of your own.

3
What is a DTD?
  • Document Type Definition
  • Standard originally developed for SGML.
  • Provides a description of the XML documents
    structure, and serves as a grammar to specify
    what tags and attributes are valid in an XML
    document and in what context they are valid.
  • E.g. The following is an example DTD statement

4
Why use a DTD?
  • DTDs are used to allow an application to
    construct valid XML that conforms to that
    specification. Also
  • Self documentation
  • Portability
  • Provides defaults for attributes
  • Entity declaration

5
Using a DTD in an XML document
  • An XML document may do any of the following
  • Refer to a DTD, using its URI.
  • Include a DTD inline as part of the XML document.
  • Omit a DTD altogether. Without a DTD, an XML
    document can be checked for well-formedness, but
    not for validity.
  • The DTD used by the XML document may be internal
    or external. An external DTD is stored as an
    ASCII text .dtd file.

6
Example Using a DTD inline
  • ISBN CDATA REQUIRED
  • section (fictionnonfiction) fiction
  • To Kill a Mockingbird
  • Harper Lee
  • Description

7
Doctype declaration
  • The Document Type (Doctype) declaration is used
    to indicate the DTD used for the document.
    Syntax may be in any of the following forms

8
Example External DTD
  • The following is an example of an XML document
    that uses an external DTD
  • Moby Dick
  • Herman Melville
  • The external DTD must be located in the same
    directory as the XML document.

9
Example Using DTDs with URLS
  • The following is an example of an XML document
    that references an external DTD with an URL
  • ooklist.dtd
  • Moby Dick
  • Herman Melville

10
Specifying Elements
  • In the DTD, this is done with the notation
  • where elemName is the actual element name, and
    elemDefinitionOrType indicates whether the
    content of the content is pure data or a compound
    type of data and other elements.

11
Some Element Types
  • The element type keyword ANY allows the element
    to contain textual data, nested elements, or any
    legal XML combination of the two.
  • The element type keyword PCDATA indicates
    textual data, and can be used to store regular
    character data we want the XML document to handle
    normally.
  • The element type keyword EMPTY indicates that the
    element is always empty.

12
Nesting elements
  • To define the allowed nestings within a DTD, the
    following notation is used
  • where the order of elements is enforced as a
    validity constraint within an XML document.
  • By default, an element can appear exactly once
    when specified without any modifiers in the DTD.

13
Recurrence Operators
  • Recurrence operators can be used to indicate how
    many times an element must appear in an XML
    document

14
Grouping elements
  • Often, recurrence occurs for a block or group of
    elements rather than with a single element.
  • To signify a group, enclose a set of elements
    within parantheses. Nested parentheses are
    acceptable.
  • In this way, a recurrence operator can then be
    applied to the group.
  • E.g.
  • group1Elem2), (group2Elem1, group2Elem2)?)

15
Either Or
  • In the DTD, an OR operator is signified by
    using . This allows one thing or the other to
    occur, and can be used in conjunction with
    groupings.
  • E.g.
  • ent2)

16
Defining Attributes
  • Attribute definitions are in the following form
  • attributeType attributeModifier
  • The attributeType keyword CDATA allows an
    attribute to take on any value, and may represent
    a comment or additional information about an
    element.
  • Another attribute type is an enumeration, where
    any of the specified values may be used, but any
    other value for the attribute results in an
    invalid document.
  • E.g.
  • (value1value2) attributeModifier

17
Attribute Modifiers
  • We can indicate in the attribute definition
    whether the attribute is required within an
    element.
  • The three modifier keywords are IMPLIED,
    REQUIRED, and FIXED.
  • An implied attribute may be given a value, or
    left unspecified.
  • A required attribute must be given a value.
  • A fixed attribute has a specified value that can
    never change. The notation for this is
  • fixedValue

18
Parameter Entities in DTDs
  • Parameter entities are entities that can only be
    used in the DTD.
  • A simple internal parameter entity has the
    format
  • E.g.
  • Note?)
  • sum

19
Parameter Entities in DTDs (contd.)
  • External parameter entitites can be declared
    using the following
  • or
  • E.g. The following orders.dtd file could be
    created
  • XHTML 1.0 Transitional//EN http//www.w3.org/TR/x
    html1/DTD/xhtml1-transitional.dtd
  • XHTML1-t.dtd

20
Using INCLUDE and IGNORE
  • We can customize our DTDs using the INCLUDE and
    IGNORE statements, which have the following
    syntax
  • E.g. In the orders.dtd file, add the following
    lines
  • (same as before)

21
Example Using the XHTML 1.1 DTD
  • The XHTML 1.1 DTD is a DTD driver which includes
    various XHTML 1.1 modules (i.e. DTD sections)
    using parameter entities.
  • E.g.
  • -//W3C//ELEMENTS XHTML 1.1 Tables 1.0//EN
    xhtml11-table-1.mod
  • xhtml-table.mod
  • The above allows us to customize the XHTML 1.1
    DTD to include/exclude support for tables.

22
Next session
  • Parsing XML Documents
  • Parsing techniques
  • Writing your own XML applications
Write a Comment
User Comments (0)
About PowerShow.com