08-dtd - DTDs XML and DTDs A DTD(Document Type Definition...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
Apr 23, 2009 DTDs
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
XML and DTDs A DTD ( Document Type Definition ) describes the structure of one or more XML documents. Specifically, a DTD describes: Elements Attributes, and Entities (We will discuss each of these in turn) An XML document is well-structured if it follows certain simple syntactic rules An XML document is valid if it also specifies and conforms to a DTD
Background image of page 2
Why DTDs? XML documents are designed to be processed by computer programs If you can put just any tags in an XML document, it’s very hard to write a program that knows how to process the tags A DTD specifies what tags may occur, when they may occur, and what attributes they may (or must) have A DTD allows the XML document to be verified (shown to be legal) A DTD that is shared across groups allows the groups to produce consistent XML documents
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Parsers An XML parser is an API that reads the content of an XML document Currently popular APIs are DOM ( D ocument O bject M odel ) and SAX ( S imple A PI for X ML ) A validating parser is an XML parser that compares the XML document to a DTD and reports any errors Most browsers don’t use validating parsers
Background image of page 4
An XML example   <novel>      <foreword>          <paragraph> This is the great American novel. </ paragraph>     </foreword>      <chapter number="1">          <paragraph> It was a dark and stormy night. </paragraph>          <paragraph> Suddenly, a shot rang out! </paragraph>     </chapter> </novel> An XML document contains (and the DTD describes): Elements, such as novel and paragraph , consisting of tags and content Attributes, such as number="1" , consisting of a name and a value Entities (not used in this example)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A DTD example   <!DOCTYPE novel [    <!ELEMENT novel (foreword, chapter+)>    <!ELEMENT foreword (paragraph+)>    <!ELEMENT chapter (paragraph+)>    <!ELEMENT paragraph (#PCDATA)>    <!ATTLIST chapter number CDATA #REQUIRED> ]> A novel consists of a foreword and one or more  chapter s, in that order Each chapter must have a number attribute A foreword consists of one or more paragraph s A chapter also consists of one or more paragraph s A paragraph consists of parsed character data (text that cannot contain any other elements)
Background image of page 6
ELEMENT descriptions Suffixes:   ? optional foreword?   + one or more chapter+   * zero or more appendix* Separators   , both, in order foreword?, chapter+   | or section|chapter Grouping   ( ) grouping (section|chapter)+
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Elements without children The syntax is   <!ELEMENT   name   category > The name is the element name used in start and end tags The category may be EMPTY : In the DTD: <!ELEMENT br EMPTY> In the XML: <br></br> or just
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/02/2011 for the course AR 107 taught by Professor Gracegraham during the Fall '11 term at Montgomery College.

Page1 / 26

08-dtd - DTDs XML and DTDs A DTD(Document Type Definition...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online