Experiment 12
Experiment 12
Experiment 12
Objective : Writing program in XML for creation of DTD, which specifies set of rules. Create a style
sheet in CSS/ XSL & display the document in internet explorer.
Theory :
XML (eXtensible Markup Language) is a markup language used to store and transport data. It is designed
to be both human-readable and machine-readable. Unlike HTML, which defines how to display data, XML
focuses on how to structure, store, and transport data. Basic XML Structure :
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Explanation:
1.<?xml version="1.0" encoding="UTF-8"?>: This is the XML declaration. It
specifies the XML version and the character encoding used.
2.<note>: The root element that contains all other elements.
3. <to>, <from>, <heading>, <body>: Child elements containing data. These tags describe the information
they hold.
To ensure that XML documents follow a specific structure, schema as like DTD (Document Type Definition)
or XML Schema (XSD) can be used to define the rules and structure of XML documents.
DTD
A Document Type Definition (DTD) defines the structure and rules for an XML document. It specifies the
allowed elements, attributes, and their relationships within an XML file. The DTD ensures that the XML
document follows a specific format and contains the required data in the correct structure.
<!DOCTYPE books [
<!ELEMENT books (book+)>
<!ELEMENT book (title, author, publisher, edition, price)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ELEMENT publisher (#PCDATA)>
<!ELEMENT edition (#PCDATA)>
<!ELEMENT price (#PCDATA)>]>
<book>
<title>Title -: A Brief History of Time</title>
<author>Author -: Stephen Hawking</author>
<publisher>Publisher -: Bantam Books</publisher>
<edition>Edition -: 2</edition>
<price>Price -: 350</price>
</book>
</books>
CSS
books {
color: white;
background-color : gray;
width: 100%;
}
heading {
color: green;
font-size : 40px;
background-color : powderblue;
}
heading, title, author, publisher, edition, price {
display : block;
}
title {
font-size : 25px;
font-weight : bold;
}
Output :