0% found this document useful (0 votes)
8 views6 pages

Assignment No 03

The document outlines an assignment focused on creating and validating XML for employee information using DTD and XML Schema. It details the structure of the XML document, the purpose of DTD and XML Schema for data validation, and how to display the XML data in a tabular format using XSLT and CSS. The assignment includes example code for XML, DTD, XML Schema, CSS, and XSLT, along with a conclusion emphasizing the importance of structured data presentation.

Uploaded by

Pranav Sherekar
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)
8 views6 pages

Assignment No 03

The document outlines an assignment focused on creating and validating XML for employee information using DTD and XML Schema. It details the structure of the XML document, the purpose of DTD and XML Schema for data validation, and how to display the XML data in a tabular format using XSLT and CSS. The assignment includes example code for XML, DTD, XML Schema, CSS, and XSLT, along with a conclusion emphasizing the importance of structured data presentation.

Uploaded by

Pranav Sherekar
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/ 6

Assignment No: 03

Title: DTD, XML

Date of completion: 25th February 2025

Objective:

• Create and validate XML using DTD and XML Schema.


• Display XML data in a table using XSLT and CSS

Problem Statement:

Design the XML document to store the information of the employees of any business
organization and demonstrate the use of:

a) DTD

b) XML Schema

And display the content in (e.g., tabular format) by using CSS/XSL

Theory:

What is XML?
XML (eXtensible Markup Language) is used to store and transport data in a structured and
readable format. It is platform-independent and widely used for data exchange between
different systems.

Why use XML for Employee Information?


Using XML to store employee information helps in organizing data like employee names,
departments, salaries, and joining dates in a structured way. It makes the data easy to
share, maintain, and validate.
a) DTD (Document Type Definition)
What is DTD?
DTD defines the structure and rules of an XML document. It ensures the XML file follows
a specific format by specifying which elements and attributes are allowed.
Why use DTD?
• Checks the correctness of XML structure.
• Defines allowed elements and their order.
• Ensures data consistency.
Types of DTD:
1. Internal DTD – Defined inside the XML document.
2. External DTD – Defined in a separate file and linked to the XML document.

b) XML Schema (XSD)


What is XML Schema?
XML Schema (XSD) is used to describe the structure and data types of an XML document.
It is more powerful than DTD and supports data types like integers, dates, and strings.
Why use XML Schema?
• Provides strong data validation.
• Supports complex data structures and data types.
• Offers namespace support and better documentation.

Displaying XML Data Using CSS and XSLT


What is CSS in XML?
CSS (Cascading Style Sheets) is used to style the XML content to make it more readable.
It helps in changing font styles, colors, and layout.

What is XSLT?
XSLT (eXtensible Stylesheet Language Transformations) transforms XML data into
human-readable formats like HTML or PDF. It helps in displaying XML data in a structured
table format.
Why use XSLT with CSS?
• Converts raw XML into a visually appealing table.
• CSS adds styling like colors, borders, and fonts to the output.
• Together, they improve data presentation.

Program Code Files:

Employees.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE employees SYSTEM "employees.dtd">
<?xml-stylesheet type="text/xsl" href="employees.xsl"?>
<employees xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="employees.xsd">
<employee id="E101" department="HR">
<name>Aarav Sharma</name>
<gender>Male</gender>
<designation>HR Manager</designation>
<salary currency="INR">850000</salary>
<joining_date>2018-03-15</joining_date>
<email>aarav.sharma@example.com</email>
</employee>
<employee id="E102" department="IT">
<name>Priya Verma</name>
<gender>Female</gender>
<designation>Software Engineer</designation>
<salary currency="INR">950000</salary>
<joining_date>2019-07-10</joining_date>
<email>priya.verma@example.com</email>
</employee>
. ..
</employees>

Employees.dtd
<!ELEMENT employees (employee+)>
<!ELEMENT employee (name, gender, designation, salary, joining_date, email)>
<!ATTLIST employee id ID #REQUIRED department CDATA #REQUIRED>
<!ELEMENT name (#PCDATA)>
<!ELEMENT gender (#PCDATA)>
<!ELEMENT designation (#PCDATA)>
<!ELEMENT salary (#PCDATA)>
<!ATTLIST salary currency CDATA #REQUIRED>
<!ELEMENT joining_date (#PCDATA)>
<!ELEMENT email (#PCDATA)>

Employees.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="employees">
<xs:complexType>
<xs:sequence>
<xs:element name="employee" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="gender" type="xs:string"/>
<xs:element name="designation" type="xs:string"/>
<xs:element name="salary">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="currency" type="xs:string" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="joining_date" type="xs:date"/>
<xs:element name="email" type="xs:string"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID" use="required"/>
<xs:attribute name="department" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Style.css

body { background-color: #f8f9fa;


font-family: Arial, sans-serif; padding: 20px;
} font-size: 1.1rem;
table { }
width: 100%; tr:nth-child(even) {
border-collapse: collapse; background-color: #f2f2f2;
margin-top: 20px; }
box-shadow: 0 4px 8px rgba(0,0,0,0.1); tr:hover {
} background-color: #d1ecf1;
th, td { transition: background-color 0.3s
padding: 12px; ease;
border: 1px solid #dee2e6; }
text-align: center; h2 {
} text-align: center;
th { color: #343a40;
background-color: #007bff; }
color: white;

Employees.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<title>Employee Information</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<h2>Business Organization Employee Directory</h2>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Gender</th>
<th>Department</th>
<th>Designation</th>
<th>Salary</th>
<th>Joining Date</th>
<th>Email</th>
</tr>
<xsl:for-each select="employees/employee">
<tr>
<td><xsl:value-of select="@id"/></td>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="gender"/></td>
<td><xsl:value-of select="@department"/></td>
<td><xsl:value-of select="designation"/></td>
<td>
<xsl:value-of select="salary"/>
(<xsl:value-of select="salary/@currency"/>)
</td>
<td><xsl:value-of select="joining_date"/></td>
<td><xsl:value-of select="email"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

Output:

Conclusion:
Using XML with DTD or XML Schema ensures the data is structured and validated. XSLT
and CSS help in displaying the data in a user-friendly format, making it easier to read and
understand.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy