+ All Categories
Home > Documents > XML (2) DTD Sungchul Hong. Publish Magnus Gregory, Modified 13...

XML (2) DTD Sungchul Hong. Publish Magnus Gregory, Modified 13...

Date post: 12-Jan-2016
Category:
Upload: magnus-gregory
View: 212 times
Download: 0 times
Share this document with a friend
22
XML (2) DTD Sungchul Hong
Transcript
Page 1: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

XML (2)

DTD

Sungchul Hong

Page 2: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE simple [

<!ELEMENT DOCUMENT (#PCDATA)>

<!ATTLIST DOCUMENT

trackNum CDATA #REQUIRED

secLevel (unclassified|classified) "unclassified">

<!ENTITY Description "This is a very simple

sample document.">

]>

<DOCUMENT trackNum="1234">This is an entity inside

an element:&Description; </DOCUMENT>

Page 3: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Document Type Definition

• A DTD is used to validate an XML document.• Only one DTD per document• Document type declaration

– <!DOCTYPE name […]>

• XML documents– Well formed documents

• Document must comply with the XML specification.

– Valid documents• A valid document is a document that has a DTD and follows the

rule laid out in that DTD.

Page 4: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Document Type Declarations

• <! DOCTYPE JU:LunchMenu SYSTEM http://catering.com/menus/lunch/Menu.DTD>

• <!DOCTYPE JU:LunchMenu PUBLIC “/lunch/Menu.DTD”>

Page 5: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Internal DTD Subset

• A DTD can be declared internal to the XML document

• Internal subsets are parsed before external subsets

• Internal declarations that match external declarations will override the corresponding declarations.

Page 6: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE simple [

<!ELEMENT DOCUMENT (TITLE,AUTHOR+,SUMMARY*,NOTE?)>

<!ATTLIST DOCUMENT

trackNum CDATA #REQUIRED

secLevel (unclassified|classified) "unclassified">

<!ELEMENT TITLE (#PCDATA)>

<!ELEMENT AUTHOR (#PCDATA)>

<!ELEMENT SUMMARY (#PCDATA)>

<!ENTITY Description "This is a very simple sample document.">

]>

<DOCUMENT trackNum="1234">

<TITLE>Sample Document</TITLE>

<AUTHOR>Simon St.Laurent</AUTHOR>

<SUMMARY>This is an entity inside an element:&Description;

</SUMMARY></DOCUMENT>

Page 7: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

External DTD Subset

• The Document Type Declaration will now provide a URL and either a system or public identifier

• Provides more flexibility than internal DTD subsets

• <! DOCTYPE JU:LunchMenu SYSTEM http://catering.com/menus/lunch/Menu.DTD>

• <!DOCTYPE JU:LunchMenu PUBLIC “/lunch/Menu.DTD”>

Page 8: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

<?xml version="1.0" standalone="no""UTF-8"?> <!DOCTYPE SIMPLE SYSTEM "http://127.0.0.1/simple.dtd"> <SIMPLE><DOCUMENT trackNum="1234"> <TITLE>Sample Document</TITLE> <AUTHOR><FIRSTNAME>Simon</FIRSTNAME> <LASTNAME>St.Laurent</LASTNAME> <COMPANY>XML Mania</COMPANY></AUTHOR><SUMMARY>This is an entity inside an element:&Description; </SUMMARY></DOCUMENT></SIMPLE>

Page 9: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Elements

• <!ELEMENT name data>

• <!ELEMENT DOCUMENT (TITLE,AUTHOR+,SUMMARY*,NOTE?)>

• Declares what elements are legal, what order they should appear in and the number of elements

• Data can be one of five types: Empty, Elements-only, Characters-only, any and mixed.

Page 10: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Elements• Empty: the corresponding element cannot contain either text or other elements

– <!ELEMENT price EMPTY>• Element-only: the corresponding element can only contain other elements, no

text.– <!ELEMENT person (name, address, tel)>

• Characters-only: The corresponding element can contain only text– <!ELEMENT bookinfo (#PCDATA) >

• Any: the corresponding element can include any of previous three types– <!ELEMENT other ANY>

• Mixed: the corresponding element must have both elements and text– <!ELEMENT mixedup (e1, e2) (#PCDATA)>

Page 11: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Elements Syntax

• Content model– ( ): substructure– , : strict ordering– | : choice– ?: optional– *: zero or more of a particular item can appear.– +: The plus-sign (+) denotes that one or more of

a particular item can appear.

Page 12: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Example<!ELEMENT DOCUMENT

(TITLE,AUTHOR+,SUMMARY*,NOTE?)>

<!ELEMENT User (Name, Email | Phone))>

<!ELEMENT Blah (A, (B?, C)*, D+, (E|F)>

Page 13: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Attributes Syntax

• A DTD defines attributes with the <!ATTLIST …> declaration.

• <!ATTLIST element attribute CDATA #required>– #REQUIRED-the attribute must appear with this

element.– #IMLIED- the attribute may appear with this element.– #FIXED default value – the attribute must always have

the default value. If it does not appear explicitly, it is assumed.

– Default value – the attribute may appear with the default or can have another value.

Page 14: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Attribute Types

• CDATA – Character data. Used if an attribute value is only plain text.

• <!ATTLIST Order order_num CDATA #REQUIRED>

• <order order_num = “123abc”> … </order>

Page 15: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Attribute Types

• ID – unique name within a document used to uniquely identify an element.

• <!ATTLIST Order order_num ID #REQUIRED>

• <Order order_num = “123abc”> .. </order>

• <order order_num = “456def”> …</order>

Page 16: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Attribute Types• IDREF- A reference to an element with an ID,

allowing for links to b created within documents.

• <!ATTLIST Order order_num ID #REQUIRED>• <!ATTLIST ClosedOrder order_ref IDREF

#REQUIRED>• <Order order_num = “123abc”>… </Order>• <ClosedOrder order_ref = “123abc”/>

Page 17: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Attribute Types

• IDREFS – Series of references to elements with corresponding Ids

• <!ELEMENT ClosedOrders EMPTY>• <!ATTLIST Order order_num ID #REQUIRED>• <!ATTLIST ClosedOrders order_ref IDREFS

#REQUIRED>• <Order order_num = “123abc”>… </Order>• <Order order_num = “456def”>… </Order>• <ClosedOrders order_ref = “123abc 456def”/>

Page 18: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Enumerated Values

• Enumerated values are defined with not type definition.

• A parenthetical sequence of legal values is given instead

• Do not use quotation marks and remember the values are case sensitive

• <!ATTLIST JU:Dessert type (regular | lowfat | sugar-free) #REQUIRED>

• <JU:Dessert type = “lowfat”>Cheescake</JU:Dessert>

Page 19: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

NOTATION

• NOTATION- Identify the format of external data items that we wish to use with our XML document

• <!NOTATION gif SYSTM “imageviewer.exe”>

Page 20: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Entities

• Entities allow you t declare content and reference it anytime you need it within a document

• Entities are like an alias to some content

• Predefined entities &lt, &gt, &amp, &apos, &quote

Page 21: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE simple [

<!ELEMENT DOCUMENT (#PCDATA)>

<!ATTLIST DOCUMENT

trackNum CDATA #REQUIRED

secLevel (unclassified|classified) "unclassified">

<!ENTITY Description "This is a very simple

sample document.">

]>

<DOCUMENT trackNum="1234">This is an entity inside

an element:&Description; </DOCUMENT>

Page 22: XML (2) DTD Sungchul Hong.                                   Publish Magnus Gregory,  Modified 13 years ago

Problems With DTD

• DTD use a non-XML syntax.

• There is no way to type information like numbers

• DTDs do not allow merging of documents

• XML Schema


Recommended