Lecture6 XML Dtd
Lecture6 XML Dtd
Lecture6 XML Dtd
• XML uses a tag-based syntax similar to HTML, but unlike HTML, which is used
for displaying information on web pages, XML is used to describe and
structure data. XML documents can contain data in a hierarchical structure,
where each piece of data is enclosed in tags that define its type and
relationship to other data.
• XML is widely used for data interchange between different systems and
platforms. It is often used in web services, configuration files, and data
storage formats where data needs to be structured and standardized for easy
processing and sharing.
What is DTD?
• DTD stands for Document Type Definition. It
defines a leading building block of an XML
document. It defines:
• Names of elements
• How and where they can be used
• Element attributes
• Proper nesting
What is DTD?
• DTD stands for Document Type Definition. It is a set of rules that defines the
structure, elements, and attributes of an XML document. A DTD specifies
the syntax that each element in the XML document must adhere to.
• DTDs are useful for validating XML documents to ensure they conform to a
specific structure and format. They also help in defining the rules for data
exchange between different systems by providing a common set of
guidelines for XML documents.
What is DTD?
Example of an internal DTD defined within an XML document:
<!DOCTYPE bookstore [
• In this example, the
<!ELEMENT bookstore (book+)>
<!ELEMENT book (title, author, year, price)>
books.dtd file contains the
<!ELEMENT title (#PCDATA)> same DTD definitions as the
<!ELEMENT author (#PCDATA)>
<!ELEMENT year (#PCDATA)> internal DTD in the previous
]>
<!ELEMENT price (#PCDATA)>
example.
<bookstore>
<book>
• The books.xml file
<title>Harry Potter</title> references the books.dtd
<author>J.K. Rowling</author>
<year>2005</year> file in its <!DOCTYPE>
<price>20.00</price>
</book> declaration, indicating that
<book>
<title>The Lord of the Rings</title>
the DTD rules defined in
<author>J.R.R. Tolkien</author> books.dtd should be used to
<year>1954</year>
<price>25.00</price> validate the XML structure.
</book>
</bookstore>
What is DTD?
Example of an external DTD defined in a separate file and
referenced in the <!DOCTYPE> declaration: books.dtd: • In this example, the internal
<!ELEMENT bookstore (book+)>
<!ELEMENT book (title, author, year, price)>
DTD is enclosed within the
<!ELEMENT title (#PCDATA)> <!DOCTYPE> declaration at
<!ELEMENT author (#PCDATA)>
<!ELEMENT year (#PCDATA)> the beginning of the XML
<!ELEMENT price (#PCDATA)>
books.xml:
document.
<!DOCTYPE bookstore SYSTEM "books.dtd">
<bookstore>
• It defines the structure of a
<book> bookstore element, which
<title>Harry Potter</title>
<author>J.K. Rowling</author> contains multiple book
<year>2005</year>
<price>20.00</price>
elements.
</book>
<book>
• Each book element has child
<title>The Lord of the Rings</title> elements for title, author,
<author>J.R.R. Tolkien</author>
<year>1954</year> year, and price.
<price>25.00</price>
</book>
</bookstore>
Quiz #1
Write an HTML for the following table along with CSS
Quiz #1- Answer
Write an HTML for the following table along with CSS
<table> <tr>
<td>Flavor</td>
<tr class="header">
<td class="banana">Banana</td>
<th></th> <td class="choclate">Chocolate</td>
<th></th> </tr>
<th>Bob</th> <tr>
<th>Alice</th> <td rowspan="2">Least<br>
Favorite</td>
</tr> <td>Color</td>
<tr> <td>Yellow</td>
<td rowspan="2">Favorite</td> <td class="pink">Pink</td>
<td>Color</td> </tr>
<tr>
<td class="blue">Blue</td>
<td>Flavor</td>
<td class="purple">Purple</td> <td>Mint</td>
</tr> <td>Walnut</td>
</tr>
</table>