Professional Documents
Culture Documents
XML Lab File
XML Lab File
Submitted by: Jaideep Singh Dang Submitted to: Mr. Pardeep Singh
Branch. : B.Tech-CSE-OSOS(6th sem)
Roll no. : R100214031
SAP Id. : 500038462
Date of
Page Date of
Experiment Experimen Remarks
no. Submission
t
a. Open MS-Excel.
b. In MS-Excel, click on DATA tab.
c. DATA->From Other Sources, select From XML Import Data.
d. Select XML file to be imported from the BROWSE window.
e. Click Next Button.
f. Finish
EXPERIMENT 1
Created by Jaideep Singh Dang, B.Tech-CSE-OSS(6 th SEM), R100214031,
500038462
Topic: Case Study
a. Open MS-ACCESS.
b. Go to EXTERNAL DATA tab.
c. In export section, a symbol with name of TO XML is there. Click on it.
d. Click NEXT and FINISH.
e. File is exported.
NOTE: THE TABLE YOU WILL SELECT WILL ONLY BE EXPORTED
TO XML FILE IN XSD FORMAT.
EXPERIMENT 2
Topic: XML Document Creation
Q1. Write a XML program to store student data[name(first name, last
name), address(street, area, town, state), roll number].
PROGRAM
<?xml version="1.0" encoding=UTF-8"?>
<!This the prologue for the XML file where we need to declare an XML version >
<rno>R100214031</rno>
<name><fn>vibhor</fn><ln>rajput</ln></name>
<address><area>engineers enclave</area><street>gms
road</street><city>dehradun</city></address>
<rno>R100214070</rno>
</student>
<student>
<name><fn>himanshu</fn><ln>kataria</ln></name>
<address><area>fri</area><city>dehradun</city></address>
<rno>R100213980</rno>
</student>
OUTPUT
PROGRAM
<students>
<student>
<name><fn>Jaideep</fn><ln>Singh</ln></name>
<address><area>kehri gaon</area><street>prem
nagar</street><city>dehradun</city></address>
<rno>R100214031</student>
</rno> <!in this the roll no tag is not closed properly i.e in order of occurrence-->
<student>
<name><fn>vibhor</fn><ln>rajput</ln></Name>
<!in this the name tag is not closed properly i.e Tag Name is in
capitals here-->
<address><area>engineers enclave</area><street>gms
road</street><city>dehradun</city></address>
<rno>R100214070</rno>
EXPERIMENT 4
Topic: Creation of DTD
Q1. Write a XML program to store student data using internal DTD.
PROGRAM
<?xml version="1.0" encoding=UTF-8?> <!--This is the prologue for the xml file-->
<!DOCTYPE students [ <!--This is the declaration of the internal DTD -->
<!ELEMENT students (student,student,student)>
<!ATTLIST students id CDATA #REQUIRED>
<!--This is the attribute for the root element>
<!ELEMENT student (name, address, rno)>
<!ELEMENT name (fn, ln)>
<!ELEMENT fn (#PCDATA)>
<!ELEMENT ln (#PCDATA)> <!These are the elements of the root -->
<!ELEMENT address (area, street, city)>
<!ELEMENT area (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT rno (#PCDATA)>
<!ENTITY author Jaideep Singh."> <!--This is the declaration of the
entities-->
]> <!--This is the end of the declaration of the dtd file -->
<! From here a normal xml document is created in a well formed way>
<students>
<student>
<address><area>fri</area><street>Pandtwari</street><city>dehradun</city></address
>
<rno>R100213980</rno>
</student>
</students>
PROGRAM
External_dtd.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE root_element SYSTEM external_dtd_source.dtd">
<!This is the declaration of the URL for the external.dtd file-->
<students> <!this is the starting tag for the xml tag-->
<student>
<name><fn>Jaideep</fn><ln>Singh</ln></name>
<address><area>kehri gaon</area><street>prem
nagar</street><city>dehradun</city></address>
<rno>R100214072</rno>
</student>
<student>
<name><fn>vibhor</fn><ln>rajput</ln></name>
<address><area>engineers enclave</area><street>gms
road</street><city>dehradun</city></address>
<rno>R100214070</rno>
</student>
<student>
<name><fn>himanshu</fn><ln>kataria</ln></name>
<address><area>fri</area><street>Pandtwari</street><city>dehradun</city></address
>
Q3. Write a XML program to store student data using different attributes.
<!ELEMENT fn (#PCDATA)>
<!ELEMENT ln (#PCDATA)>
<!ELEMENT address (area, street, city)>
<!ELEMENT area (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT rno (#PCDATA)>
<!ELEMENT branch EMPTY>
<!ATTLIST branch type CDATA #REQUIRED>
<!ELEMENT fees EMPTY>
<!ATTLIST fees type (cheque|cash) "cash">
<!ELEMENT profile EMPTY>
<!DOCTYPE rootemployee [
<!ELEMENT rootemployee (employee)>
<!ELEMENT employee (id,name,department,project,contact,remarks,reviews)>
<!DOCTYPE rootemployee [
<!ELEMENT rootemployee (employee,employee)>
<!ELEMENT employee (id,name,department,project,contact,remarks,reviews)>
<!ELEMENT id (#PCDATA)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT department (post,field)>
<!ELEMENT post (#PCDATA)>
<!ELEMENT field (#PCDATA)>
<!ELEMENT project EMPTY>
<!ELEMENT contact (email,(landline|mobile))>
<!ELEMENT landline (#PCDATA)>
<!--The order of the occurrence is not maintained as the declaration-->
]>
<rootemployee>
<employee>
<id>1</id>
<name>jaideep</name>
<department>
<post>manager</post>
<!--The order of the occurrence is not maintained as the declaration as field
tag is not used properly or is missing-->
</department>
<project></project>
<contact>
<email>abc@xyz.com</email>
<mobile>9998886767</mobile>
</contact>
<remarks>88cc<name>ram</name></remarks>
<reviews>Good</reviews>
</employee>
<!--The document is not valid as the root tag is not present-->
<?xml version="1.0"?>
<xs:schema <!This is the root element of the xsd file-->
xmlns:xs="http://www.w3.org/2001/XMLSchema"
<!-- Indicates that the elements and data types used in the schema come
from the "http://www.w3.org/2001/XMLSchema" namespace.-->
targetNamespace="https://www.w3schools.com" <!--Indicates the
elements decribed in the document-->
xmlns="https://www.w3schools.com" <!--Indicates default namespace-->
elementFormDefault=qualified">
<!--indicates elements declared are qualified >
<xs:simpleType name=value">
<!--specifies that the elements are simple in structure-->
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="100"/>
</xs:restriction>
</xs:simpleType>
</xs:schema><!--end of root element-->
<age
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='file:/Users/jaideepsingh/NetBeansProje
cts/XML/src/xmldemo_dtd/SimpleXSD.xsd'>
</age>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType>
<xs:sequence>
<xs:element name="shipto">
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType>
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<shiporder
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='file:/Users/jaideepsingh/NetBeansProje
cts/XML/src/xmldemo_dtd/ComplexXSD.xsd'
orderid="1">
<orderperson>1</orderperson>
<shipto>
<name>Jaideep</name>
<address>Dehradun</address>
<city>Dehradun</city>
<country>India</country>
</shipto>
<item>
<title>Dracula</title>
<note>Vampire Book</note>
<quantity>1</quantity>
<price>450</price>
</item>
</shiporder>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="EmployeeInfoType">
<xs:sequence>
</xs:sequence>
</xs:complexType>
<xs:complexType name="EmployeeType">
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:schema>
<Employee_Info
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="GlobalXSD.xsd">
<Employee Employee_Number="101">
<Name>JAIDEEP SINGH</Name>
<Department>XML</Department>
<Telephone>+91-7830761616</Telephone>
<Email>jadesdang@gmail.com</Email>
</Employee>
</Employee_Info>
employee
background-color: pink;
firstname,lastname,email
font-size:25px;
display:block;
color: blue;
margin-left: 50px;
XML file:
<!DOCTYPE employee [
]>
<employee>
<firstname>Jaideep</firstname>
<lastname>Singh</lastname>
<email>jadesdang@gmail.com</email>
</employee>
XSLT FILE-
<?xml version = "1.0" encoding = "UTF-8"?>
<html>
<body>
<h2>Students</h2>
<xsl:for-each select="class/student">
<tr>
<td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
XML FILE
RegistrationForm.jsp
<%--
Document : RegistrationForm
Created on : Apr 21, 2017, 12:20:54 PM
Author : jaideepsingh
--%>
$(document).ready(function() {
$('#username').keyup(function() {
var uname = $('#username').val();
var datastr='user='+uname;
$.ajax({
type:"post",
url:"ajaxname",
data:datastr,
success:function(msg)
{
$("#useravail").hide();
$("#useravail").html(msg).fadeIn("slow");
}
});
});
});
</script>
<script type="text/javascript">
$(document).ready(function() {
$('#course').change(function() {
var coursename = $('#course').val();
var datastr='course='+coursename;
$.ajax({
type:"post",
url:"ajaxdomain",
data:datastr,
success:function(msg1)
{
//$("#response").hide();
$("#response").html(msg1);
}
<script type="text/javascript">
$(document).ready(function() {
$('#state').change(function() {
var statename = $('#state').val();
var datastr='state='+statename;
$.ajax({
type:"post",
url:"ajaxstate",
data:datastr,
success:function(msg2)
{
//$("#useravail").hide();
$("#responseState").html(msg2);
}
});
});
});
</script>
</head>
<body>
<form action="ajaxsave" name="StudentRegistration" method="post"
onsubmit="return(validate());">
<tr>
<td colspan=2>
<center><font size=4><b>Student Registration
Form</b></font></center>
</td>
</tr>
<tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="lastname" id="lastname"
size="30"></td>
</tr>
<tr>
<td>User Name</td>
<td><input type="text" name="username" id="username"
size="30"></td>
</tr>
<tr>
<td>Availability</td>
<td><p> <span id="useravail"></span></p> </td>
</tr>
<tr>
<td>Course</td>
<td><select name="course" class="Course" id="course">
<option value="-1" selected>select..</option>
<option value="btech">B.TECH</option>
<option value="mba">MBA</option>
</select></td>
</tr>
<tr>
<td>Domain</td>
<td id="response">
<!--Response will be inserted here-->
</td>
</tr>
<tr>
<td>State</td>
<tr>
<td>City</td>
<td id="responseState">
</td>
</tr>
<tr>
<td>Email Id</td>
<td><input type="text" name="emailid" id="emailid"
size="30"></td>
</tr>
<tr>
<td><input type="reset"></td>
<td colspan="2"><input type="submit" value="Submit Form"
/></td>
</tr>
</table>
</form>
</body>
</html>
Ajaxname:
import java.io.IOException;
import java.io.PrintWriter;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request,response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
String uname=null;
uname=request.getParameter("user");
Connection myConn = null;
PrintWriter out=response.getWriter();
ResultSet theResult=null;
String user = "root";
String pass = "jadedang";
// 2. Create a statement
PreparedStatement theStatement = myConn.prepareStatement("select *
from user where username=? ");
theResult = theStatement.executeQuery();
if(theResult.next()){
out.println("Not Available");
}
else{
out.println("Available");
myConn.close();
}
catch(Exception e){
out.println(e);}
}
}
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request,response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
String coursename=null;
coursename=request.getParameter("course");
Connection myConn = null;
PreparedStatement theStatement;
try {
// 2. Create a statement
theStatement = myConn.prepareStatement("select idbranch from
branch where namebranch=? ");
theResult = theStatement.executeQuery();
while(theResult.next()){
int id=theResult.getInt("idbranch");
theStatement=myConn.prepareStatement("select * from domain
where idbranch=?");
theStatement.setInt(1,id);
theResult = theStatement.executeQuery();
out.println("<select name='domain'>");
while(theResult.next()){
out.println("<option
value='"+theResult.getString("namedomain")
+"'>"+theResult.getString("namedomain")+"</option>");
}
out.println("</select>");
}
myConn.close();
}
}
Ajaxstate:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(request,response);
}
/**
try {
// 2. Create a statement
theStatement = myConn.prepareStatement("select idstate from state
where namestate=? ");
theResult = theStatement.executeQuery();
while(theResult.next()){
int id=theResult.getInt("idstate");
theStatement=myConn.prepareStatement("select * from city where
idstate=?");
theStatement.setInt(1,id);
theResult = theStatement.executeQuery();
}
catch(Exception e){
out.println(e);}
}
}
Ajaxsave:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
response)
*/
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter out=response.getWriter();
ResultSet theResult=null;
String user = "root";
String pass = "jadedang";
try {
pst.setString(1,name);
pst.setString(2,Lname);
pst.setString(3,Uname);
pst.setString(4,course);
pst.setString(5,domain);
pst.setString(6,state);
pst.setString(7,city);
pst.setString(8,Emailid);
int i = pst.executeUpdate();
}
else{
msg="failed to insert the data";
out.println("<font size='6' color=blue>" + msg + "</font>");
}
pst.close();
}
catch (Exception e){
out.println(e);
}