Element-Content Model:: Example
Element-Content Model:: Example
Element-Content Model:: Example
<!ATTLIST element-name
attribute-name
Example:
<! ELEMENT person (ssn, name, attribute-type
office, phone?) > default-
value>
<! ATTLIS person age CDATA #REQUIRED) >
The attribute-type can have the following values:
CDADA = string
ID = key
IDREF = foreign key
IDREFS = foreign keys
separated by space
(val | val | …) = enumeration
NMTOKEN = must be a valid XML
name
NMTOKENS = multiple valid XML
The default-value can have the following values:
names
ENTITY = entity
ENTITIES = a list of entities
NOTATION = a name of a notation
xml: = the value is
predefined
included in the
element
Example 1:
DTD example:
FIXED value
or The only value
<square width="100”/>
allowed
Example 2:
DTD example:
< !DOCTYPE family [
< !ELEMENT family (person)* >
< !ELEMENT person ( name ) >
< !ELEMENT name (#PCDATA) >
< !ATTLIST person id ID #REQUIRED
mother IDREF #IMPLIED
father IDREF #IMPLIED
children IDREFS #IMPLIED
]>
XML example:
<family>
<person id = “jane” mother = “mary” father = “john”>
<name> Jane Doe </name>
</person>
<person id = “john” children = “jane jack”>
<name> John Doe </name>
</person>
<person id = “mary” children = “jane jack”>
<name> Mary Smith </name>
</person>
<person id = “jack” mother = “smith” father = “john”>
<name> Jack Smith </name>
</person>
</family>
DTD – Entities
Entities
• Entities as variables used to define shortcuts to common text.
• Entity references are references to entities.
• Entities can be declared internal.
• Entities can be declared external.
Internal Entity Declaration
Syntax:
<!ENTITY entity-name "entity-
value">
DTD Example:
<!ENTITY writer "Jan Egil Refsnes.">
<!ENTITY copyright "Copyright
XML101.">
External Entity Declaration
Syntax:
<!ENTITY
XML entity-name SYSTEM
example:
"URL">
<author>&writer;©right;</aut
DTD Example:
hor> writer SYSTEM
<!ENTITY
"http://www.xml101.com/entities
/entities.xml">
<!ENTITY copyright SYSTEM
"http://www.xml101.com/entities
Entities: Entities as variables used to define common text. Entity references are references to
/entities.dtd">
entities.
XML example:
<author>&writer;©right;</aut
hor>
The following entities are predefined in XML:
Entity References | Character
------------------------------------
< <
> >
& &
" "
' '
Entities are expanded when a XML document is parsed by an XML parser.
DTD Validation
How to test for DTD errors while loading XML document?
Since DTD is the grammar for XML, XML is a parse tree of its DTD. Then we can use a XML
parser to check if the XML is valid.