Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
38 views37 pages

XML Practical File

The document is a practical file for the Web Development II course at Satya College of Engineering and Technology, detailing various exercises related to XML, DTD, XML Schema, CSS, and XSL transformations. It includes code snippets and outputs for tasks such as XML file creation, DTD implementation, and styling with CSS. The exercises aim to provide hands-on experience in web development concepts for BCA students in their second semester.

Uploaded by

imhackerboss4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views37 pages

XML Practical File

The document is a practical file for the Web Development II course at Satya College of Engineering and Technology, detailing various exercises related to XML, DTD, XML Schema, CSS, and XSL transformations. It includes code snippets and outputs for tasks such as XML file creation, DTD implementation, and styling with CSS. The exercises aim to provide hands-on experience in web development concepts for BCA students in their second semester.

Uploaded by

imhackerboss4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

SATYA COLLEGE OF ENGINEERING AND

TECHNOLOGY, PALWAL

Practical File
Of

Web Development -II


(SubjectCode-24CSC402SE01)

BCA 2nd sem

Session: Jan-May 2025

Submitted To: SubmittedBy:

Mrs. Rachna Beniwal Name:

CSE Department Roll no:

1
INDEX

Sl.No EXERCISE PageNo

1. SIMPLEXMLFILECREATION-ELEMENTS

2. SIMPLEXMLFILECREATION-ATTRIBUTES

3. INTERNALDTD IMPLEMENTATION

4. EXTERNALDTD IMPLEMENTATION

5. XML SCHEMA

6. CASCADINGSTYLE SHEET

7. XSL–TRANSFORMATION

8 XSL FORMATTING

9 XPATHIMPLEMENTATION

10 XMLDOCUMENT CLASS

2
`

EX.NO.: 01

SIMPLE XML FILE CREATION-ELEMENTS

<?xmlversion="1.0"?>
<addbook>
<details>
<name>JohnSmith</name>
<DOB>2-january-1978</DOB>
<city>Chennai</city>
<state>Tamilnadu</state>
<pincode>600089</pincode>
<worktitle="ProjectManager"company="TCS"city="Chennai"></work>
<phoneno>984002561</phoneno>
<email>[email protected]</email>
</details>
<details>
<name>Annie</name>
<DOB>30-March-1982</DOB>
<city>VilleParle</city>
<state>Mumbai</state>
<pincode>876001</pincode>
<worktitle="HR"company="Wipro"city="Mumbai"></work>
<phoneno>9600560190</phoneno>
<email>[email protected]</email>
</details>
</addbook>

3
`

OUTPUT

Result:
The XML Document executed successfully

4
EX.NO.: 02

SIMPLE XML DOCUMENT-ATTRIBUTES


<ADDRESSBOOK>
<PERSON1
Name="NKrishnamoorthy"
Age="45"
Dob="06-02-1976"
Mobile="944339443"
Mail="[email protected]"Stree
tname="Thiruneermalai
Road"Houseno="303"
Area="Thirumudivakkam"
Pincode="600044"
City="Chennai"
State="Tamilnadu"
/>
<PERSON2
Name="Balavinayagam"
Age="27"
Dob="09-06-1990"
Mobile="9600365435"
Mail="[email protected]"St
reetname="North Car
Street"Houseno="77/99a"
Area="Rockfort"
Pincode="600002"
City="tiruchirappalli"
State="Tamilnadu"
/>
<PERSON3
Name="Sushmitha"
Age="47"
Dob="09-02-1970"
Mobile="9789548789"
Mail="[email protected]"Str
eetname="Haneefa
Colony"Houseno="548"
Area="Vaniyambadi"
Pincode="625689"
City="Vaniyambadi"
State="Tamilnadu"
/>
</ADDRESSBOOK>

5
`

Output:

Result:
ThesimpleXMLdocumentforgeneratingaddressbookisdonewiththe attributes.

6
`

Ex.No:.3

INTERNAL DTD IMPLEMENTATION

