0% found this document useful (0 votes)
235 views

XML Assignment

The document provides instructions for three XML assignments: 1) Create an XML file listing books available at a bookstore organized into technical, cooking, and yoga categories. 2) Write a PHP script to create a CD catalog using data from an XML file listing CDs. 3) Write a PHP script to generate an XML file with book title and publication details entered through an HTML form. The script should write the XML tags and input data to a new XML file.

Uploaded by

beast 7
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
235 views

XML Assignment

The document provides instructions for three XML assignments: 1) Create an XML file listing books available at a bookstore organized into technical, cooking, and yoga categories. 2) Write a PHP script to create a CD catalog using data from an XML file listing CDs. 3) Write a PHP script to generate an XML file with book title and publication details entered through an HTML form. The script should write the XML tags and input data to a new XML file.

Uploaded by

beast 7
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

XML Assignment

Q 1 Create a XML file which gives details of books available in “ABC Bookstore”
from following categories
1) Technical
2) Cooking
3) YOGA

INPUT 1>
Bookstore.xml
<?xml version='1.0' ?>
<ABC_Bookstore>
<books category="technical">
<book_no>1</book_no>
<book_name>def</book_name>
<author_name>xxx</author_name>
<price>100</price>
<year>1990</year>
</books>
<books category="Cooking">
<book_no>2</book_no>
<book_name>ccc</book_name>
<author_name>aaa</author_name>
<price>200</price>
<year>1950</year>
</books>
<books category="YOGA">
<book_no>3</book_no>
<book_name>ddd</book_name>
<author_name>zzz</author_name>
<price>150</price>
<year>2016</year>
</books>
</ABC_Bookstore>

OUTPUT :
Q 2. Write PHP script to create a CD catalog using XML file.

INPUT1>
cd.xml
<?xml version='1.0' encoding='UTF-8' ?>
<CD>
<cd type='music'>
<name>silent_songs</name>
<launch-date>5-6-2014</launch-date>
<composer>A-R-Rehman</composer>
</cd>
<cd type='music'>
<name>Hip-Hop</name>
<launch-date>4-8-2011</launch-date>
<composer>Yo-Yo-Honey singh</composer>
</cd>
<cd type='music'>
<name>love track</name>
<launch-date>6-9-2000</launch-date>
<composer>Arjit Singh</composer>
</cd>
</CD>

OUTPUT 1:

INPUT2>
cd.php
<?php
$xml=simplexml_load_file('cd.xml');
var_dump($xml);
?>?>
OUTPUT 2:

Q 3) Write a PHP script to generate an XML in the following format


INPUT1>
book_info.html
<html>
<head>
<title>Create XML</title>
</head>
<form action=book_info.php method=get>
Enter Book Title<input type=text name=txtTitle></br>
Enter Publication<input type=text name=publ></br>
<input type=submit value="submit">
</form>
</html>

INPUT2>
book_info.php
<?php
echo "Links data posted";
$ele=$_GET['txtTitle'];
$att=$_GET['publ'];
$xmltags="<?xml version=1.0?>";
$xmltags=$xmltags."<Bookstore>";
$xmltags=$xmltags."<Books>";
$xmltags=$xmltags."<PHP>";
$xmltags=$xmltags."<title>";
$xmltags=$xmltags.$ele;
$xmltags=$xmltags."</title>";
$xmltags=$xmltags."<publication>";
$xmltags=$xmltags."<attrib>";
$xmltags=$xmltags.$att;
$xmltags=$xmltags."</attrib>";
$xmltags=$xmltags."</PHP>";
$xmltags=$xmltags."</Books>";
$xmltags=$xmltags."</Bookstore>";
if($fp=fopen("books.xml","w"))
{
 if($wt=fwrite($fp,$xmltags))
 {
 echo "File created";
 }
 else
 echo "Not write";
}
else
echo "Not opened";

OUTPUT 1 :

You might also like