XML DTD (Document Type Definition) uses several building blocks to define the structure, content, and rules for XML documents. These building blocks include elements, attributes, entities, and notations. Here’s a simple explanation of each with examples:
<!ELEMENT>
)Elements define the structure of XML documents, specifying what elements can appear, their content model (child elements), and order.
Example:
Example
<!ELEMENT book (title, author, genre, price)>
book
element with child elements title
, author
, genre
, and price
.<!ATTLIST>
)Attributes provide additional information about elements, such as metadata or properties.
Example:
Example
<!ATTLIST person id ID #IMPLIED>
id
attribute for the person
element of type ID
, which is optional (#IMPLIED
).<!ENTITY>
)Entities define reusable text fragments or symbols within XML documents, helping to manage and reuse data.
Example:
Example
<!ENTITY greeting "Hello, World!">
greeting
with the value "Hello, World!"
.<!NOTATION>
)Notations define the format of non-XML data referenced within an XML document, such as images or multimedia files.
Example:
Example
<!NOTATION GIF SYSTEM "image/gif">
GIF
for handling image/gif
files.Here’s an example combining these building blocks to define a simple XML structure:
Example
<!DOCTYPE library [ <!ELEMENT library (book*)> <!ELEMENT book (title, author, genre, price)> <!ELEMENT title (#PCDATA)> <!ELEMENT author (#PCDATA)> <!ELEMENT genre (#PCDATA)> <!ELEMENT price (#PCDATA)> <!ATTLIST book id ID #IMPLIED> <!ATTLIST book availability (InStock|OutOfStock) "InStock"> <!ENTITY welcome "Welcome to our library!"> <!NOTATION GIF SYSTEM "image/gif"> ]> <library> <book id="001" availability="InStock"> <title>Harry Potter and the Philosopher's Stone</title> <author>J.K. Rowling</author> <genre>Fantasy</genre> <price>10.99</price> </book> <book id="002" availability="OutOfStock"> <title>The Catcher in the Rye</title> <author>J.D. Salinger</author> <genre>Novel</genre> <price>8.99</price> </book> </library>
library
can contain multiple book
elements, each with title
, author
, genre
, and price
child elements.book
elements can have id
and availability
attributes.welcome
with the text "Welcome to our library!".GIF
for handling image/gif
files.In summary, XML DTD building blocks provide a comprehensive framework for defining the structure, content, and rules of XML documents, enhancing their flexibility, interoperability, and data management capabilities.