You are on page 1of 20

Practical File Web Technology Branch: Computer Science Year: 4th College: Quantum School Of Technology Name: Rakesh

Bhatt Branch:Computer Science Roll NO: 37

Index S.NO Practical Name 1 Making Html page including following things-Unordered List, Table 2 Design a page using FrameSet 3 Design a page to implement a Registration form 4 Design a page to implement Java Script 5 To implement the CSS styleseet 6 To implement the bean. 7 To make a program to implement the Generic servlets 8 To desing a web page to implement HTTP servlet: 9 Write a program to implement the JSP programming 10 Design a dynamic page to enter the student data into database as well as show the data using JSP. 11 Reading data from the XML file using DTD (Data Type Definition) 12 Reading data from the XML file using XML-Schema

Remarks

Practicle 1: Making Html page including following things: 1. Unordered List 2. Table Html Coding:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <center> <h1>&nbsp; </h1><h1>&nbsp;</h1><h1>This is the First Html Page </h1> <table width="200" border="1"> <tr> <td><strong>Name</strong></td> <td><strong>Class</strong></td> <td><strong>Branch</strong></td> </tr> <tr> <td>abc</td><td>BTech</td> <td>CSE</td> </tr> <tr> <td>def</td><td>BTech</td> <td>CSE</td></tr></table> </center> <div align="center">This is the Example of Unorderd List:<br/> <ul> <li>Write Your Name</li> <li>Write Your Phone No</li> <li>Write Your Email Id</li> </ul> </div> <ceter> <div align="center"> This is the example of Ordered List: <ol> <li>name</li> <li>branch</li> <li>roll No</li> </ol></div><ul></ul></body></html> Design: This is Layout of web page:

Practical 2: Object: Design a page using FrameSet: FrameSet require four pages to be build: 1. Home 2. Header 3. Body 4. Image 5. NewSide

Coding of these pages with layouts is as follows: Header: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> body { background-color: #3FF; } body,td,th { font-size: 36px; color: #00F; } </style> </head> <body> <p>Hello Welcome you all in .Net learning web site</p> <p>&nbsp;</p> </body> </html> Design:

Body Page: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> body { background-color: #FC3; } body,td,th { font-family: "Times New Roman", Times, serif; font-size: 18px; } </style> </head> <body> <strong><br /> CHAPTER 19 BUILDING A BETTER WINDOW WITH SYSTEM.WINDOWS.FORMS</strong><br /> <p> Given that the total number of types within System.Windows.Forms is well over 10 0 strong, it would be redundant (not to mention a terrible waste of paper) to li

st every member of the Windows<br /> Forms family. To set the stage for the next several chapters, however, Table 191 lists some of the\core .NET 2.0 System.Windows.Forms types (consult the .NET F ramework 2.0 SDK documentation for<br /> full details).<br /> . Core Types of the System.Windows.Forms Namespace<br /> Classes Meaning in Life<br /> Application This class encapsulates the runtime operation of aWindows<br /> Forms application.<br /> Button, CheckBox, ComboBox, These classes (in addition to many others) correspon d to<br /> DateTimePicker, ListBox, various GUI widgets. You'll examine many of these items in<br /> LinkLabel, MaskedTextBox, detail in Chapter 21.<br /> MonthCalendar, PictureBox,<br /> TreeView<br /> FlowLayoutPanel, .NET </p></body></html> Design: Image page: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <img src="../Wallpaper/img2.jpg" /></body></html> Design:

New Side Page: Code: <table width="200" border="1"> <tr> <td><a href="body.html" target="body">ASP.Net</a></td> </tr><tr> <td><a href="body.html" target="body">Windows Frame</a></td> </tr><tr> <td>Ajax</td></tr><tr> <td>Silverlight</td></tr> </table> Design:

Home: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR /xhtml1/DTD/xhtml1-frameset.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head>

<frameset rows="89*,378*" cols="*"> <frameset rows="*" cols="167,923"> <frame src="image.html" /> <frame src="header2.html" /> </frameset> <frameset rows="*" cols="169,921"> <frame src="header.html" /> <frame src="body.html" name="body" /> </frameset> </frameset><noframes></noframes> </head> <body> </body> </html> Design:

Practical 3 Object: Design a page to implement a Registration form: HTML coding: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="css1.css" rel="stylesheet" type="text/css" /> </head> <body> <form action="" method="post" enctype="multipart/form-data" name="form1" id="for m1"> <br \ /> <h1 align="center"> This is the Form</h1><br \ /> <div align="center"> <table width="449" border="1" class="class1"> <tr> <td width="205">User Name</td> <td width="228"> <label for="txtuname"></label> <input type="text" name="txtuname" id="txtuname" /> </td> </tr> <tr> <td>Password</td> <td> <label for="txtpassword"></label>

<input type="password" name="txtpassword" id="txtpassword" /> </td> </tr> <tr> <td>Confirmt Password</td> <td><input type="password" align="center" /> </td> </tr> <tr> <td>Sex</td> <td>Male<input type="radio" value="male" /> Female<input type="radio" value="female" /> </td> </tr> <tr> <td>Country</td> <td><label for="country"></label> <select name="country" id="country"> <option value="india">India</option> <option value="australia">Australia</option> <option value="pak">Pakistan</option> <option value="srilanka">Sri Lanka</option> </select></td> </tr> <tr> <td>Father Name</td> <td><label for="txtfathername"></label> <input type="text" name="txtfathername" id="txtfathername" /></td> </tr> <tr> <td>Upload Image</td> <td><label for="filefield"></label> <input type="file" name="filefield" id="filefield" /></td> </tr> <tr> <td>Date Of Birth</td> <td><label for="txtdob"></label> <input type="text" name="txtdob" id="txtdob" /></td> </tr> <tr> <td>Phone No</td> <td><input type="text" name="txtphoneno" id="txtphoneno" /> <label for="txtphoneno"></label></td> </tr> <tr> <td><input type="submit" name="Submit" id="Submit" value="Submit" /></td > <td><input type="reset" name="Reset" id="Reset" value="Reset" /></td> </tr> </table> </div> </form> </body> </html> CSS coding: @charset "utf-8"; /* CSS Document */ .class1 {

background-color:#FC9; } WEB PAGE DESGIN:

Practical 4 Objective: Design a page to implement Java Script HTML Coding: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <script language="javascript" type="text/javascript"> var a=prompt("Enter the no to calculate the factorial"); var c=1; for(var b=a;b>0;b--) { c*=b } document.writeln("The factorial of the number "+a+" "+"is="+c); </script> <body> </body> </html> Web Design:

Practical 5 Object: To implement the CSS styleseet CSS Code: .introtext { font-family:Georgia, "Times New Roman", Times, serif; color:#FC9; background-color:#03F; } .Header { font-family: "Times New Roman", Times, serif; background-color: #636; font-size:14px; color:#FFF; } .Footer { background-color:#969; } .SidePage { font-family: Verdana, Geneva, sans-serif; font-size: 16px; text-decoration: underline overline; background-color:#969;

} HTML Coding: <head> <title>Untitled Document</title> <link href="practcss.css" rel="stylesheet" type="text/css" /> </head <body> <table width="1091" height="442" border="1"> <tr class="Header"> <td width="200"><div align="center">Home</div></td> <td width="497"><div align="center">About Us</div></td> <td width="195"><div align="center">Registration</div></td> <td width="171"><div align="center">Feedback</div></td></tr><tr> <td><table width="200" height="203" border="1" class="SidePage"> <tr> <td> C#</td></tr> <tr> <td>ASP.Net</td></tr> <tr> <td>Java</td></tr> <tr> <td>JavaScript</td></tr> </table></td> <td colspan="3" class="introtext">Grouping and Combining Selectors<br /> CSS also enables you to group multiple selectors by separating them with a comma. This is handy if you<br /> want to apply the same styles to different elements. The following rule tu rns all headings in the page to red:<br /> h1, h2, h3, h4, h5, h6<br /> {<br /> color: Red;<br /> }<br /> Moreover, with CSS you can also combine selectors, enabling you to hierarc hically point to a specific<br /> element in a page. You can do this by separating the selectors with a spac e. The following example<br /> targets all &lt;p&gt; elements that fall within an element with an id of M ainContent, leaving all other<br /> paragraphs unmodified.<br /> #MainContent p<br /> {<br /> font-size: 18px;<br /> }<br /> Note that combining is very different from grouping. Grouping is just a sh ortcut to avoid typing the<br /> same declarations over and over again, whereas combining enables you to ta rget specific elements in<br /> your document.<br /> With combining, you're not limited to ID and Type selectors; you can also us e it with the other</td></tr> <tr class="Footer"> <td>&nbsp;</td> <td colspan="3">Thanks to join Us </td></tr></table></body></html> Design:

Practical 6 Object-To implement the bean. Code:

Here are four classes are made. 1. Class 1: Here we are specifying the properties and also obtaining the property via get pr operty method package ClassRoomEx; import java.beans.*; public class ColorsBeanInfo extends SimpleBeanInfo { public PropertyDescriptor[] getPropertyDescriptors(){ try{ PropertyDescriptor rectangular=new PropertyDescriptor("rectangular", bea nex.class); PropertyDescriptor pd[]={rectangular}; return pd; }catch(Exception e){ System.out.println("exception caught."+e); } return null;}} Class 2It is the main class which deal with obtaining the properties of bean class and displaying properties to the screen package ClassRoomEx; import java.beans.*; import java.awt.*; public class IntrospectorDemo { public static void main(String args[]){ try{ Class c=Class.forName("ClassRoomEx.beanex"); BeanInfo beanInfo=Introspector.getBeanInfo(c); System.out.println("Properties:"); PropertyDescriptor propertyDescriptors[]=beanInfo.getPropertyDescriptors(); for(int i=0;i<propertyDescriptors.length;i++){ System.out.println("\t"+propertyDescriptors[i].getName()); } System.out.println("Events:"); EventSetDescriptor eventSetDescriptor[]=beanInfo.getEventSetDescriptors(); for(int i=0;i<eventSetDescriptor.length;i++){ System.out.println("\t"+eventSetDescriptor[i].getName()); } }catch(Exception e){ System.out.println("Exception caught."+e); } } } Class 3 Here is the main class which deal with the main implementation of bean here a Bo olean variable rectangular is specified and it has been declared a the property. package ClassRoomEx; import java.beans.*; import java.awt.*; import java.awt.event.*; import java.io.Serializable; public class beanex extends Canvas implements Serializable{ transient private Color color; private boolean rectangular; public beanex(){ addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me){ change(); }});

rectangular=false; setSize(200,100); change(); } public boolean getRectangular(){ return rectangular;} public void setRectangular(boolean flag){ this.rectangular=flag; repaint(); } public void change(){ color=randomColor(); repaint();} public Color randomColor(){ int r=(int) (255*Math.random()); int g=(int) (255*Math.random()); int b=(int) (255*Math.random()); return new Color(r,g,b); } public void paint(Graphics g){ Dimension d=getSize(); int h=d.height; int w=d.width; g.setColor(color); if(rectangular){ g.fillRect(0,0,w-1,h-1);} else{ g.fillOval(0, 0, w-1, h-1);}}} Output: run: Properties: accessibleContext background bufferStrategy enabled focusable font foreground name rectangular visible Events: mouseWheel mouse mouseMotion component hierarchyBounds focus hierarchy propertyChange inputMethod key

