Академический Документы
Профессиональный Документы
Культура Документы
• Types:
– Internal DTD
– External DTD
Internal DTD
• Syntax:
<!DOCTYPE root_element [
Document Type Definition (DTD):
elements/attributes/entities/notations/proce
ssing instructions/comments
]>
Example Internal DTD
<?xml version="1.0" standalone="yes" ?>
<!--open the DOCTYPE declaration - the open square bracket indicates an
internal DTD-->
<!DOCTYPE person [
• Syntax:
<!DOCTYPE root_element SYSTEM "DTD_location">
where:
DTD_location: relative or absolute URL
Example for Private external DTD
<Employee>
<eid>101</eid>
<name>kumar</name>
</Employee>
Example contd…
The external DTD (“employee.dtd") referenced in the example
contains information about the XML document's structure:
• Syntax:
• These are intended for broad use. The "DTD_location" is used to find
the public DTD if it cannot be located by the "DTD_name".
where:
DTD_location: relative or absolute URL
DTD_name: follows the syntax
"prefix//owner_of_the_DTD//description_of_the_DTD//ISO
639_language_identifier“
Example for Public External DTD
<?xml version="1.0" standalone="no" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD> <TITLE>A typical HTML file</TITLE> </HEAD>
<BODY> This is the typical structure of an HTML file.
It follows the notation of the HTML 4.0 specification, including tags
that have been deprecated (hence the "transitional" label).
</BODY>
</HTML>
prefixes
• The following prefixes are allowed in the DTD name:
Prefix Definition
ISO The DTD is an ISO standard. All ISO standards are
approved.
+ The DTD is an approved non-ISO standard.
- The DTD is an unapproved non-ISO standard.
Element Type Declaration
• set the rules for the type and number of elements
that may appear in an XML document
syntax:
<!ELEMENT name allowable_contents>
• The name in the element type's end tag must match the
name in the element type's start tag . Element names
are case sensitive.
Rules:
All of the children elements must be declared in a separate
element type declaration
<!ELEMENT name allowable_contents>
Allowable
contents Definition
<!--the elements listed below may only contain text that is not markup--
>
<!ELEMENT id (#PCDATA)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
]>
<student>
<id>9216735</id> <surname>Smith</surname>
<firstname>Jo</firstname>
</student>
Declaring optional children
syntax:
<!ELEMENT parent_name (child_name?)>
<!ELEMENT child's_name allowable_contents>
Rules:
If the child element is used in the XML document it must
be declared in a separate element type declaration
Example
<?xml version="1.0"?>
<!DOCTYPE student [
<!--'student' can have zero or one child element of type 'dob'-->
<!ELEMENT student (id,dob?)>
<!ELEMENT id (#PCDATA)>
<!ELEMENT dob (#PCDATA)>
]>
<student>
<id>ECE06117</id>
</student>
Declaring zero or more children
<?xml version="1.0"?>
<!DOCTYPE student [
<!ELEMENT student (subject*)>
<!ELEMENT subject (#PCDATA)> ]>
<student>
<subject>Mathematics</subject>
<subject>Physics</subject>
<subject>Chemistry</subject>
</student>
Declaring One or More children
One or more children are declared using the (+) operator.
<student>
<surname>Smith</surname>
<firstname>
<fullname>Josephine</fullname>
<nickname>Jo</nickname>
</firstname>
</student>
Mixed Content
Rules:
•(#PCDATA) must come first in the mixed content declaration .
•The operator (*) must follow the mixed content declaration if
children elements are included
Example 1
<?xml version="1.0"?>
<!DOCTYPE student [
<!ELEMENT student (#PCDATA|id)*>
<!ELEMENT id (#PCDATA)>
]>
<student>
Here's a bit of text mixed up with the child
element. <id>9216735</id>
You can put text anywhere, before or
after the child element. You don't even have to include the 'id'
element.
</student>
Example 2
<?xml version="1.0"?>
<!DOCTYPE student [
<!ELEMENT student (#PCDATA|id|surname|dob)*>
<!ELEMENT id (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
<!ELEMENT dob (#PCDATA)> ]>
<student>
You can put text anywhere. You can also put the elements
in any order in the document.
<surname>Smith</surname>
And, you don't have to include all the elements listed in
the element declaration.
<id>9216735</id>
</student>
Attribute List Declarations
• Attributes are additional information associated with an
element type.
•The ATTLIST declaration identifies
• type of attribute
• default value
• element types
syntax:
<!ATTLIST element_name attribute_name
attribute_type default_value> . . .
<element attribute_name="attribute_value">
Rules:
•Attributes may only appear in start or empty tags .
•The keyword ATTLIST must be in upper case
Example
<?xml version="1.0"?>
<!DOCTYPE image
[ <!ELEMENT image
EMPTY>
<!ATTLIST image height CDATA #REQUIRED>
<!ATTLIST image width CDATA #REQUIRED>
]>
<image height="32"
width="32"/>
Attribute types
Character data
<?xml version="1.0"?>
<!DOCTYPE image [
<!ELEMENT image EMPTY>
<!ATTLIST image height CDATA #REQUIRED>
<!ATTLIST image width CDATA #REQUIRED> ]>
<image height="32" width="32"/>
Example
<?xml version="1.0"?>
<!DOCTYPE student_name
[ <!ELEMENT student_name
(#PCDATA)> <!ATTLIST student_name
student_no ID #REQUIRED> ]>
<student_name student_no="a9216735">Jo
Smith</student_name>
IDREF
<name>"kumar"</name>
INTERNAL (PARSED) GENERAL ENTITY