You are previewing XML: Visual QuickStart Guide, Second Edition.

XML: Visual QuickStart Guide, Second Edition

Cover of XML: Visual QuickStart Guide, Second Edition by Kevin Howard Goldberg Published by Peachpit Press
  1. Copyright
    1. Dedication
  2. Foreword by Elizabeth Castro
  3. About the Author
  4. Thank You
  5. Image Copyrights
  6. Introduction
    1. What is XML?
    2. The Power of XML
    3. Extending XML
    4. XML in Practice
    5. About This Book
      1. A Guided Tour
      2. XML2e Companion Web Site
      3. From 2001 to 2008
    6. What This Book is Not
  7. 1. XML
    1. 1. Writing XML
      1. Tools for Writing XML
      2. An XML Sample
      3. Rules for Writing XML
      4. Elements, Attributes, and Values
      5. How To Begin
      6. Creating the Root Element
      7. Writing Child Elements
      8. Nesting Elements
      9. Adding Attributes
      10. Using Empty Elements
      11. Writing Comments
      12. Predefined Entities – Five Special Symbols
      13. Displaying Elements as Text
  8. 2. XSL
    1. 2. XSLT
      1. Transforming XML with XSLT
      2. Beginning an XSLT Style Sheet
      3. Creating the Root Template
      4. Outputting HTML
      5. Outputting Values
      6. Looping Over Nodes
      7. Processing Nodes Conditionally
      8. Adding Conditional Choices
      9. Sorting Nodes Before Processing
      10. Generating Output Attributes
      11. Creating and Applying Templates
    2. 3. XPath Patterns and Expressions
      1. Locating Nodes
      2. Determining the Current Node
      3. Referring to the Current Node
      4. Selecting a Node’s Children
      5. Selecting a Node’s Parent or Siblings
      6. Selecting a Node’s Attributes
      7. Conditionally Selecting Nodes
      8. Creating Absolute Location Paths
      9. Selecting All the Descendants
    3. 4. XPath Functions
      1. Comparing Two Values
      2. Testing the Position
      3. Multiplying, Dividing, Adding, Subtracting
      4. Counting Nodes
      5. Formatting Numbers
      6. Rounding Numbers
      7. Extracting Substrings
      8. Changing the Case of a String
      9. Totaling Values
      10. More XPath Functions
    4. 5. XSL-FO
      1. The Two Parts of an XSL-FO Document
      2. Creating an XSL-FO Document
      3. Creating and Styling Blocks of Page Content
      4. Adding Images
      5. Defining a Page Template
      6. Creating a Page Template Header
      7. Using XSLT to Create XSL-FO
      8. Inserting Page Breaks
      9. Outputting Page Content in Columns
      10. Adding a New Page Template
  9. 3. DTD
    1. 6. Creating a DTD
      1. Working with DTDs
      2. Defining an Element That Contains Text
      3. Defining an Empty Element
      4. Defining an Element That Contains a Child
      5. Defining an Element That Contains Children
      6. Defining How Many Occurrences
      7. Defining Choices
      8. Defining an Element That Contains Anything
      9. About Attributes
      10. Defining Attributes
      11. Defining Default Values
      12. Defining Attributes with Choices
      13. Defining Attributes with Unique Values
      14. Referencing Attributes with Unique Values
      15. Restricting Attributes to Valid XML Names
    2. 7. Entities and Notations in DTDs
      1. Creating a General Entity
      2. Using General Entities
      3. Creating an External General Entity
      4. Using External General Entities
      5. Creating Entities for Unparsed Content
      6. Embedding Unparsed Content
      7. Creating and Using Parameter Entities
      8. Creating an External Parameter Entity
    3. 8. Validation and Using DTDs
      1. Creating an External DTD
      2. Declaring an External DTD
      3. Declaring and Creating an Internal DTD
      4. Validating XML Documents Against a DTD
      5. Naming a Public External DTD
      6. Declaring a Public External DTD
      7. Pros and Cons of DTDs
  10. 4. XML Schema
    1. 9. XML Schema Basics
      1. Working with XML Schema
      2. Beginning a Simple XML Schema
      3. Associating an XML Schema with an XML Document
      4. Annotating Schemas
    2. 10. Defining Simple Types
      1. Defining a Simple Type Element
      2. Using Date and Time Types
      3. Using Number Types
      4. Predefining an Element’s Content
      5. Deriving Custom Simple Types
      6. Deriving Named Custom Types
      7. Specifying a Range of Acceptable Values
      8. Specifying a Set of Acceptable Values
      9. Limiting the Length of an Element
      10. Specifying a Pattern for an Element
      11. Limiting a Number’s Digits
      12. Deriving a List Type
      13. Deriving a Union Type
    3. 11. Defining Complex Types
      1. Complex Type Basics
      2. Deriving Anonymous Complex Types
      3. Deriving Named Complex Types
      4. Defining Complex Types That Contain Child Elements
      5. Requiring Child Elements to Appear in Sequence
      6. Allowing Child Elements to Appear in Any Order
      7. Creating a Set of Choices
      8. Defining Elements to Contain Only Text
      9. Defining Empty Elements
      10. Defining Elements with Mixed Content
      11. Deriving Complex Types from Existing Complex Types
      12. Referencing Globally Defined Elements
      13. Controlling How Many
      14. Defining Named Model Groups
      15. Referencing a Named Model Group
      16. Defining Attributes
      17. Requiring an Attribute
      18. Predefining an Attribute’s Content
      19. Defining Attribute Groups
      20. Referencing Attribute Groups
      21. Local and Global Definitions
  11. 5. Namespaces
    1. 12. XML Namespaces
      1. Designing a Namespace Name
      2. Declaring a Default Namespace
      3. Declaring a Namespace Name Prefix
      4. Labeling Elements with a Namespace Prefix
      5. How Namespaces Affect Attributes
    2. 13. Using XML Namespaces
      1. Populating an XML Namespace
      2. XML Schemas, XML Documents, and Namespaces
      3. Referencing XML Schema Components in Namespaces
      4. Namespaces and Validating XML
      5. Adding All Locally Defined Elements
      6. Adding Particular Locally Defined Elements
      7. XML Schemas in Multiple Files
      8. XML Schemas with Multiple Namespaces
      9. The Schema of Schemas as the Default
      10. Namespaces and DTDs
      11. XSLT and Namespaces
  12. 6. Recent W3C Recommendations
    1. 14. XSLT 2.0
      1. Extending XSLT
      2. Creating a Simplified Style Sheet
      3. Generating XHTML Output Documents
      4. Generating Multiple Output Documents
      5. Creating User Defined Functions
      6. Calling User Defined Functions
      7. Grouping Output Using Common Values
      8. Validating XSLT Output
    2. 15. XPath 2.0
      1. XPath 1.0 and XPath 2.0
      2. Averaging Values in a Sequence
      3. Finding the Minimum or Maximum Value
      4. Formatting Strings
      5. Testing Conditions
      6. Quantifying a Condition
      7. Removing Duplicate Items
      8. Looping Over Sequences
      9. Using Today’s Date and Time
      10. Writing Comments
      11. Processing Non-XML Input
    3. 16. XQuery 1.0
      1. XQuery 1.0 vs. XSLT 2.0
      2. Composing an XQuery Document
      3. Identifying an XML Source Document
      4. Using Path Expressions
      5. Writing FLWOR Expressions
      6. Testing with Conditional Expressions
      7. Joining Two Related Data Sources
      8. Creating and Calling User Defined Functions
      9. XQuery and Databases
  13. 7. XML in Practice
    1. 17. Ajax, RSS, SOAP, and More
      1. Ajax Basics
      2. Ajax Examples
      3. RSS Basics
      4. RSS Schema
      5. Extending RSS
      6. SOAP and Web Services
      7. SOAP Message Schema
      8. WSDL
      9. KML Basics
      10. A Simple KML File
      11. ODF and OOXML
      12. eBooks, ePub, and More
      13. Tools for XML in Practice
  14. Appendices
    1. A. XML Tools
      1. XML Editors
      2. Additional XML Editors
      3. XML Tools and Resources
    2. B. Character Sets and Entities
      1. Specifying the Character Encoding
      2. Using Numeric Character References
      3. Using Entity References
      4. Unicode Characters
O'Reilly logo

Chapter 8. Validation and Using DTDs

In the previous two chapters, you learned how to create DTDs. In this chapter, you’ll learn how to use them.

Specifically, a DTD defines rules for every element and attribute that can appear in an XML document. However, you must declare the DTD in your XML document in order to use it. Once this declaration is made, you can use various tools to validate the XML document against the DTD. This is the reason for creating a DTD in the first place, to insure that a given XML document is constructed in a specific way as defined by the DTD.

DTDs can be written and saved as separate files, or they can be written entirely inside an XML document. A benefit of writing internal DTDs is that there is only one file to manage ...

The best content for your career. Discover unlimited learning on demand for around $1/day.