Practical 7 Objective: To make a program to implement the Generic servlets Html Coding <html><head><title>Untitled Document</title> </head> <body><center> <form name="form1" method="get" action="http://localhost:8080/servlets-examples/ servlet/gservlet"> <table width="33%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>User Name</td> <td> <label for="txtname"></label> <input type="text" name="txtname" id="txtname" /> </td></tr><tr> <td>Passsword</td> <td> <label for="txtpass"></label> <input type="text" name="txtpass" id="txtpass" /> </td> </tr> <tr> <td> <input type="reset" name="btnreset" id="btnreset" value="Reset" /> </td><td> <input type="submit" name="submit" id="submit" value="Submit" /> </td> </tr></table></form></center></body></html> Web Page Design: Servlet Coding: import javax.servlet.*; import java.io.*; public class gservlet extends GenericServlet { public void service(ServletRequest req,ServletResponse res){ try{ res.setContentType("text/html"); PrintWriter out=res.getWriter(); out.print("<html>"); out.println("<body>"); String str1=req.getParameter("txtname"); String str2=req.getParameter("txtpass"); out.print("<center>"); out.println("<table border=2>"); out.println("<tr><td>"); out.println(str1); out.println("</td>"); out.println("<td>"); out.println(str2); out.println("</td>"); out.println("</tr>"); out.println("</table>"); out.println("</center>"); out.println("</body>"); out.println("</html>"); }catch(Exception e){}}{}} Servlet Design:

