Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
4Activity
0 of .
Results for:
No results containing your search query
P. 1
Lecture 2 DTD

Lecture 2 DTD

Ratings: (0)|Views: 30 |Likes:
Published by f_atencia

More info:

Published by: f_atencia on Jun 01, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

09/26/2010

pdf

text

original

 
1
DWAX 2010.11
Lecture 2 Week 2
Creating a Valid XML Document UsingDocument Type Definitions (DTDs)
DWAX 2010.12
Recap from last week
Information about a book:
 –Title, Author, Chapters
Decide on a way to structure the information, inthis case:
<?xml version="1.0"?><book><title>Web Applications</title><author>John Doe</author><chapters><chapter>Introduction</chapter><chapter>ASP</chapter><chapter>XML</chapter></chapters></book>
DWAX 2010.13
Parsers, Well-formed and Valid XMLDocuments
Parsers
 –Nonvalidating
Checks if document is well formed (contains no syntax errorsand conforms to the XML specifications)
 –Validating
Checks if document is well formedChecks if XML document is Valid (conforms to the rules setout in it’s DTD or Schema) –By definition, a valid document is also well formed
DWAX 2010.14
DTDs
Uses
Extended Backus-Naur Form 
(
EBNF 
) grammar
Used to define the structure of an XML document:
 –Ensure all required elements are present in the document –Prevent undefined elements from being used –Enforce a specific data structure –Specify the use of attributes and define their possible values –Define default values for attributes –Describe how the parser should access non-XML or non-textualcontent
 
2
DWAX 2010.15
Declaring a DTD
A document type
definition 
is a collection ofrules or declarations that define the content andstructure of the document.
A document type
declaration 
attaches thoserules to the document’s content.
DWAX 2010.16
Document Type Declaration
Document Type Declaration
 –Introduce DTDsinto XML documents –Placed in XML document’s prolog –Begins with ‘
<!DOCTYPE
andends with
>
 –Often referred to as the DOCTYPE declaration –Can point to
External subsets
 –Declarations outside document –Exist in different file –typically ending with
.dtd
extension
Internal subsets
 –Declarations inside document –Visible only within document in which it resides
DWAX 2010.17
Declaring an internal DTD
The DOCTYPE declaration for an internal subset is:
<!DOCTYPE
root 
[
declarations 
]>
Where
root 
is the name of the document’s root element,and
declarations 
are the statements that comprise theDTD.
DWAX 2010.18
Adding a Document Type Declaration
(Note: no definitions added yet, this is not valid)
<?xml version="1.0"?>
<!DOCTYPE book[]>
<book><title>Web Applications</title><author>John Doe</author><chapters><chapter>Introduction</chapter><chapter>ASP</chapter><chapter>XML</chapter></chapters></book>
 
3
DWAX 2010.19
Starting the Document Type Definition:Declaring Document Elements
Every 
element used in the document must be declared in the DTDfor the document to be valid.
An
element type declaration 
specifies the name of the elementand indicates what kind of content the element can contain.
The element declaration syntax is:
<!ELEMENT
element content-model 
>
Where
element 
is the element name and
content-model 
specifieswhat type of content the element contains.
DWAX 2010.110
Declaring Document Elements
The element name is case sensitive.
DTDs define five different types of element content:
 – 
Any elements
. No restrictions on the element’s content.
<!ELEMENT
element 
ANY>
 – 
Empty elements
. The element cannot store any content.
<!ELEMENT
element 
EMPTY>
 – 
Character data
. The element can only contain a text string.
<!ELEMENT
element 
(#PCDATA)>The keyword #PCDATA stands for “parsed-character data”and is any well-formed text string.
 – 
Elements
. The element can only contain child elements.
<!ELEMENT
element 
(
child elements 
)>
 – 
Mixed
. The element can contain both character data and childelements.
<!ELEMENT element (#PCDATA|child1|child2|…)*>The parent element can contain character data or any number of thespecified child elements, or it can contain no content at all.
DWAX 2010.111
Types of Element Content
The declaration
<!ELEMENT customer (phone)><!ELEMENT phone (#PCDATA)>
indicates the Customer element can only have one child, namedPhone. You cannot repeat the same child element more than oncewith this declaration. The phone element can only contain characterdata.
Valid XML markup could be:
<customer><phone>02 3333 4444</phone></customer>
DWAX 2010.112
Sequences
Sequences
 –Specify order in which elements occur –Comma (
,
) is used as delimiter
<!ELEMENT
element (child1, child2, …
)>
<classroom><teacher>1</teacher><student>20</student></classroom>
Defining the
classroom 
element in a DTD:
<!ELEMENT classroom (teacher, student)>
The order of the child elements in the XML file must match theorder defined in the element declaration

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->