<?xmlversion="1.0"?>
<!DOCTYPEbookstore[
<!ELEMENTbookstore(name,topic+)>
<!ELEMENTtopic(name,book*)>
<!ELEMENTname(#PCDATA)>
<!ELEMENTbook(title,author)>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTauthor(#PCDATA)>
<!ATTLISTbookISBNCDATA"0">

]>
<bookstore>
<name>Mike'sStore</name>
<topic>
<name>XML</name>
<bookISBN="120-90-100">
<title>Mike'sGuideToDTD'sandXMLSchemas</title>
<author>MikeJervis</author>
</book>
</topic>
</bookstore>

7
`

OUTPUT

Result:
XMLfileexecutedsuccessfully.

8
Ex.No:.4

EXTERNAL DTD IMPLEMENTATION

<?xmlversion="1.0"?>
<!ELEMENTCombomeal(burger,fries,drink)>
<!ENTITYCOLA"Pepsi">
<!ELEMENTburger(name,bun)>
<!ELEMENTname(#PCDATA)>
<!ELEMENTbun(meat,cheese,chick)>
<!ATTLISTbunbread(white|wheat)#REQUIRED>
<!ELEMENTmeatEMPTY>
<!ELEMENTcheeseEMPTY>
<!ELEMENTchickEMPTY>
<!ELEMENTfriesEMPTY>
<!ATTLISTfriessize(small|medium|large)#REQUIRED>
<!ELEMENTdrink(#PCDATA)>
<!ATTLISTdrinksize(small|medium|large)#REQUIRED>

Byimportinga.dtdfilewhichhasbeenwrittenseparately (.xml
file)
<?xmlversion="1.0"?>
<!DOCTYPECombomealSYSTEM"DTD1.dtd">
<Combomeal>
<burger>
<name>TASTYBURGER</name>
<bunbread="white">
<meat/>
<cheese/>
<chick/>
</bun>
</burger>
<friessize="large"/>
<drinksize="large">&COLA;</drink>
</Combomeal>

9
`

Output:

Result:
XMLfileexecutedsuccessfully.

10
`

Ex.No:.5

XMLSCHEMA

<?xmlversion="1.0"?>
<xs:schema>
<xmlns:xs="http://www.w3.org/2001/XMLNSschema"
target namespace="http://www.w3schools.com
elementformdefault="qualified">
<xs:elementname="to"type="xs:string"/>
<xs:elementname="heading"type=xs:string"/>
<xs:elementname="body"type="xs:string"/>
</xs:sequence>
</xs:complextype>
</xs:element>
</xs:schema>

XMLfile

<?xmlversion="1.0"?>
<note xmlns="http://www.w3cschools.com"
xmlns:xsi="http://www.w3.org/2001/XMLNSschema_instance"
xsi:xmlSchemaLocation="http:/w3cschoools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>don'tforgotme</body>
</note>

11
`

Output:

Result:
XMLfileexecutedsuccessfully.

12
Ex.No :.6

CASCADING STYLESHEET

bookstore
{
border-style:double;
background-color:green;
font-family:algerian;
display:block;
}
book
{
height:50px;
font-size:150%;
foreground-color:red;
margin-left:300px;
text-decoration:underline;
}
title
{
height:50px;
font-size:150%;
margin-left:300px;
}
author
{
height:50px;
font-size:250%;
margin-left:300px;
text-decoration:underline;
}
price
{
height:50px;
font-size:150%;
margin-left:300px;

13
`

Importing css file in XMLfile

<?xmlversion="1.0"?>
<?xml-stylesheettype="text/css"href="bookes.css"?>
<bookstore>
<book>BookDetail</book>
<title>Title:ANSIC</title>
<author>Author:Balagurusamy</author>
<rs>Price: 250 </rs>
</bookstore>

Output:

Result:
XMLfileexecutedsuccessfully.

14
Ex.No:.7

XSL TRANSFORMATION

SourceCode:

Filename:“cdcatalog.xsl”

<?xmlversion="1.0"encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:templatematch="/">
<html>
<body>
<h2>MyCDCollection</h2>
<tableborder="1">
<trbgcolor="#9acd32">
<thstyle="text-align:left">Title</th>
<thstyle="text-align:left">Artist</th>
</tr>
<xsl:for-eachselect="catalog/cd">
<tr>
<td><xsl:value-ofselect="title"/></td>
<td><xsl:value-ofselect="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

15
`

SourceCode:
Filename:“Simpxsl.xml”
<?xmlversion="1.0"encoding="UTF-8"?>
<?xml-stylesheettype="text/xsl"href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>EmpireBurlesque</title>
<artist>BobDylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hideyourheart</title>
<artist>BonnieTyler</artist>
<country>UK</country>
<company>CBSRecords</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>GreatestHits</title>
<artist>DollyParton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Stillgottheblues</title>

16
`

<artist>GaryMoore</artist>
<country>UK</country>
<company>Virginrecords</company>
<price>10.20</price>
<year>1990</year>
</cd>
<cd>
<title>Eros</title>
<artist>ErosRamazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Onenightonly</title>
<artist>BeeGees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.90</price>
<year>1998</year>
</cd>
<cd>
<title>SylviasMother</title>
<artist>Dr.Hook</artist>
<country>UK</country>
<company>CBS</company>
<price>8.10</price>
<year>1973</year>
</cd>
<cd>
<title>MaggieMay</title>
<artist>RodStewart</artist>
<country>UK</country>
<company>Pickwick</company>
<price>8.50</price>
<year>1990</year>

17
`

</cd>
<cd>
<title>Romanza</title>
<artist>AndreaBocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
<cd>
<title>Whenamanlovesa woman</title>
<artist>PercySledge</artist>
<country>USA</country>
<company>Atlantic</company>
<price>8.70</price>
<year>1987</year>
</cd>
<cd>
<title>Blackangel</title>
<artist>SavageRose</artist>
<country>EU</country>
<company>Mega</company>
<price>10.90</price>
<year>1995</year>
</cd>
<cd>
<title>1999GrammyNominees</title>
<artist>Many</artist>
<country>USA</country>
<company>Grammy</company>
<price>10.20</price>
<year>1999</year>
</cd>
<cd>
<title>Forthegoodtimes</title>
<artist>KennyRogers</artist>
<country>UK</country>

18
`

<company>MucikMaster</company>
<price>8.70</price>
<year>1995</year>
</cd>
<cd>
<title>BigWilliestyle</title>
<artist>WillSmith</artist>
<country>USA</country>
<company>Columbia</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>TupeloHoney</title>
<artist>VanMorrison</artist>
<country>UK</country>
<company>Polydor</company>
<price>8.20</price>
<year>1971</year>
</cd>
<cd>
<title>Soulsville</title>
<artist>JornHoel</artist>
<country>Norway</country>
<company>WEA</company>
<price>7.90</price>
<year>1996</year>
</cd>
<cd>
<title>Theverybestof</title>
<artist>CatStevens</artist>
<country>UK</country>
<company>Island</company>
<price>8.90</price>
<year>1990</year>
</cd>
<cd>

19
`

<title>Stop</title>
<artist>SamBrown</artist>
<country>UK</country>
<company>Aand M</company>
<price>8.90</price>
<year>1988</year>
</cd>
<cd>
<title>BridgeofSpies</title>
<artist>T`Pau</artist>
<country>UK</country>
<company>Siren</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>PrivateDancer</title>
<artist>TinaTurner</artist>
<country>UK</country>
<company>Capitol</company>
<price>8.90</price>
<year>1983</year>
</cd>
<cd>
<title>Midtomnatten</title>
<artist>KimLarsen</artist>
<country>EU</country>
<company>Medley</company>
<price>7.80</price>
<year>1983</year>
</cd>
<cd>
<title>PavarottiGalaConcert</title>
<artist>LucianoPavarotti</artist>
<country>UK</country>
<company>DECCA</company>
<price>9.90</price>

20
`

<year>1991</year>
</cd>
<cd>
<title>Thedockofthebay</title>
<artist>OtisRedding</artist>
<country>USA</country>
<company>Atlantic</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Picturebook</title>
<artist>SimplyRed</artist>
<country>EU</country>
<company>Elektra</company>
<price>7.20</price>
<year>1985</year>
</cd>
<cd>
<title>Red</title>
<artist>TheCommunards</artist>
<country>UK</country>
<company>London</company>
<price>7.80</price>
<year>1987</year>
</cd>
<cd>
<title>Unchainmyheart</title>
<artist>JoeCocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
</catalog>

21
`

OUTPUT

Result:
ThustheprogramtoconvertthesimpleXSLTtransformationfromXSLtoXML has
been executed successfully.

22
` Ex.No:7
XSL TRANSFORMATION-BOOK SHOP

<?xmlversion="1.0"?>
<?xml-stylesheettype="text/xsl"href="style.xsl"?>
<BooksforYou>
<BookBookID="1000">
<Title>IfTomorrowComes</Title>
<Rate>275</Rate>
<Author>KrishnaKumar</Author>
<Publication>Pearson</Publication>
<ISBN>111-222-333</ISBN>
</Book>
<BookBookID="1001">
<Title>.NETExpertGuide</Title>
<Rate>475</Rate>
<Author>James</Author>
<Publication>MicrosoftPress</Publication>
<ISBN>121-222-333</ISBN>
</Book>
<BookBookID="1002">
<Title>CProjects</Title>
<Rate>275</Rate>
<Author>YashwantP.Kanetkar</Author>
<Publication>BPBPublications</Publication>
<ISBN>111-232-333</ISBN>
</Book>
<BookBookID="1003">
<Title>LetusC</Title>
<Rate>225</Rate>
<Author>YashwantP.Kanetkar</Author>
<Publication>BPBPublications</Publication>
<ISBN>111-222-353</ISBN>
</Book>

23
`

<BookBookID="1004">
<Title>ComandBeyondin VC++</Title>
<Rate>375</Rate>
<Author>YashvantP.Kanetkar</Author>
<Publication>BPBPublications</Publication>
<ISBN>111-555-333</ISBN>
</Book>
</BooksforYou>

//XSLTDOCUMENT
<?xmlversion="1.0"encoding="UTF-8"?>
<xsl:stylesheetxmlns:xsl="http://www.w3.org/1999/XSL/
Transform"version="1.0">

<xsl:templatematch="/">

<html>

<bodybackground="tech.gif">

<h1align="center">
<fontcolor="blue">BooksatyourownCyberShoppe</font>
</h1>

<tableborder="4"cellpadding="10"cellspacing="5"align="center"
bgcolor="lightgreen" bordercolor="green">

<tbody>
<tr>
<th>BookID</th>
<th>Title</th>
<th>Rate</th>
<th>Author</th>
<th>Publication</th>

24
`

<th>ISBN</th>
</tr>

<xsl:for-eachselect="BooksforYou/Book">
<tr>
<td><xsl:value-ofselect="@BookID"/></td>
<td><xsl:value-ofselect="Title"/></td>
<td><xsl:value-ofselect="Rate"/></td>
<td><xsl:value-ofselect="Author"/></td>
<td><xsl:value-ofselect="Publication"/></td>
<td><xsl:value-ofselect="ISBN"/></td>
</tr>
</xsl:for-each>

</tbody>
</table>

</body>
</html>

</xsl:template>
</xsl:stylesheet>

25
`

OUTPUT

BooksatyourownCyberShoppe
Book
Title Rate Author Publication ISBN
ID

IfTomorrow 111-
1000 275 Krishna Kumar Pearson
Comes 222-333

.NETExpert Microsoft 121-


1001 475 James
Guide Press 222-333

BPB 111-
1002 C Projects 275 YashwantP.Kanetkar
Publications 232-333

BPB 111-
1003 LetusC 225 YashwantP.Kanetkar
Publications 222-353

Com and
BPB 111-
1004 Beyondin 375 YashvantP.Kanetkar
Publications 555-333
VC++

Result:
ThustheprogramtoconvertthesimpleXSLTtransformationfromXSLto XML has
been executed successfully.

26
` Ex.No:8
XSL FORMATTING

XMLFile(root.xml)

<?xmlversion="1.0"?>

<?xml-stylesheettype="text/xsl"href="decimalformat.xsl"?>

<root/>

XSLDocument

//decimalformat.xsl

<?xmlversion="1.0"?>
<?xml-stylesheettype="text/xsl"href="decimalformat.xsl"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:outputmethod="html"/>
<xsl:decimal-formatname="us"decimal-separator='.'grouping-separator=','/>
<xsl:decimal-formatname="european"decimal-separator=','grouping-
separator='.' />
<xsl:decimal-formatname="example"decimal-separator="."grouping- separator=","
infinity="INFINITY"minus-sign="-"NaN="NotaNumber"percent="%"
per-mille="m" zero-digit="0" digit="#" pattern-separator=";" />
<xsl:templatematch="/">
<HTML><BODY>
<tableborder="1"cellpadding="2"cellspacing="0">
<tr align="center">
<td><b>Data</b></td>
<td><b>Default</b></td>

27
`

<td><b>European</b></td>
<td><b>US</b></td>
<td><b>Example</b></td>
</tr>
<tralign="right">
<td>24535.2</td>
<td><xsl:value-ofselect="format-number(24535.2,'###,###.00')"/></td>
<td><xsl:value-ofselect="format-number(24535.2,'###.###,00',
'european')"/></td>
<td><xsl:value-ofselect="format-number(24535.2,'###,###.00','us')"/></td>
<td><xsl:value-ofselect="format-number(24535.2,'###,###.00',
'example')"/></td>
</tr>
</table>
</BODY></HTML>
</xsl:template>
</xsl:stylesheet>

28
`

Output

Result
TheformattingofXML/XSLissuccessfullycompleted

29
Ex.No:8
XSL FORMATTING

XMLFile (family.xml)
<?xml version="1.0"?>
<?xml-stylesheettype="text/xsl"href="family.xsl"?>
<family>
<person>
<given-nameage="10">
<name>Fred</name>
<nick-name>Freddy</nick-name>
</given-name>
<family-name>Smith</family-name>
</person>
<person>
<given-nameage="10">
<name>Robert</name>
<nick-name>Bob</nick-name>
</given-name>
<family-name>Smith</family-name>
</person>
</family>

XSLTFile(family.xsl)
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="person">
<p>
<xsl:copy-ofselect="given-name"/>
<xsl:text></xsl:text>
<xsl:copy-ofselect="family-name"/>
</p>
</xsl:template>

</xsl:stylesheet>

30
`

Output

Result
TheformattingofXML/XSLissuccessfullycompleted

31
` Ex.No:.9

XPATH IMPLEMENTATION

XPATH

<?xmlversion="1.0"encoding="UTF-8"?>
<xsl:stylesheet
version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:templatematch="/">

<palign="center"><fontcolor="blue"> COMPUTERSHOP</font></p>
<xsl:for-eachselect="purchase/product">
<b>Productid:</b><xsl:value-ofselect="@id"/><br/> Name :
<xsl:value-of select="@name"/><br/>
PricePerUnit:<xsl:value-ofselect="@price"/><br/>
<br/><br/>

<xsl:for-eachselect="order">
<b>orderid:</b><xsl:value-ofselect="@id"/><br/> Quantity
<xsl:value-of select="@quantity"/><br/>
ordervalue<xsl:value-ofselect='(../@price)*(quantity)'/><br/>
</xsl:for-each>

<HR/>
<b> Product Sales Value : <xsl:value-of
select='(./@price)*sum(./order/quantity)'/></b><br/><hr/><br/>

</xsl:for-each></xsl:template></xsl:stylesheet>

32
`

ImportingXpathfileinXmlfile

<?xmlversion="1.0"?>
<?xml-stylesheettype="text/xsl"href="xpat.xsl"?>
<purchase>

<productid="P001"name="COMPUTER"price="45000">
<orderid="001"><quantity>30</quantity></order>
<orderid="002"><quantity>50</quantity></order>
</product>

<productid="P002"name="PRINTER"price="10000">
<orderid="003"><quantity>20</quantity></order>
<orderid="004"><quantity>15</quantity></order>

</product>
</purchase>

33
`

Output

Result:
XMLfileexecutedsuccessfully.

34
` Ex.No:.10

XMLDOCUMENTCLASS

<?xmlversion="1.0"?>
<countries>
<countrycname="India">
<statename="TamilNadu">TN</state>
<statename="Keral">TN</state>
<statename="Rajasthan">TN</state>
<statename="Assam">TN</state>
</country>

<countrycname="UnitedStates">
<statename="Florida">FL</state>
<statename="Georgia">GA</state>
<statename="Colorado">CO</state>
<statename="Hawaii">HI</state>
</country>
</countries>

<html>
<body>
<SCRIPT LANGUAGE="JavaScript">
varxmlDoc=newActiveXObject("Microsoft.XMLDOM");
xmlDoc.load("country.xml");
varroot=xml.Doc.documentElement.lastChild.lastChild.previousSibling;
document.write("nodeType:"+root.nodeType+"<BR>");
document.write("nodeType:"+root.nodeName+"<BR>");
document.write("Text:"+root.text+"<BR>");
</SCRIPT>
</body>
</html>

35
`

OUTPUT

Result:
XMLfileexecutedsuccessfully.

36
`

37

You might also like