XML Arun
XML Arun
Input:-
<?xml version="1.0" encoding="UTF-8"?>
<car>
<id>01</id>
<company>Toyota</company>
<model>Camry</model>
<engine>2.5L 4-Cylinder</engine>
<mileage>30 mpg</mileage>
</car>
<car>
<id>02</id>
<company>Honda</company>
<model>Lv8</model>
<engine>2.3L 3-Cylinder</engine>
<mileage>35 mpg</mileage>
</car>
Output:-
Input:-
<?xml version="1.0" encoding="UTF-8"?>
<college> <students>
<firstname>Om</firstname>
<lastname>Gupta</lastname><contact>
<email>[email protected]</email><address>
<city>Nagpur</city>
<state>Maharastra</state>
<pin>440002</pin></address></contact></students><students>
<firstname>Pratik</firstname>
<lastname>Lonkar</lastname>
<contact>
<email>[email protected]</email>
<address>
<city>Chandrapur</city>
<state>Maharastra</state>
<pin>430005</pin></address></contact></students></college>
Output:-
Input:-(car.xml)
<?xml version="1.0" encoding="UTF-8"?><cars><car>
<id>1</id>
<company>Toyota</company>
<model>Camry</model>
<engine>V6</engine>
<mileage>30 mpg</mileage></car><car>
<id>2</id>
<company>Ford</company>
<model>Mustang</model>
<engine>V8</engine>
<mileage>25 mpg</mileage></car><car>
<id>3</id>
<company>Honda</company>
<model>Accord</model>
<engine>Inline-4</engine>
<mileage>32 mpg</mileage></car></cars>
(Car.xsl)
<xsl:template match="/">
<html><head><style>
table {
border-collapse: collapse;
width: 100%;
}th, td {
padding: 8px;
<h1>Car Details</h1>
<table><tr><th>ID</th><th>Company</th>
<th>Model</th> <th>Engine</th><th>Mileage</th></tr>
<td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="company"/></td>
<td><xsl:value-of select="model"/></td>
<td><xsl:value-of select="engine"/></td>
<td><xsl:value-of select="mileage"/></td>
</tr></xsl:for-each></table></body>
</html></xsl:template></xsl:stylesheet>
Output:-
Input:-
<?xml version="1.0" encoding="UTF-8"?>
<bookstore> <book>
<BookID>001</BookID>
<BookName>Introduction to XML</BookName>
<AuthorName>John Doe</AuthorName>
<Publisher>XYZ Publishing</Publisher>
<Price>29.99</Price><Edition>1st</Edition>
</book<book>
<BookID>002</BookID>
<AuthorName>Jane Smith</AuthorName>
<Publisher>ABC Books</Publisher>
<Price>39.99</Price><Edition>2nd</Edition>
</book></bookstore>
(XSL)
<xsl:template match="/"><html><head><style>
table {
border-collapse: collapse;
width: 80%;
padding: 8px;
text-align: left; }
</style></head><body>
<h2>Bookstore Information</h2>
<table><tr>
<th>Price</th><th>Edition</th></tr>
<xsl:for-each select="bookstore/book">
<tr>
<td><xsl:value-of select="BookID"/></td>
<td><xsl:value-of select="BookName"/></td>
<td><xsl:value-of select="AuthorName"/></td>
<td><xsl:value-of select="Publisher"/></td>
<td><xsl:value-of select="Price"/></td>
<td><xsl:value-of select="Edition"/></td>
</tr>
</xsl:for-each>
</table></body></html>
</xsl:template>
</xsl:stylesheet>
Output:-
Input:- (XML)
<?xml version="1.0" encoding="UTF-8"?>
<foods>
<food>
<name>Apple</name>
<carbs_per_serving>25g</carbs_per_serving>
<fiber_per_serving>4g</fiber_per_serving>
<fat_per_serving>0g</fat_per_serving>
<kj_per_serving>218kJ</kj_per_serving>
</food><food>
<name>Banana</name>
<carbs_per_serving>27g</carbs_per_serving>
<fiber_per_serving>3g</fiber_per_serving>
<fat_per_serving>0.3g</fat_per_serving>
<kj_per_serving>367kJ</kj_per_serving>
</food></foods>
(XSL)
<xsl:template match="/">
<html><head><style>
table {
border-collapse: collapse;
width: 100%;}th, td {
padding: 8px;
<body><table><tr>
<th>Name</th>
<xsl:for-each select="foods/food"><tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="carbs_per_serving"/></td>
<td><xsl:value-of select="fiber_per_serving"/></td>
<td><xsl:value-of select="fat_per_serving"/></td>
<td><xsl:value-of select="kj_per_serving"/></td>
</tr></xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Output:-
Input:-(XML)
<?xml version="1.0" encoding="UTF-8"?>
<students> <student>
<rollno>101</rollno>
<firstname>Om</firstname>
<lastname>Gupta</lastname>
<nickname>Om</nickname>
<marks>80</marks></student><student>
<rollno>102</rollno>
<firstname>Pratik</firstname>
<lastname>Lonkar</lastname>
<nickname>Golu</nickname>
<marks>84</marks>
</student><student>
<rollno>103</rollno>
<firstname>Tanuja</firstname>
<lastname>Dongare</lastname>
<nickname>Tanu</nickname>
<marks>96</marks>
</student></students>
(XSL)
<xsl:template match="/students">
<html><head><style> table {
border-collapse: collapse;
width: 100%;}th, td {
padding: 8px;
<h1>Student Information</h1>
<table><tr><th>Roll No</th>
<th>Nickname</th><th>Marks</th>/tr>
<xsl:apply-templates select="student">
</xsl:apply-templates>
</table></body></html> </xsl:template>
<xsl:template match="student">
<tr>
<td><xsl:value-of select="rollno"/></td>
<td><xsl:value-of select="firstname"/></td>
<td><xsl:value-of select="lastname"/></td>
<td><xsl:value-of select="nickname"/></td>
<td><xsl:value-of select="marks"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
Output:-
Input:-(emp.xml)
<?xml version="1.0" encoding="UTF-8"?>
<employees>
<employee>
<empid>1</empid>
<firstname>John</firstname>
<lastname>Doe</lastname>
<designation>Manager</designation>
<salary>60000</salary>
</employee>
<employee>
<empid>2</empid>
<firstname>Jane</firstname>
<lastname>Smith</lastname>
<designation>Developer</designation>
<salary>50000</salary>
</employee></employees>
(emp.xsl)
<table border="1"><tr>
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Designation</th>
<th>Salary</th></tr>
<xsl:apply-templates select="employees/employee"/>
</table></body></html></xsl:template>
<xsl:template match="employee"><tr>
<td><xsl:value-of select="empid"/></td>
<td><xsl:value-of select="firstname"/></td>
<td><xsl:value-of select="lastname"/></td>
<td><xsl:choose>
<xsl:when test="designation='Manager'">
Manager</xsl:when>
<xsl:when test="designation='Developer'">
Developer</xsl:when>
<xsl:otherwise>
Other</xsl:otherwise></xsl:choose>
</td><td><xsl:value-of select="salary"/></td>
</tr></xsl:template></xsl:stylesheet>
Output:-
Input:-(emp.xml)
<?xml version="1.0" encoding="UTF-8"?>
<employees>
<employee>
<empid>1</empid>
<firstname>John</firstname>
<lastname>Doe</lastname>
<designation>Manager</designation>
<salary>60000</salary></employee>
<employee>
<empid>2</empid>
<firstname>Jane</firstname>
<lastname>Smith</lastname>
<designation>Developer</designation>
<salary>50000</salary>
</employee</employees>
(emp.xsl)
<xsl:template match="/employees">
<html><head>
<title>Employee Information</title>
</head> <body>
<h1>Employee Information</h1>
<table border="1"><tr>
<th>Employee ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Designation</th>
<th>Salary</th></tr>
<xsl:apply-templates select="employee" />
</table></body></html></xsl:template>
</xsl:template></xsl:stylesheet>
Output:-
Employee Information
Emp Id First Name Last Name Designation Salary
01 Om Gupta Developer 10000
02 Gungun Shahu Manager 90000
Practical 9:- Create a XML document Which contains details of Bank information like: customer id,
customername, accountnumber , accounttype , bankname branchname IFSCcode Address and display
the same as a table by using xsl:import element by using XSLT.
Input:- (acc.xml)
<?xml version="1.0" encoding="UTF-8"?>
<bank_info>
<customer>
<customer_id>101</customer_id>
<customer_name>Ram</customer_name>
<account_number>70011005</account_number>
<account_type>Savings</account_type>
<bank_name>BOI</bank_name>
<branch_name>Itwari</branch_name>
<ifsc_code>BKID721</ifsc_code>
<address>Nagpur</address>
</customer</bank_info>
(acc.xsl)
<xsl:template match="/bank_info">
<html><head><style>
table {
border-collapse: collapse;
width: 100%;}
th, td {
padding: 8px;
text-align: left; }
th {
<body><table><tr>
<th>Customer ID</th>
<th>Customer Name</th>
<th>Account Number</th>
<th>Account Type</th>
<th>Bank Name</th>
<th>Branch Name</th>
<th>IFSC Code</th>
<th>Address</th></tr>
<xsl:for-each select="customer">
<tr><td><xsl:value-of select="customer_id"/></td>
<td><xsl:value-of select="customer_name"/></td>
<td><xsl:value-of select="account_number"/></td>
<td><xsl:value-of select="account_type"/></td>
<td><xsl:value-of select="bank_name"/></td>
<td><xsl:value-of select="branch_name"/></td>
<td><xsl:value-of select="ifsc_code"/></td>
<td><xsl:value-of select="address"/></td>
</tr></xsl:for-each></table></body>
</html></xsl:template></xsl:stylesheet>
Output:-
Input:-(reg.xml)
<?xml version="1.0" encoding="UTF-8"?>
<matrimony_registration> <person>
<id>1</id>
<firstname>Prathmesh</firstname>
<lastname>Mohale</lastname>
<DOB>15-08-1947</DOB>
<Height>185 cm</Height>
<complexion>Fair</complexion>
<Education>Master's Degree</Education>
<job_description>Software Engineer</job_description>
<address>Nagpur</address>
<mobile>99900009</mobile></person></matrimony_registration>
(reg.xsl)
<xsl:template match="/matrimony_registration">
<table border="1"><tr>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>DOB</th>
<th>Height</th>
<th>Complexion</th>
<th>Education</th>
<th>Job Description</th>
<th>Address</th>
<th>Mobile Number</th>
</table></body></html></xsl:template>
<xsl:template match="person"><tr>
<td><xsl:value-of select="id"/></td>
<td><xsl:value-of select="firstname"/></td>
<td><xsl:value-of select="lastname"/></td>
<td><xsl:value-of select="DOB"/></td>
<td><xsl:value-of select="Height"/></td>
<td><xsl:value-of select="complexion"/></td>
<td><xsl:value-of select="Education"/></td>
<td><xsl:value-of select="job_description"/></td>
<td><xsl:value-of select="address"/></td>
</xsl:template></xsl:stylesheet>
Output:-
ID First Name Last DOB Height Complexion Education Job Address Mobile
Name Description Number
1 Prathmesh Mohale 15- 158cm Fair Bachelor Government Nagpur 9990000
08- Degree Feild
1947
2 Ruchit Vinod 12- 159cm Fair Bachelor Software Nagpur 8880006
05- Degree Feild
1989
Practical 11:- Create a valid XML document containing details of a car like: id, company name, model,
engine and mileage by using XML Schema.
Input:- (car_schema.xsd):
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema
<xs:element name="car">
<xs:complexType><xs:sequence>
</xs:sequence></xs:complexType></xs:element></xs:schema>
(car_schema.xml):
<?xml version="1.0"?>
<car xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="car_schema.xsd">
<id>1</id>
<company>Toyota</company>
<model>Camry</model>
<engine>V6</engine>
<mileage>32.5</mileage></car>
Output:-
Input:-prg1.xml
<?xml version="1.0" encoding="utf-8"?>
<company>Maruthi</company><model>Swift</model>
<engine>1248cc</engine><mileage>20</mileage>
</car><car id="c102">
<company>Hyundai</company><model>i20</model>
<engine>1000cc</engine><mileage>15</mileage>
</car></cars>Prg2.php
<?php$xml=new DOMDocument;
$xml->load('prg1.xml');
if($xml->validate()){
Output:-
Input:-(newspaper.dtd):
<!ELEMENT newspaper (article+)>
<headline>Machine Learning</headline>
<body>Machine Learning is the most demandable field in the ear of the “Artificial Inteligence ”
Big data and iot is also plays an crutial role in field of technology &lt; &gt;
&amp;</body>
</article></newspaper> (newspaper.php):
<?phplibxml_use_internal_errors(true);
$document->load('news.xml');
if ($document->validate()) {echo "Validation successful. The XML is valid against the DTD."; }
else {echo "Validation failed. The XML is not valid against the DTD. Errors:\n";
Output:-
Input:-Python:
import xml.etree.ElementTree as ET
</note><note>
</note></notes>
'''root = ET.fromstring(xml_string)
important_notes = []
title = note.find('title').text
content = note.find('content').text
print(f'Title: {note["title"]}')
print(f'Content: {note["content"]}')
print()
Output:-
Input:-(train.xml)
<?xml version="1.0" encoding="UTF-8"?>
<train_info>
<train>
<title>Express Train</title>
<type>Passenger</type>
<name>Example Express</name>
<number>12345</number>
<source>New York</source>
<destination>Los Angeles</destination>
</train>
</train_info>
(train.dtd)
(train.cssl)
train_info {
margin: 20px;
}train {
font-size: 18px;
font-weight: bold;
}type {
font-style: italic;
}name {
color: #3366CC;
}number {
color: #009900;
}source, destination {
margin-top: 5px;
Output:-
Express Train
Passenger
Example Express
12345
Nework Y
Los Angeles
Practical 16:- Create a valid xml document to encode TV Program Schedules by using External DTD
validate with php file.
Input:- (tv.xml)
<?xml version="1.0"?>
<tv_schedule><channel>
<title>Program 1</title>
<start_time>2023-10-11T08:00:00</start_time>
<end_time>2023-10-11T09:00:00</end_time>
</program><program>
<title>Program 2</title>
<start_time>2023-10-11T09:30:00</start_time>
<end_time>2023-10-11T10:30:00</end_time>
</program></channel><channel></channel>
</tv_schedule> (tv.dtd)
$xmlDoc->load('tv_schedule.xml');
if ($xmlDoc->validate()) {
Output:-
Input:-(book.XML)
<addressBook xmlns="http://www.example.com/addressbook">
<person>
<name>John Doe</name>
<state>New York</state>
<pincode>10001</pincode>
<telephone>555-123-4567</telephone>
<fax>555-987-6543</fax>
<mobile>555-789-0123</mobile>
<email>[email protected]</email>
</person>
</addressBook>
(Book.xsd)
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com/addressbook"
xmlns="http://www.example.com/addressbook"
elementFormDefault="qualified">
<xs:element name="addressBook">
<xs:complexType>
<xs:sequence>
<xs:complexType>
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Output:-
Input:-
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<style type="text/css">
.topic {
font-weight: bold;
</style></head><body>
<topics><topic><name>Mathematics</name>
</topic><topic><name>Science</name>
Output:-
Subject Topics
Mathematics
Mathematics is the study of numbers, auntities, and shapes.
Science
Science is the pursuit of Knowledge through observation and
Experimentation