0% found this document useful (0 votes)
150 views28 pages

XML Arun

Uploaded by

SHARDUL MESHRAM
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)
150 views28 pages

XML Arun

Uploaded by

SHARDUL MESHRAM
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/ 28

Practical 1:- Create a well-formed XML document containing details of a car like: id, company name,

model, engine and mileage.

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:-

Id Company Model Engine Mileage


01 Toyota Camry 2.5L4-Cylinder 30mpg
02 Honda Lv8 2.3L3-Cylinder 30mpg
Practical 2:- Create a well-formed XML document to show following tree structure of student
information:

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:-

firstnam lastname mail city state pin


e
Om Gupta Om.gmail.com Nagpur Maharastra 440002
Pratik Lonkar Pratik.gmail.com Chandrapur Maharastra 430005
Practical 3:- Create a XML document which contains details of cars car like: id, company name,
model, engine and mileage and display the same as a table by using element by using XSLT.

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)

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html><head><style>

table {

border-collapse: collapse;

width: 100%;

}th, td {

border: 1px solid black;

padding: 8px;

text-align: left; }</style></head> <body>

<h1>Car Details</h1>
<table><tr><th>ID</th><th>Company</th>

<th>Model</th> <th>Engine</th><th>Mileage</th></tr>

<xsl:for-each select="cars/car"> <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:-

Id Company Model Engine Mileage


1 Toyota Camry V6 30 mpg
2 Ford Mustang V8 25 mpg
3 Honda Accord Inline-4 32 mpg
Practical 4:- Create a XML document Which contains details of book store information like: Book ID,
Book, Name Author, Name, Publisher, Price and Edition and display the same as a table by using
element by using XSLT.

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>

<BookName>Advanced XSLT Techniques</BookName>

<AuthorName>Jane Smith</AuthorName>

<Publisher>ABC Books</Publisher>

<Price>39.99</Price><Edition>2nd</Edition>

</book></bookstore>

(XSL)

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/"><html><head><style>

table {

border-collapse: collapse;

width: 80%;

margin: 20px; }th, td {

border: 1px solid black;

padding: 8px;

text-align: left; }

</style></head><body>

<h2>Bookstore Information</h2>

<table><tr>

<th>Book ID</th><th>Book Name</th>


<th>Author Name</th><th>Publisher</th>

<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:-

BookID BookName AuthorName Publisher Price Edition


001 Introduction to XML John Doe XYZ Publishing 29.99 1st
002 Advanced XSLT Jane Smith ABC Books 39.99 2nd
Techniques
Practical 5:- Create a XML document Which contains details of foodtype information like: Name,
carbs_per_serving, fiber_per_serving, fat_per_serving, kj_per_serving and display the same as a table
by using xsl:if element by using XSLT.

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)

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html><head><style>

table {

border-collapse: collapse;

width: 100%;}th, td {

border: 1px solid black;

padding: 8px;

text-align: left; }</style></head>

<body><table><tr>

<th>Name</th>

<th>Carbs per Serving</th>


<th>Fiber per Serving</th>

<th>Fat per Serving</th>

<th>kJ per Serving</th></tr>

<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:-

Name Carbs per Fiber per Fat per kJ per


Serving Serving Serving Serving
Apple 25g 4g 0g 218 KJ
Banana 27g 3g 0.3g 367 KJ
Practical 6:- Create a XML document Which contains details of Student information like: Rollno,
firstname,, lastname, nickname, marks and display the same as a table by using xsl:sort element by
using XSLT.

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)

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/students">

<html><head><style> table {

border-collapse: collapse;

width: 100%;}th, td {

border: 1px solid black;

padding: 8px;

text-align: left; }</style></head>


<body>

<h1>Student Information</h1>

<table><tr><th>Roll No</th>

<th>First Name</th> <th>Last Name</th>

<th>Nickname</th><th>Marks</th>/tr>

<xsl:apply-templates select="student">

<xsl:sort select="marks" data-type="number" order="descending"/>

</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:-

Roll No First Name Last Name Nickname Marks


101 Om Gupta Om 80
102 Pratik Lonkar Golu 84
103 Tanuja Dongare Tanu 96
Practical 7:- Create a XML document Which contains details of Employee information like: empid,
firstname,, lastname, designation, salary and display the same as a table by using xsl:choose element
by using XSLT.

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)

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/"> <html><body>