Practical 8 Objective: To desing a web page to implement HTTP servlet: Html Coding: <html><head><title>Untitled Document</title> </head> <body><center> <form name="form1" method="get" action="http://localhost:8080/servlets-examples/ servlet/gservlet"> <table width="33%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>User Name</td> <td> <label for="txtname"></label> <input type="text" name="txtname" id="txtname" /> </td></tr><tr> <td>Passsword</td> <td> <label for="txtpass"></label> <input type="text" name="txtpass" id="txtpass" /> </td> </tr> <tr> <td> <input type="reset" name="btnreset" id="btnreset" value="Reset" /> </td><td> <input type="submit" name="submit" id="submit" value="Submit" /> </td> </tr></table></form></center></body></html> Web Page Desing: Servlet Coding: import javax.servlet.*; import java.io.*; import javax.servlet.http.*; public class gservlet extends HttpServlet { public void doGet(HttpServletRequest req,HttpServletResponse res){ try{ res.setContentType("text/html"); PrintWriter out=res.getWriter(); out.print("<html>"); out.println("<body>"); String str1=req.getParameter("txtname"); String str2=req.getParameter("txtpass"); out.print("<center>"); out.println("<table border=2>"); out.println("<tr><td>"); out.println(str1); out.println("</td>"); out.println("<td>"); out.println(str2); out.println("</td>"); out.println("</tr>");

out.println("</table>"); out.println("</center>"); out.println("</body>"); out.println("</html>"); }catch(Exception e){}{}} Servlet Desing:

Practical 9 Object: Write a program to implement the JSP programming: JSP Code: Page 1: <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql .*" errorPage="" %> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <center> <form name="form1" method="get" action="exjsp1.jsp"> <font size="+2"> Please Enter Your Web Site Address and click on open </font> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <table width="150" border="1"> <tr><td width="140"><input type="text" name="txtweburl" /></td></tr><tr><td> <input type="submit" name="btn" value="OPEN" /> </td></tr></table></form></center></body></html> Design: Page 2: JSP Coding: <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql .*" errorPage="" %> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <% String str=request.getParameter("txtweburl"); out.print("<a href=http://"+str+">"); %> <center>Click Here</center> <% out.print("<a>");%> </body></html> Design: After Clicking the text the next page opens is:

