0% found this document useful (0 votes)
184 views57 pages

XML Lab Manual

This document is a lab manual for the PCA15501 course on XML and Web Services at SRM University, detailing exercises for creating XML files, implementing DTDs, XML schemas, and CSS. It includes step-by-step algorithms for various XML-related tasks, such as creating address books and transforming XML with XSLT. The manual is intended for postgraduate students in the MCA program, batch 2016-2018.

Uploaded by

indrajeet
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)
184 views57 pages

XML Lab Manual

This document is a lab manual for the PCA15501 course on XML and Web Services at SRM University, detailing exercises for creating XML files, implementing DTDs, XML schemas, and CSS. It includes step-by-step algorithms for various XML-related tasks, such as creating address books and transforming XML with XSLT. The manual is intended for postgraduate students in the MCA program, batch 2016-2018.

Uploaded by

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

` SRM UNIVERSITY

Ramapuram Campus, Chennai-600089.


Department Of Computer Applications

LAB
MANUAL
PCA15501 – XML & WEB SERVICES

For
P.G. Degree Programme
Batch (2016– 2018)
MCA (5th Semester)

Prepared By Approved By

1
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
INDEX

Sl.No EXERCISE Page No

1. SIMPLE XML FILE CREATION-ELEMENTS 3

2. SIMPLE XML FILE CREATION-ATTRIBUTES 6

3. INTERNAL DTD IMPLEMENTATION 9

4. EXTERNAL DTD IMPLEMENTATION 12

5. XML SCHEMA 15

6. CASCADING STYLE SHEET 18

7. XSL –TRANSFORMATION 21 & 30

8 XSL FORMATTING 35 & 39

9 XPATH IMPLEMENTATION 42

10 XML DOCUMENT CLASS 46

11 XML PARSER ERROR CLASS 49

12 XML BINDING IN DATASET 52

13 WEB SERVICES 55

2
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

EX.NO.: 01

SIMPLE XML FILE FOR ADDRESS BOOK

Aim :-creating a simple XML document


Algorithm :
Step 1:open notepad.
Step 2: define root element as addbook
Step 3: Define Element as details.
Step 4: define sub element like name,DOB,city,state,pincode, work.
Step 5: define attribute for the work as title and company.
Step 6: close all the tag of subsequent element
Step 7. save the file with .xml extension.
Step 7: Open Browser and open the XML file.

3
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
**XML file

<?xml version="1.0"?>
<addbook>
<details>
<name>John Smith</name>
<DOB>2-january-1978</DOB>
<city>Chennai</city>
<state>Tamilnadu</state>
<pincode>600089</pincode>
<work title="Project Manager" company="TCS" city="Chennai"></work>
<phoneno>984002561</phoneno>
<email>john@yahoo.in</email>
</details>
<details>
<name>Annie</name>
<DOB>30-March-1982</DOB>
<city>Ville Parle</city>
<state>Mumbai</state>
<pincode>876001</pincode>
<work title="HR" company="Wipro" city="Mumbai"></work>
<phoneno>9600560190</phoneno>
<email>annie@gmail.com</email>
</details>
</addbook>

4
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

OUTPUT

Result:
The XML Document executed successfully.

5
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
EX.NO.: 02

SIMPLE XML DOCUMENT-ATTRIBUTES

Aim :-creating a simple XML document with attributes


Algorithm :
Step 1:open notepad.
Step 2: define root element as ADDRESSBOOK
Step 3: Define Sub Element .
Step 4: define sub attributes like name,DOB,city,state,pincode,email, phone.
Step 5: close all the tags
Step 7. save the file with .xml extension.
Step 7: Open Browser and open the XML file.

6
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
SIMPLE XML DOCUMENT-ATTRIBUTES
<ADDRESSBOOK>
<PERSON1
Name="N Krishnamoorthy"
Age="45"
Dob="06-02-1976"
Mobile="944339443"
Mail="krishnamoorthy@yahoo.com"
Streetname="Thiruneermalai Road"
Houseno="303"
Area="Thirumudivakkam"
Pincode="600044"
City="Chennai"
State="Tamilnadu"
/>
<PERSON2
Name="Balavinayagam"
Age="27"
Dob="09-06-1990"
Mobile="9600365435"
Mail="balavinayak@yahoo.com"
Streetname="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="Sushmi_67@gmail.com"
Streetname="Haneefa Colony"
Houseno="548"
Area="Vaniyambadi"
Pincode="625689"
City="Vaniyambadi"
State="Tamilnadu"
/>
</ADDRESSBOOK>

7
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Output:

Result:
The simple XML document for generating address book is done with the attributes.

8
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No:.3

INTERNAL DTD IMPLEMENTATION

Aim : Create an XML file using the Internal DTD

Algorithm:

Step 1: Open <!DOCTYPE declare root element as ‘bookstore’.

Step 2: Declare elements name, topic into bookstore.

Step 3: Declare elements name, ISBN attribute of book into topic.

Step 4: Elements name, title, author as PCDATA.

Step 5: Root element consist of Mike’s store as name value, topic consist of
xml as name value, ISBN is 120-90-100 attribute of book, title include
some contents, Mike Jervis as author value

9
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
INTERNAL DTD

XML file to store book details (with DTD)

<?xml version="1.0"?>
<!DOCTYPE bookstore [
<!ELEMENT bookstore (name,topic+)>
<!ELEMENT topic (name,book*)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT book (title,author)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT author (#PCDATA)>
<!ATTLIST book ISBN CDATA "0">

]>
<bookstore>
<name>Mike's Store</name>
<topic>
<name>XML</name>
<book ISBN="120-90-100">
<title>Mike's Guide To DTD's and XML Schemas</title>
<author>Mike Jervis</author>
</book>
</topic>
</bookstore>

10
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

OUTPUT

Result:
XML file executed successfully.

11
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No:.4

EXTERNAL DTD IMPLEMENTATION

Aim: Create an external DTD and implement it in XML file.

Algorithm:
Step 1: Open Notepad.
Step 2: Create a DTD file for element and sub elements.
Step 3: Save the file as. DTD extension.
Step 4: Create a new XML file
Step 5: Implement the DTD file with syntax
[!DOCTYPE SYSTEM “filename”]
Step 6: save the file with .xml extension.
Step 7: Run the XML file in Browser.

12
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

External DTD

<?xml version="1.0"?>
<!ELEMENT Combomeal (burger,fries,drink)>
<!ENTITY COLA "Pepsi" >
<!ELEMENT burger(name,bun)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT bun (meat,cheese,chick)>
<!ATTLIST bun bread (white|wheat) #REQUIRED>
<!ELEMENT meat EMPTY>
<!ELEMENT cheese EMPTY>
<!ELEMENT chick EMPTY>
<!ELEMENT fries EMPTY>
<!ATTLIST fries size (small|medium|large) #REQUIRED>
<!ELEMENT drink (#PCDATA)>
<!ATTLIST drink size (small|medium|large) #REQUIRED>

By importing a .dtd file which has been written separately


(.xml file)
<?xml version="1.0"?>
<!DOCTYPE Combomeal SYSTEM "DTD1.dtd">
<Combomeal>
<burger>
<name>TASTY BURGER</name>
<bun bread="white">
<meat/>
<cheese/>
<chick/>
</bun>
</burger>
<fries size="large"/>
<drink size="large">&COLA;</drink>
</Combomeal>

13
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
Output:

Result:
XML file executed successfully.

14
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No:.5

XML SCHEMA

Aim :-creating a XML Schma

Algorithm :

Step 1:open notepad for creating .dtd file for xml schema definition .
Step 2: define the data types of elements which is to be defined in xml file.
Step 3: close the root element of .dtd file and save it.
Step 4: Open another notepad for xml file
Step 5: define respected element as defined in the .dtd file and define the value.
Step6. close all the subsequent elements tag.
Step 7: save the file with .xml extension
Step 8: Open Browser and open the XML file.

15
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

XML SCHEMA

<?xml version="1.0"?>
<xs:schema>
<xmlns:xs="http://www.w3.org/2001/XMLNS schema"
target namespace="http://www.w3schools.com
element form default="qualified">
<xs:element name="to"type="xs:string"/>
<xs:element name="heading"type=xs:string"/>
<xs:element name="body"type="xs:string"/>
</xs:sequence>
</xs:complex type>
</xs:element>
</xs:schema>

XML file

<?xml version="1.0"?>
<note xmlns="http://www.w3cschools.com"
xmlns:xsi="http://www.w3.org/2001/XMLNS schema_instance"
xsi:xmlSchemaLocation="http:/w3cschoools.com note.xsd">
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>don't forgot me</body>
</note>

16
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
Output:

Result:
XML file executed successfully.

17
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
Ex.No :.6

CASCADING STYLE SHEET

Aim :-create an xml file to implement css concept.

Algorithm :
Step 1:open notepad.
Step 2:write css code for the elements and sub elements and save it with .css
extension.
Step 3: Create a new XML file and implement the css file in XML file. Save it
with .css extension.
Step 4: Open Browser and open the XML file.

18
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

CASCADING STYLE SHEET


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;

19
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Importing css file in XML file

<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="bookes.css"?>
<bookstore>
<book> Book Detail </book>
<title> Title: ANSI C </title>
<author> Author : Balagurusamy </author>
<rs> Price : 250 </rs>
</bookstore>

Output:

Result:
XML file executed successfully.

20
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No:.7
XSL TRANSFORMATION

Aim:
To create a simple XSLT transformation from XSL to XML.

Algorithm:

Step-1: Create a XSLT document using notepad.

Step-2: Using XSLT document, we can create a style sheet like Font Style, Font Size,

bgcolor,..etc. and write the following code: :“cdcatalog.xsl”

Step-3: Save the document as“ Filename.xsl”.

Step-4: Then create a XML document.

Step-5: Create a Link with the XSLT document using href tag=”Filename.xsl” and write

the following code: “Simpxsl.xml”

Step-6: Save the document as “Simpxsl.xml”.

Step-7: Then execute the xml file and view the output:

21
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
XSL TRANSFORMATION

Source Code:

Filename:“cdcatalog.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>
<h2>My CD Collection</h2>
<table border="1">
<trbgcolor="#9acd32">
<th style="text-align:left">Title</th>
<th style="text-align:left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

22
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Source Code:
Filename: “Simpxsl.xml”
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
<cd>
<title>Still got the blues</title>

23
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
<artist>Gary Moore</artist>
<country>UK</country>
<company>Virgin records</company>
<price>10.20</price>
<year>1990</year>
</cd>
<cd>
<title>Eros</title>
<artist>Eros Ramazzotti</artist>
<country>EU</country>
<company>BMG</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>One night only</title>
<artist>Bee Gees</artist>
<country>UK</country>
<company>Polydor</company>
<price>10.90</price>
<year>1998</year>
</cd>
<cd>
<title>Sylvias Mother</title>
<artist>Dr.Hook</artist>
<country>UK</country>
<company>CBS</company>
<price>8.10</price>
<year>1973</year>
</cd>
<cd>
<title>Maggie May</title>
<artist>Rod Stewart</artist>
<country>UK</country>
<company>Pickwick</company>
<price>8.50</price>
<year>1990</year>

24
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
</cd>
<cd>
<title>Romanza</title>
<artist>Andrea Bocelli</artist>
<country>EU</country>
<company>Polydor</company>
<price>10.80</price>
<year>1996</year>
</cd>
<cd>
<title>When a man loves a woman</title>
<artist>Percy Sledge</artist>
<country>USA</country>
<company>Atlantic</company>
<price>8.70</price>
<year>1987</year>
</cd>
<cd>
<title>Black angel</title>
<artist>Savage Rose</artist>
<country>EU</country>
<company>Mega</company>
<price>10.90</price>
<year>1995</year>
</cd>
<cd>
<title>1999 Grammy Nominees</title>
<artist>Many</artist>
<country>USA</country>
<company>Grammy</company>
<price>10.20</price>
<year>1999</year>
</cd>
<cd>
<title>For the good times</title>
<artist>Kenny Rogers</artist>
<country>UK</country>

25
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
<company>Mucik Master</company>
<price>8.70</price>
<year>1995</year>
</cd>
<cd>
<title>Big Willie style</title>
<artist>Will Smith</artist>
<country>USA</country>
<company>Columbia</company>
<price>9.90</price>
<year>1997</year>
</cd>
<cd>
<title>Tupelo Honey</title>
<artist>Van Morrison</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>The very best of</title>
<artist>Cat Stevens</artist>
<country>UK</country>
<company>Island</company>
<price>8.90</price>
<year>1990</year>
</cd>
<cd>

26
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
<title>Stop</title>
<artist>Sam Brown</artist>
<country>UK</country>
<company>A and M</company>
<price>8.90</price>
<year>1988</year>
</cd>
<cd>
<title>Bridge of Spies</title>
<artist>T`Pau</artist>
<country>UK</country>
<company>Siren</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Private Dancer</title>
<artist>Tina Turner</artist>
<country>UK</country>
<company>Capitol</company>
<price>8.90</price>
<year>1983</year>
</cd>
<cd>
<title>Midtomnatten</title>
<artist>Kim Larsen</artist>
<country>EU</country>
<company>Medley</company>
<price>7.80</price>
<year>1983</year>
</cd>
<cd>
<title>Pavarotti Gala Concert</title>
<artist>Luciano Pavarotti</artist>
<country>UK</country>
<company>DECCA</company>
<price>9.90</price>

27
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
<year>1991</year>
</cd>
<cd>
<title>The dock of the bay</title>
<artist>Otis Redding</artist>
<country>USA</country>
<company>Atlantic</company>
<price>7.90</price>
<year>1987</year>
</cd>
<cd>
<title>Picture book</title>
<artist>Simply Red</artist>
<country>EU</country>
<company>Elektra</company>
<price>7.20</price>
<year>1985</year>
</cd>
<cd>
<title>Red</title>
<artist>The Communards</artist>
<country>UK</country>
<company>London</company>
<price>7.80</price>
<year>1987</year>
</cd>
<cd>
<title>Unchain my heart</title>
<artist>Joe Cocker</artist>
<country>USA</country>
<company>EMI</company>
<price>8.20</price>
<year>1987</year>
</cd>
</catalog>

28
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

OUTPUT

Result:
Thus the program to convert the simple XSLT transformation from XSL to XML
has been executed successfully.

29
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No:7
XSL TRANSFORMATION-BOOK SHOP

Aim:
To create a simple XSLT transformation from XSL to XML.

Algorithm:

Step-1: Create a XSLT document using notepad.

Step-2: Using XSLT document, we can create a style sheet like Font Style, Font Size,

bgcolor,..etc. and write the following code:

Step-3: Save the document as :“style.xsl”.

Step-4: Then create a XML document.

Step-5: Create a Link with the XSLT document using href tag=”style.xsl” and write the

following code:

Step-6: Save the document as “Book.xml”.

Step-7: Then execute the xml file and view the output:

30
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

XSL TRANSFORMATION- BOOK SHOP

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<BooksforYou>
<Book BookID = "1000">
<Title>If Tomorrow Comes</Title>
<Rate>275</Rate>
<Author>Krishna Kumar</Author>
<Publication>Pearson</Publication>
<ISBN>111-222-333</ISBN>
</Book>
<Book BookID ="1001">
<Title>.NET Expert Guide</Title>
<Rate>475</Rate>
<Author>James</Author>
<Publication>Microsoft Press</Publication>
<ISBN>121-222-333</ISBN>
</Book>
<Book BookID ="1002">
<Title>C Projects</Title>
<Rate>275</Rate>
<Author>YashwantP.Kanetkar</Author>
<Publication>BPB Publications</Publication>
<ISBN>111-232-333</ISBN>
</Book>
<Book BookID ="1003">
<Title>Let us C</Title>
<Rate>225</Rate>
<Author>YashwantP.Kanetkar</Author>
<Publication>BPB Publications</Publication>
<ISBN>111-222-353</ISBN>
</Book>
31
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

<Book BookID ="1004">


<Title>Com and Beyond in VC++</Title>
<Rate>375</Rate>
<Author>YashvantP.Kanetkar</Author>
<Publication>BPB Publications</Publication>
<ISBN>111-555-333</ISBN>
</Book>
</BooksforYou>

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

<xsl:template match="/">

<html>

<body background="tech.gif">

<h1 align="center">
<font color="blue">Books at your own Cyber Shoppe</font>
</h1>

<table border="4" cellpadding="10" cellspacing="5" align="center"


bgcolor="lightgreen" bordercolor="green">

<tbody>
<tr>
<th>Book ID</th>
<th>Title</th>
<th>Rate</th>
<th>Author</th>
<th>Publication</th>

32
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
<th>ISBN</th>
</tr>

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

</tbody>
</table>

</body>
</html>

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

33
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

OUTPUT

Books at your own Cyber Shoppe


Book
Title Rate Author Publication ISBN
ID

If Tomorrow 111-
1000 275 Krishna Kumar Pearson
Comes 222-333

.NET Expert Microsoft 121-


1001 475 James
Guide Press 222-333

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

BPB 111-
1003 Let us C 225 YashwantP.Kanetkar
Publications 222-353

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

Result:
Thus the program to convert the simple XSLT transformation from XSL to
XML has been executed successfully.

34
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No: 8

XSL FORMATTING

Aim:

To demonstrate XSL formatting-how to format numbers using the


<xsl:decimal-format> element.

Algorithm:

Step-1: Create a XML document using notepad.

Step-2: In the XML Document specify the .xsl file name in href.

Step-3: Save the document as“ Root.xml”.

Step-4: Then create a XSLT document.

Step-5: Create a Link with the XSLT document using href tag write the code:

Step-6: Save the document as “DecimalformaT.xsl”.

Step-7: Then execute the xml file and view the output:

35
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

XSL FORMATTING

XML File (root.xml)

<?xml version="1.0"?>

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

<root/>

XSL Document

//decimalformat.xsl

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="decimalformat.xsl"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html"/>
<xsl:decimal-format name="us" decimal-separator='.' grouping-separator=',' />
<xsl:decimal-format name="european" decimal-separator=',' grouping-
separator='.' />
<xsl:decimal-format name="example" decimal-separator="." grouping-
separator=","
infinity="INFINITY" minus-sign="-" NaN="Not a Number" percent="%"
per-mille="m" zero-digit="0" digit="#" pattern-separator=";" />
<xsl:template match="/">
<HTML><BODY>
<table border="1" cellpadding="2" cellspacing="0">
<tr align="center">
<td><b>Data</b></td>
<td><b>Default</b></td>
36
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
<td><b>European</b></td>
<td><b>US</b></td>
<td><b>Example</b></td>
</tr>
<tr align="right">
<td>24535.2</td>
<td><xsl:value-of select="format-number(24535.2, '###,###.00')"/></td>
<td><xsl:value-of select="format-number(24535.2, '###.###,00',
'european')"/></td>
<td><xsl:value-of select="format-number(24535.2, '###,###.00', 'us')"/></td>
<td><xsl:value-of select="format-number(24535.2, '###,###.00',
'example')"/></td>
</tr>
</table>
</BODY></HTML>
</xsl:template>
</xsl:stylesheet>

37
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
Output

Result
The formatting of XML/XSL is successfully completed

38
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No:8
XSL FORMATTING

Aim:

To demonstrate XSL formatting-how to format using element.

Algorithm:

Step-1: Create a XML document using notepad.

Step-2: In the XML Document specify the .xsl file name in href.

Step-3: Save the document as“ family.xml”.

Step-4: Then create a XSLT document.

Step-5: Create a Link with the XSLT document using href tag write the code:

Step-6: Save the document as “family.xsl”.

Step-7: Then execute the xml file and view the output:

39
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

XML File (family.xml)


<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="family.xsl"?>
<family>
<person>
<given-name age="10">
<name>Fred</name>
<nick-name>Freddy</nick-name>
</given-name>
<family-name>Smith</family-name>
</person>
<person>
<given-name age="10">
<name>Robert</name>
<nick-name>Bob</nick-name>
</given-name>
<family-name>Smith</family-name>
</person>
</family>

XSLT File (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-of select="given-name"/>
<xsl:text> </xsl:text>
<xsl:copy-of select="family-name"/>
</p>
</xsl:template>

</xsl:stylesheet>

40
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Output

Result
The formatting of XML/XSL is successfully completed

41
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No:. 9

XPATH IMPLEMENTATION

Aim: Create a XML file to implement XPATH concept.

Algorithm:

Step 1: Open notepad.


Step 2: Write XSL code for the element and sub elements. Save it with .xsl
extension.
Step 3: Create a new XML file and implement the XSL file in XML file. Save it
with .xml extension.
Step 4: Open Browser and open the XML file.

42
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

XPATH

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


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

<p align="center"> <font color="blue"> COMPUTER SHOP </font> </p>


<xsl:for-each select="purchase/product">
<b> Product id : </b> <xsl:value-of select="@id"/> <br/>
Name : <xsl:value-of select="@name"/> <br/>
Price Per Unit : <xsl:value-of select="@price"/> <br/>
<br/> <br/>

<xsl:for-each select="order">
<b> order id: </b> <xsl:value-of select="@id"/> <br/>
Quantity <xsl:value-of select="@quantity"/> <br/>
order value <xsl:value-of select='(../@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>

43
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Importing Xpath file in Xml file

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="xpat.xsl"?>
<purchase>

<product id="P001" name="COMPUTER" price="45000">


<order id="001"> <quantity> 30 </quantity></order>
<order id="002"> <quantity> 50 </quantity></order>
</product>

<product id="P002" name="PRINTER" price="10000">


<order id="003"> <quantity> 20 </quantity></order>
<order id="004"> <quantity> 15 </quantity></order>

</product>
</purchase>

44
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
Output

Result:
XML file executed successfully.

45
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No:.10

XML DOM CLASS

Aim :-creating a XML DOM class

Algorithm :
Step 1:open notepad for creating a simple xml file.
Step 2: define element countries as root. Country and state as subelement.
Step 3: close the root element of .xml file and save it.
Step 4: Open another notepad for creating .html file for DOM class
Step 5: declare JavaScript as Script language and print the root and child
element of .xml file.
Step6. close all the subsequent elements tag.
Step 7: save the file with .html extension
Step 8: Open Browser and open the HTML file

46
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
XML DOCUMENT CLASS

<?xml version="1.0"?>
<countries>
<country cname="India">
<state name="TamilNadu">TN</state>
<state name="Keral">TN</state>
<state name="Rajasthan">TN</state>
<state name="Assam">TN</state>
</country>

<country cname="United States">


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

<html>
<body>
<SCRIPT LANGUAGE="JavaScript">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.load("country.xml");
var root=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>

47
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
OUTPUT

Result:
XML file executed successfully.

48
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No:.11

XML PARSER ERROR CLASS

Aim: To identify the error in the XML file using the XML parser error
functions.

Algorithm:

Step 1: Open Notepad


Step 2: Create an XML file with at least two or three elements with some error.
[Error means the Tags may differ in Case]
Step 3: Create a HTML file. Implement the XML file.
Step 4: Use the error functions to fetch the Error in the XML file.
Step 5: Open browser Run the HTML file.

49
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

XML PARSER ERROR

<?xml version="1.0"?>
<countries>
<country cname="Canada">
<state name="India">IND</state>
<state name="Australia">AUS</state>
</country>
<country cname="United States">
<State name="Colorado">CO</state>
<state name="Delaware">DE</state>
</country>
</Countries>

<html>
<body>
<scrit language="JavaScript">
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("dom.xml");
if(xmlDoc.parseError.errorCode != 0)
{
document.writeln("Error" + xmlDoc.parseError.errorCode+"on line"
+xmlDoc.parseError.line+",position"+xmlDoc.parseError.linepos+"<BR><BR>
");
document.writeln(xmlDoc.parseError.reason+"<BR><BR>");
document.writeln(xmlDoc.parseError.srcText+"<BR><BR>");
}
</script>
</body>
</html>

50
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

OUTPUT

Result:
XML file executed successfully.

51
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
Ex.No:.12

XML BINDING IN DATASET

Aim: Using XML file as a dataset through ASP .Net

Algorithm:

Step 1: Create an XML file with at least two or three tags.


Step 2: Create a new website in ASP .Net
Step 3: Go to solution explorer right click ->add Existing item ->add XML file
in website.
Step 4: Add a gridview control in design view.
Step 5: Double click on page and go to page load option.
Step 6: Write page load code to access the dataset from xml file in grid view.

52
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

XML BINDING IN DATASET

<?xml version="1.0"?>
<addbook>
<details>
<name>John Smith</name>
<DOB>2-january-1978</DOB>
<city>Chennai</city>
<state>Tamilnadu</state>
<pincode>600089</pincode>
<work title="Project Manager" company="TCS" city="Chennai"></work>
<phoneno>984002561</phoneno>
<email>john@yahoo.in</email>
</details>

<details>
<name>Annie</name>
<DOB>30-March-1982</DOB>
<city>Ville Parle</city>
<state>Mumbai</state>
<pincode>876001</pincode>
<work title="HR" company="Wipro" city="Mumbai"></work>
<phoneno>9600560190</phoneno>
<email>annie@gmail.com</email>
</details>
</addbook>

53
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications
CODE for page Load

public partial class _Default : System.Web.UI.Page


{
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(MapPath("simple.xml"));
GridView1.DataSource = ds;
GridView1.DataBind();
}
}

OUTPUT

Result:
XML file executed successfully.

54
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

Ex.No:.13

WEB SERVICES

Aim: - To Write a asp.net program for web service.

Algorithm:-
Step 1: Start
Step 2: Click on start | Go to Program | Go To Microsoft Visual Studio
2005 | Click On Microsoft Visual Studio 2005

Step 3: Click on File Menu | Go to File | Go to New | Click on New


asp.net web service.
Step 4: Add the web method as mul and write the code
Go to solution explorer
Step 5: Right Click on Solution Explorer and Add web reference and
choose web services in solution| then chose the service is a
“service”; and then click on add reference.
Step 6: And then add new web form
Step 7: And drag the 3 textbox and 3 labels and one button and change
the appropriate name using text property.
Step 8: double click on button and write the code
Step 9: Run the project.
Step 10: Stop

55
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

WEB SERVICES

CODE FOR [WebMethod]

public int mul(int a ,int b)

{
return a * b;
}

CODE ON BUTTON

protected void Button1_Click(object sender, EventArgs e)

{
localhost.Service s = new localhost.Service();
int a= Int32.Parse(TextBox1.Text);
int b = Int32.Parse(TextBox2.Text);
int res = s.mul(a, b);
TextBox3.Text = res.ToString();

56
` SRM UNIVERSITY
Ramapuram Campus, Chennai-600089.
Department Of Computer Applications

OUTPUT

Result:
XML file executed successfully.

57

You might also like