<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:-

Emp Id First Name Last Name Designation Salary


01 Harshita Rao Developer 80000
02 Rohini Bhagat Manager 70000
Practical 8:- Create a XML document Which contains details of Employee information like: empid,
firstname, lastname, designation, salary and display the same as a table by using xsl:apply-templates
element by using XSLT

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)

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<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 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:value-of select="designation" /></td>

<td><xsl:value-of select="salary" /></td></tr>

</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)

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/bank_info">

<html><head><style>

table {

border-collapse: collapse;

width: 100%;}

th, td {

border: 1px solid black;

padding: 8px;

text-align: left; }

th {

background-color: #f2f2f2; }</style></head>

<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:-

Custome Custome Account Accoun Bank Branc IFSC Addres


r ID r Name Number t Type Nam h Code s
e Name
101 Ram 7001100 Saving BOI Itwari BKID72 Nagpur
5 1
Practical 10:- Create a XML document Which contains details of matrimony registration information
like: id, firstname,, lastname, DOB, Height,complexion,Education,job_description,address,mobile no
and display the same as a table by using xsl:key element by using XSLT.

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)

<?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" version="4.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/matrimony_registration">

<html><head><title>Matrimony Registration Details</title>

</head> <body><h1>Matrimony Registration Details</h1>

<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>

</tr> <xsl:apply-templates select="person"/>

</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>

<td><xsl:value-of select="mobile"/></td> </tr>

</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:element name="id" type="xs:integer"/>

<xs:element name="company" type="xs:string"/>

<xs:element name="model" type="xs:string"/>

<xs:element name="engine" type="xs:string"/>

<xs:element name="mileage" type="xs:decimal"/>

</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:-

Id Company Model Engine Mileage


01 Toyota Camry V6 32.5
02 MG dv8 L27 30
Practical 12:- Create a valid Internal DTD document containing details of a car like: id, company
name, model, engine and mileage using DTD validate with php file