Practical 10 Object: Design a dynamic page to enter the student data into database as well as show the data. Home Page: HTML Code: <head><title>Untitled Document</title></head> <body><form id="form2" name="form2" method="post" action="http://localhost:8080/ jsp-examples/next.jsp"> <center><table width="429" border="1"> <tr> <td width="184">User Name</td> <td width="229"><input type="text" name="txtname" id="txtname" /></td> </t r> <tr> <td>Select Your Profession</td><td><select name="profession" id="organizat ion"> <option>Student</option><option>Employee</option></select></td> </tr> <tr><td>Enter Organization Name</td> <td><input type="text" name="organization" id="organization2" /></td> </tr> <tr> <td>Enter Email Id</td> <td><input type="text" name="emailid" id="emailid" /></td> </tr><tr> <td><input type="submit" name="submiyt" id="submiyt" value="Submit" onclic k="onValidte()"/></td><td><input type="reset" name="Reset" id="Reset" value="Res et" /></td> </tr></table></center></form> <script language="javascript" type="text/javascript"> function onValidte() { var ab=0; if((form2.txtname.value=="")||(form2.emailid.value=="")||(form2.organization.val ue)) {alert("Please Enter All the Required Field"+form2.txtname.value+form2.professio n.value+form2.emailid.value); ab=1;} if(ab!==1) {alert("your value have been entered");}} </script></body></html> Page Design: JSP page to insert the data in the Data into the database: JSP Coding: <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql .*" errorPage="" %> <head></head><body> <% String str= request.getParameter("txtname"); String str1=request.getParameter("profession"); String str2=request.getParameter("organization"); String str3=request.getParameter("emailid"); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Custom"); PreparedStatement stmt=con.prepareStatement("insert into custoer(Name,Work,Organ ization,Emailid) values(?,?,?,?)"); stmt.setString(1,str); stmt.setString(2,str1); stmt.setString(3,str2); stmt.setString(4,str3); stmt.executeUpdate(); con.close(); out.print("<center>"); out.println("<h2>Values updated</h2>"); out.print("</center>");

}catch(Exception e) { out.println("Exception "+e.getMessage()); } %> <center><form id="form1" name="form1" method="post" action="http://localhost:808 0/jsp-examples/value.jsp"> <input type="submit" name="submit" id="submit" value="Show All Values" /> </form></center></body></html> JSP Page Design: JSP JSP <%@ .*" <% page to show Data: coding: page contentType="text/html; charset=utf-8" language="java" import="java.sql errorPage="" %><body> try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Custom"); Statement s=con.createStatement(); ResultSet rs=s.executeQuery("select * from custoer"); out.print("<center><table border=1><tr><th>Id</th><th>Name</th><th>Prof ession</th><th>Organization</th><th>Email Id</th>"); while(rs.next()){ out.print("<tr><td>"); out.println(rs.getString(1)); out.print("</td><td>"); out.println(rs.getString(2)); out.print(" </td><td>"); out.println(rs.getString(3)); out.print("</td><td>"); out.println(rs.getString(4)); out.print("</td><td>"); out.println(rs.getString(5)); out.print("</td></tr>"); } out.print("</table></center>"); }catch(Exception e){ out.println("Excepition:"+e.getMessage());%> </body></html> JSP Page Design:

