Professional Documents
Culture Documents
0> <course startdate=February 06, 2006> <title> eXtensible Markup Language </title> <lecturer>Phan Vo Minh Thang</lecturer> </course>
Different XML applications can use different DTDs to specify what they do and do not allow
eXtensible Markup Language
An XML document is valid if it has an DTD and the document conforms with the DTD The document type declaration must appear before the first element in an XML
The document type declaration is included in the prolog of the XML document after the XML declaration but before the root element You can use a relative URL (or just the filename) instead of the absolute form, if the document resides in the same server (or directory) as the DTD
DOCTYPE Declaration
<!DOCTYPE root_element source location [ internal DTD ]>
Starts with <! to signify a declaration and ends with > Must include DOCTYPE keyword and root_element One of two source keywords PUBLIC or SYSTEM One or two location1 location2 to associate a DTD Internal DTD may be included within [ internal DTD ]
When you use an external DTD subset, you should give the standalone attribute of the XML declaration the value no
DOCTYPE examples
<!DOCTYPE BookCatalog SYSTEM http://www.wrox.com/DTDs/BookCatalog.dtd>
Element Declaration
DTD is a mechanism to describe every object (element, attribute,) that can appear in an XML document Element Declaration
<!ELEMENT element-name content-specification >
Content specification specifies what children the element may or must have in what order
<!ELEMENT address-book (entry+)>
EMPTY: empty element ANY: can contain any other elements declared in the DTD (including mixed content, child elements)
Mixed Content
Element contents that have #PCDATA
Element Content
Element contents that contain only elements
eXtensible Markup Language
The Secret of +, *, ?
+, *, ?: Occurrence indicators
No occurrence indicator: appear once and only once +: appear one or several times *: appear zero or more times ?: appear once or not at all
Example
<!ELEMENT entry (name,address*,tel*,fax*,email*)> <!ELEMENT address (street,region?,postal-code,locality,country)>
The Secret of , |
, | : Connectors
, : Elements must appear in the same order | : Only one element must appear
Examples
<!ELEMENT name (#PCDATA | fname | lname)*> <!ELEMENT entry (name,address*,tel*,fax*,email*)>
Mixed Content: Components must always separated by a |, and the model must repeat
<!ELEMENT name (#PCDATA, fname, lname)> <!ELEMENT name (#PCDATA | fname | lname)*>
PCDATA must be the first child in the list
eXtensible Markup Language
Lecturer: Phan Vo Minh Thang MSc.
More Examples
<!ELEMENT cover (title, (author | subtitle))> <!ELEMENT circle (center, (radius | diameter))> <!ELEMENT name (last_name | (first_name, ((middle_name+, last_name) | (last_name?)))> <!ELEMENT paragraph (#PADATA | name | profession | footnote | emphasize | date)* > <!ELEMENT image EMPTY)
<image source="bus.jpg" width="152" />
Attribute Declaration
Attribute Declaration
<!ATTLIST element-name attribute-name attribute-type defaultvalue>
<!ATTLIST tel preferred (true|false) false> <!ATTLIST email href CDATA #REQUIRED preferred (true|false) false>
Attribute Type
CDATA: String ID: Identifier unique in the document IDREF: Value of an ID IDREFS: List of IDREF separated by space ENTITY: Name of an external entity ENTITIES: List of ENTITY NMTOKEN: Word without spaces NMTOKENS: List of NMTOKEN Enumerated-type list: Closed list of NMTOKEN separated by | Notation: name of a notation declared in the DTD
eXtensible Markup Language
Lecturer: Phan Vo Minh Thang MSc.
NMTOKENS
one ore more XML name tokens separated by whitespace <performances dates="08-21-2001 08-23-2001 08-27-2001"> Kat and the Kings </performances>
eXtensible Markup Language
IDREFS
Contain a whitespace-separated list of XML names, each of which must be the ID of an element in the document
ENTITIES
Contain the name of one ore more unparsed entities declared elsewhere in the DTD, separated by whitespace <!ATTLIST slide_show slides ENTITIES #REQUIRED>
<slide_show slides="slide1 slide2 slide3 slide4 />
Default Value
#REQUIRED
The attribute is required. Each instance of the element must provide a value for the attribute No default value is provided <!ATTLIST person name CDATA #REQUIRED>
#IMPLIED
The attribute is optional. Each instance of the element may or may not provide a value for the attribute No default value is provided <!ATTLIST person born CDATA #IMPLIED>
Literal Value
The attribute will take this value if no value is given in the document <!ATTLIST web_page protocol NMTOKEN "http">
Limitation of DTD
Limitations of DTD
Content is limited to textual Difficult to put in repetition constraints DTD does not use XML syntax
Advanced DTD
General Entity Declaration External Parsed General Entities External Unparsed Entities and Notations Parameter Entities Conditional Inclusion
Validation
A validating parser compares a document to its DTD and lists any places where the document differs from the constraints specified in the DTD
The parser can decide what it wants to do about any violations
A validity error is not necessarily a fatal error
Validating a Document
Web browsers do not validate documents but only check them for well-formedness Online validating parsers
http://www.stg.brown.edu/service/xmlvalid http://www.cogsci.ed.ac.uk/%7Erichard/xml-check.html
Info
Course name: