XML Lab
XML Lab
XML Lab
BCA
XML AND WEB SERVICES LAB
Name : _____________________________
Roll No : _____________________________
Semester :
Academic Year :
INDEX
Exp Page
Date Name of the Experiment Signature
No No
1 XML Document Creation
3 XSL Transformation
Aim:
To create a simple XML document to display the address book.
Procedure:
Step-1: Create the xml document using notepad.
Step-2: Create the addressbook as a root tag.
Step-3: Followed by create a three employees address in detail using different tag.
Step-4: Save the file as “Employee.xml”.
Step-5: Finally execute the program in Internet Explorer to view the output.
Source Code:
Filename: “Employee.xml”
Result:
Thus, the simple xml document creation has been executed successfully.
Exp No:2 IMPORTING AND EXPORTING XML DOCUMENT
Date: IN DATABASE
Aim:
To create a xml document and database for importing and exporting xml document
into database.
Procedure:
Step-1: Start the process.
Step-2: Create the xml document using notepad and write the following code:
Source Code:
Filename: “Hello.xml”
If the Developer tab is not available, you need to enable it in the options. Click on File, and then go
all the way down to Options. Click on the Customize Ribbon section, and in the column on the right,
there should be a list of tabs called Main Tabs that you can check or uncheck.
Find where it says Developer, and make sure the box is checked. Then click OK. The Developer tab
should now be up top, to the right of the View tab.
Step-6: To import the xml document click->Developer tab ->Sources.
Step-7: Add an XML Map:
In the XML Source task pane, click the XML Maps option at the very bottom right. A window will
pop up.
Click Add to add a browse the location of xml document and click ok.
Step-8: Drag and drop XML elements into the spreadsheet and import the XML file into Excel.
Add the new record into the database.
Step-9: Once finished converting each column into an XML element, return to the Developer tab,
find the XML section again, and click Export. Save your XML file, and then open it in Notepad to
see the results:
Result:
Thus, the program to importing and exporting XML into Excel-database has been executed
successfully.
Exp No:3 XSL TRANSFORMATION
Date:
Aim:
To create a simple XSLT transformation from XSL to XML.
Procedure:
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:
Source Code:
Filename:“cdcatalog.xsl”
Source Code:
Filename: “Simpxsl.xml”
Result:
Thus the program to convert the simple XSLT transformation from XSL to XML has
been executed successfully.
Exp No:4(i) INTERNAL DTD CREATION
Date:
Aim:
To create a XML program for Internal DTD(Document Type Definition) creation.
Procedure:
Step-1: Open the notepad.
Step-2: Create a DTD document for book details.
Step-3:Save the document as “Filename.xml”.
Step-4:Type a XML Parser using HTML coding.
Step-5:Save the document as “Filename.html”.
Step-6:Execute the program in Internet Explorer.
Source Code:
File name:“Sche.xml”
Filename:“Par.html”
<html>
<body>
<h3>This demonstrates a parser error:</h3>
<script type="text/javascript">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.validateOnParse="true";
xmlDoc.load("Sche.xml");
document.write("<br/>Error Code:");
document.write(xmlDoc.parseError.errorCode);
document.write("<br/>Error Reason:");
document.write(xmlDoc.parseError.reason);
document.write("<br/>Error Line:");
document.write(xmlDoc.parseError.line);
</script>
</body>
</html>
Output:
Result:
Thus, the XML program for creating Internal DTD has been executed successfully.
Exp No:4(ii) EXTERNAL DTD CREATION
Date:
Aim:
To create a XML program for External DTD(Document Type Definition) creation.
Procedure:
Step-1: Open the notepad.
Step-2: Create a DTD document for book details.
Step-3: Save the document as “Filename.dtd”.
Step-4: Create a XML document for book details.
Step-5: Save the document as “Filename.xml”.
Step-6: Type a XML Parser using HTML coding.
Step-7: Save the document as “Filename.html”.
Step-8: Execute the program in Internet Explorer.
Source Code:
Filename:“not.dtd”
Filename: “Sc.xml”
<html>
<body>
<h3>This demonstrates a parser error:</h3>
<script type="text/javascript">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.validateOnParse="true";
xmlDoc.load("Sc.xml");
document.write("<br/>Error Code:");
document.write(xmlDoc.parseError.errorCode);
document.write("<br/>Error Reason:");
document.write(xmlDoc.parseError.reason);
document.write("<br/>Error Line:");
document.write(xmlDoc.parseError.line);
</script>
</body>
</html>
Output:
Result:
Thus, the XML program for creating External DTD has been executed successfully.
Exp No:5 XML SCHEMA CREATION
Date:
Aim:
To create a program for XML Schema creation and display element and attributes.
Procedure:
Step-1: Open the XMLwriter.
Step-2: Click File->New->XML Document and name the Filename.
Step-3:Type the following program:
Source Code:
Filename:“Sche.xml”
Source Code:
Filename:“sche.xsd”
Result:
Thus, the program for XML Schema creation and display element and attributes has
been executed successfully.
Exp No:6 PARSING XML DOCUMENT USING
Date: DOM/SAX PARSER
Aim:
To create a parsing XML document using DOM(Document Object Model) parser.
Procedure:
Step-1: Open the notepad.
Step-2: Create a xml document for book collection.
Step-3: Save the document as “Filename.xml”.
Step-4: Type the following program:
Source Code:
Filename:“Bookcollection.xml”
<bookdb>
<book>
<name>Java Complete Reference</name>
<author>lan</author>
<year>2001</year>
<publication>Tata McDraw Hill</publication>
</book>
<book>
<name>C# Complete Reference</name>
<author>balagurusamy</author>
<year>2006</year>
<publication>Persion Addition</publication>
</book>
<book>
<name>Complete Reference</name>
<author>Kanithkar</author>
<year>2005</year>
<publication>Tata McDraw Hill</publication>
</book>
</bookdb>
Source Code:
Filename: “Bookdetailsdom.html”
<html>
<head>
<script language="javascript">
var root;
var xmldoc=new ActiveXObject("Microsoft.XMLDOM");
xmldoc.load("Bookcollection.xml");
function start()
{
if(xmldoc.readyState=="4")
loading();
else
alert("could not load");
}
function loading()
{
var i;
root=xmldoc.documentElement;
var count;
count=root.childNodes.length;
for(i=0;i<count;i++)
{
document.write(root.childNodes.item(i).text+"<br>");
}
}
</script>
</head>
<body onLoad="start()">
</body>
</html>
Result:
Thus, the parsing XML document using DOM(Document Object Model) parser has been
executed successfully.