Practical 11 Object: Reading data from the XML file using DTD (Data Type Definition) DTD file coding: <?xml version="1.0"> <!ELEMENT customers(customer*)> <!--the general declaration element elementname(name of child elements of data t ypes-->

<!ELEMENT customer (name,title,company,(address,phone)+,email_id+,account_number )> <!ELEMENT name (first_name,middle_name?,last_name)> <!ELEMENT address(street,city,state,zip)> <!ELEMENT phone (business_phone|cell_phone|home,fax)> <!ELEMENT first_name (#PCDATA)> <!ELEMENT last_name (#PCDATA)> <!ELEMENT title (#PCDATA)> <!ELEMENT company (#PCDATA)> <!ELEMENT street (#PCDATA)> <!ELEMENT city (#PCDATA)> <!ELEMENT state (#PCDATA)> <!ELEMENT zip (#PCDATA)> <!ELEMENT business_phone (#PCDATA)> <!ELEMENT cell_phone (#PCDATA)> <!ELEMENT fax (#PCDATA)> <!ELEMENT home (#PCDATA)> <!ELEMENT email_id (#PCDATA)> <!ELEMENT account_number (#PCDATA)> <!ATTLIST customer cust_id (CDATA) #REQUIRED type (retail|wholesale) "retail"> XML file coding: <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE customers SYSTEM "C:\Documents and Settings\Wipro i Value\Desktop\Work \cus.dtd"> <customers> <cutomer id="393994"> <name> <first_name>Rakesh </first_name> <last_name>bhatt</last_name> </name> <title>Student</title> <company>Quantum Global Campus</company> <address> <street>kurma</street> <city>Pithoragarha</city> <state>Uttrakhand </state> <zip>262530 </zip> </address> <phone> <home>9410793962</home> <fax>lasjdfjalfd</fax> </phone> <email_id>bhattrakesh09@gmail.com</email_id> <account_number>8384388484585</account_number> </cutomer> <customer id="39939393"> <name> <first_name> sudhir</first_name> <middle_name>kumar</middle_name> <last_name>upreti</last_name> </name> <title>Student</title> <company>Quantum Global Campus</company> <address> <street>kurma</street> <city>Pithoragarha</city>

<state>Uttrakhand </state> <zip>262530 </zip> </address> <phone> <cell_phone>9410793962</cell_phone> <fax>lasjdfjalfd</fax> </phone> <email_id>bhattrakesh09@gmail.com</email_id> <account_number>838438848458</account_number> </customer> </customers> HTML PAGE coding: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> Hello dear how ar you <script language="javascript" type="text/javascript"> try{ var xmlfile=new ActiveXObject("Microsoft.XMLDOM"); xmlfile.load("C:\Documents and Settings\Wipro i Value\My Documents\custoer.xml "); nodes=xmlfile.documentElement.childNodes; document.write("here the script is working"); document.write(nodes.Item(0).getFirstChild().getNodeValue()); document.write(nodes.Item(1).getFirstChild().getNodeValue()); }catch(exception) { document.write("exception occur"+exception.description); } </script> </body> </html> Output: Practical 12 Object: Reading data from the XML file using XML-Schema XML-Schema file coding: <?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="customers"> <xs:complexType> <xs:sequence> <xs:element name="customer" minOccurs="0" maxOccurs="unbounded"> <xs:complexType> <xs:sequence> <xs:element name="name"> <xs:complexType> <xs:sequence> <xs:element name="first_name" type="xs:string"/> <xs:element name="middle_name" type="xs:string"/> <xs:element name="last_name" type="xs:string"/>

</xs:sequence> </xs:complexType> </xs:element> <xs:element name="title" type="xs:string"/> <xs:element name="company" type="xs:string"/> <xs:element name="address" minoccurs="1" maxoccurs="unbound"> <xs:complexType> <xs:sequence> <xs:element name="street" type="xs:string"/> <xs:element name="city" type="xs:string"/> <xs:element name="state" type="xs:string"/> <xs:element name="zip" type="xs:double"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="phone"> <xs:complexType> <xs:sequence> <xs:element name="business_phone"> <xs:simpleType> <xs:restriction base="xs:double"> <xs:maxLenght value="10"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="cell_phone"> <xs:simpleType> <xs:restriction base="xs:double"> <xs:maxLenght value="10"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="fax"> <xs:simpleType> <xs:restriction base="xs:double"> <xs:maxLenght value="10"/> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name="home"> <xs:simpleType> <xs:restriction base="xs:double"> <xs:maxLenght value="10"/> </xs:restriction> </xs:simpleType> </xs:element>

</xs:sequence>

</xs:complexType> </xs:element> <xs:element name="email_id" type="xs:string" minoccurs="1" maxoccurs="unbound"/> <xs:element name="account_number" type="xs:double"/> </xs:sequence> </xs:complexType> </xs:sequence> </xs:complexType> </xs:element> </xs:element> </xs:schema> XML file coding: <?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?> <customers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocat ion="customers.xsd"> <customers> <cutomer id="393994"> <name> <first_name>Rakesh </first_name> <last_name>bhatt</last_name> </name> <title>Student</title> <company>Quantum Global Campus</company> <address> <street>kurma</street> <city>Pithoragarha</city> <state>Uttrakhand </state> <zip>262530 </zip> </address> <phone> <home>9410793962</home> <fax>lasjdfjalfd</fax> </phone> <email_id>bhattrakesh09@gmail.com</email_id> <account_number>8384388484585</account_number> </cutomer> <customer id="39939393"> <name> <first_name> sudhir</first_name> <middle_name>kumar</middle_name> <last_name>upreti</last_name> </name> <title>Student</title> <company>Quantum Global Campus</company> <address> <street>kurma</street> <city>Pithoragarha</city> <state>Uttrakhand </state> <zip>262530 </zip> </address> <phone> <cell_phone>9410793962</cell_phone> <fax>lasjdfjalfd</fax> </phone> <email_id>bhattrakesh09@gmail.com</email_id>

<account_number>838438848458</account_number> </customer> </customers> HTML PAGE coding: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.or g/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> Hello dear how ar you <script language="javascript" type="text/javascript"> try{ var xmlfile=new ActiveXObject("Microsoft.XMLDOM"); xmlfile.load("C:\Documents and Settings\Wipro i Value\My Documents\custoer.xml "); nodes=xmlfile.documentElement.childNodes; document.write("here the script is working"); document.write(nodes.Item(0).getFirstChild().getNodeValue()); document.write(nodes.Item(1).getFirstChild().getNodeValue()); }catch(exception) { document.write("exception occur"+exception.description); } </script> </body> </html> Output:

You might also like