Input:-prg1.xml
<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE cars[<!ELEMENT cars (car+)>

<!ELEMENT car (company, model, engine, mileage)>

<!ELEMENT company (#PCDATA)> <!ELEMENT model (#PCDATA)>

<!ELEMENT engine (#PCDATA)> <!ELEMENT mileage (#PCDATA)>

<!ATTLIST car id CDATA #REQUIRED>]> <cars> <car id="c101">

<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()){

echo"It's a valid document";}

else{echo"It's a not valid document";}?>

Output:-

Its’s valid document


Id Company Model Engine Mileage
C101 Maruthi Swift 1248cc 20
C102 Hyundai i20 1000cc 25
Practical 13:- Create a valid DTD document for Newspaper Article by using Element,Attribute
and Entity building blocks validate with php file

Input:-(newspaper.dtd):
<!ELEMENT newspaper (article+)>

<!ELEMENT article (headline, byline, dateline?, body)>

<!ELEMENT headline (#PCDATA)> <!ELEMENT byline (#PCDATA)>

<!ELEMENT dateline (#PCDATA)> <!ELEMENT body (#PCDATA)>

<!ATTLIST articleid ID #REQUIREDcategory CDATA #IMPLIED>

<!ENTITY % specialChars "&#38;#60;&#38;#62;&#38;#38;">

<!ENTITY lt "&#38;#60;"> <!ENTITY gt "&#38;#62;">

<!ENTITY amp "&#38;#38;"> (newspaper.xml):

<!DOCTYPE newspaper SYSTEM "newspaper.dtd">

<newspaper><article id="1" category="Tech">

<headline>Machine Learning</headline>

<byline>prof.Ashish</byline><dateline>October 11, 2023</dateline>

<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 &amp;lt; &amp;gt;
&amp;amp;</body>

</article></newspaper> (newspaper.php):

<?phplibxml_use_internal_errors(true);

$document = new DOMDocument();

$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";

foreach (libxml_get_errors() as $error)

{echo $error->message . " at line " . $error->line . "\n";}}libxml_clear_errors();?>

Output:-

Validation failed.The XML is not vlid against the DTD.Errors:


Element “body”:This element is not expected.Expectedis one of
(dateline,headline,byline,dateline?).
Practical 14:- Create a XML document to parse an XML string into an XML DOM object and then
extract the information of important note.

Input:-Python:
import xml.etree.ElementTree as ET

xml_string = '''<notes> <note>

<title>Important Note 1</title>

<content>This is the content of the first important note.</content>

</note><note>

<title>Important Note 2</title>

<content>Content of the second important note.</content>

</note></notes>

'''root = ET.fromstring(xml_string)

important_notes = []

for note in root.findall('note'):

title = note.find('title').text

content = note.find('content').text

important_notes.append({'title': title, 'content': content})

for note in important_notes:

print(f'Title: {note["title"]}')

print(f'Content: {note["content"]}')

print()

Output:-

Title: Important Note 1


Content: This is the contentof the first important note.

Title: Important Note 2


Content: This is the contentof the second important note.
Practical 15:- Create a valid XML document of train information like:train title,train type ,name,
number, source and destination by using DTD and CSS.

Input:-(train.xml)
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE train_info SYSTEM "train_info.dtd">

<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)

<!ELEMENT train_info (train+)>

<!ELEMENT train (title, type, name, number, source, destination)>

<!ELEMENT title (#PCDATA)>

<!ELEMENT type (#PCDATA)>

<!ELEMENT name (#PCDATA)>

<!ELEMENT number (#PCDATA)>

<!ELEMENT source (#PCDATA)>

<!ELEMENT destination (#PCDATA)>

(train.cssl)

train_info {

font-family: Arial, sans-serif;

margin: 20px;

}train {

border: 1px solid #000;

padding: 10px; }title {

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"?>

<!DOCTYPE tv_schedule SYSTEM "tv_schedule.dtd">

<tv_schedule><channel>

<name>Channel 1</name> <program>

<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)

<!ELEMENT tv_schedule (channel+)><!ELEMENT channel (name, program+)>

<!ELEMENT name (#PCDATA)> <!ELEMENT program (title, start_time, end_time)>

<!ELEMENT title (#PCDATA)> <!ELEMENT start_time (#PCDATA)>

<!ELEMENT end_time (#PCDATA)> (Tv.php)

<?php $xmlDoc = new DOMDocument();

$xmlDoc->load('tv_schedule.xml');

if ($xmlDoc->validate()) {

echo "XML is valid according to DTD."; } else {

echo "XML is not valid according to DTD."; }?>

Output:-

XML is Valid according to DTD


Practical 17:- Write a program to create a valid XML document for A simple address book to store the
following information: The person name, Home address, state,pincode, Telephone number, FAX
number, Mobile number E-mail address by using XML schema.

Input:-(book.XML)

<?xml version="1.0" encoding="UTF-8"?>

<addressBook xmlns="http://www.example.com/addressbook">

<person>

<name>John Doe</name>

<homeAddress>123 Main St</homeAddress>

<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)

<?xml version="1.0" encoding="UTF-8"?>

<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:element name="person" maxOccurs="unbounded">

<xs:complexType>

<xs:sequence>

<xs:element name="name" type="xs:string"/>

<xs:element name="homeAddress" type="xs:string"/>

<xs:element name="state" type="xs:string"/>

<xs:element name="pincode" type="xs:string"/>


<xs:element name="telephone" type="xs:string"/>

<xs:element name="fax" type="xs:string"/>

<xs:element name="mobile" type="xs:string"/>

<xs:element name="email" type="xs:string"/>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

Output:-

Name: John Doe


Home Address:123 Main St
State: New York
Pincode:10001
Telephone:555-123-4567
Fax:555-987-6543
Mobile:555-789-0123
Email: [email protected]
Practical 18:- Create a valid xml document to show the information about subject topics by using css

Input:-

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head> <title>Subject Topics</title>

<style type="text/css">

.topic {

font-weight: bold;

}.description { color: #333; }

</style></head><body>

<topics><topic><name>Mathematics</name>

<description>Mathematics is the study of numbers, quantities, and shapes.</description>

</topic><topic><name>Science</name>

<description>Science is the pursuit of knowledge through observation and


experimentation.</description></topic></topics></body></html>

Output:-

Subject Topics
Mathematics
Mathematics is the study of numbers, auntities, and shapes.

Science
Science is the pursuit of Knowledge through observation and
Experimentation

You might also like