0% found this document useful (0 votes)
5 views1 page

DTD Cheet Sheet

Uploaded by

cokegplays
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

DTD Cheet Sheet

Uploaded by

cokegplays
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DTDs for XML Cheat Sheet

What is XML? What is a DTD?

XML A flexible text format used to store and DTD Defines the structure and rules for an XML
(eXten​sible transport data, designed to be both (Document document.
Markup human-​rea​dable and machin​e-r​eadable Type It ensures that the XML follows a specific schema.
Language) Defini​tion)
Key features Platfo​rm-​ind​epe​ndent Key features Elements
Designed for inform​ation exchange Attributes
Hierar​chical structure with custom tags Entities

1. DTD Declar​ation 2. Element Declar​ations

External DTD file: <!ELEMENT element_name (content)>


<!D​OCTYPE root_e​lement SYSTEM "​
fil​
e.d​td"> LEMENT elemen​t_name EMPTY>
<!E​
Internal DTD file: Example with sub-el​
ements:
<!D​
OCTYPE root_e​
lement [ <!E​
LEMENT candy_​types (choco​
late, gummy,
​ ​<!-- DTD declar​
ations go here --> hard_c​and​y)>
]> Example with text content:
<!E​
LEMENT descri​
ption (#PCDA​
TA)>
SYSTEM: Points to an external DTD file.
EMPTY: If the element has no content
Root Element & Hierarchy PCDATA : Parsed Character Data is text that will be parsed by the

Every XML document has one root element that holds the entire XML parser. Tags inside are treated as markup and entities will be

structure. expanded.
CDATA: (Unparsed) Character data is text which is not parsed
LEMENT candy_​
<!E​ store (categ​ _ch​
ory​ oco​late,
further in an XML document.
ry_​
catego​ gum​
my?​
)>
Tags inside are not treated as markup and entities will not be
expanded.
Entities

&amp; & Attributes

&lt; < <!A​ ute​


t_name attrib​
TTLIST elemen​ _name type status>
&gt; >
&apos; ' Status:

&quot; " #REQUIRED must be present

<!E​
NTITY copy "​Cop
​yright SweetWorld 2023"> #IMPLIED optional
Called in the XML document with &copy;. #FIXED fixed value
Types: CDATA (any character string)
Parameter Entities
Enumer​ations (prede​fined values)
Reusable defini​tions within a DTD.
Example:
Allows complex content to be reused in multiple elements. <!A​
TTLIST candy chocol​ate​_flavor CDATA #REQUIRED
NTITY % product "​(price, manufa​
<!E​ ctu​
rer?, images?, sugar_content CDATA #REQUI​RED>
ption?, nutrit​
descri​ ion​al_
​inf​o?)​">

<!E​LEMENT chocol​ate_bar %produ​ct;> Attrib​utes: chocol​ate​_fl​avor, sugar_​content


Element: candy

Element Occurrence

? Optional, zero or one occurrence


* Optional, zero, one, or more occurr​ences
+ At least one occurrence
, Elements must appear in the given order
| Either one element or the other

LEMENT nutrit​
<!E​ ion​al_info (calor​
ies?, fat_content?,
sugar_​con​
ten​t?)>

Calories, fat_co​ntent, and sugar_​content are optional.

You might also like