Menu


Notice: Undefined index: url3 in /home/u681245571/domains/studyglance.in/public_html/labprograms/wtdisplay.php on line 84

Notice: Undefined index: url4 in /home/u681245571/domains/studyglance.in/public_html/labprograms/wtdisplay.php on line 85

Notice: Undefined index: title in /home/u681245571/domains/studyglance.in/public_html/labprograms/wtdisplay.php on line 86

Notice: Undefined index: opurl2 in /home/u681245571/domains/studyglance.in/public_html/labprograms/wtdisplay.php on line 88

Notice: Undefined index: opurl3 in /home/u681245571/domains/studyglance.in/public_html/labprograms/wtdisplay.php on line 89

Notice: Undefined index: opurl4 in /home/u681245571/domains/studyglance.in/public_html/labprograms/wtdisplay.php on line 90

[R16] Web Technologies [ Lab Programs ]


Aim:

Source Code:

student.xml


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

<students-details>
<student>
<studentid>561</studentid>
<name>Ramu</name>
<address>ECIL</address>
<gender>Male</gender>
</student>
<student>
<studentid>562</studentid>
<name>Ramya</name>
<address>KBHP</address>
<gender>Female</gender>
</student>
<student>
<studentid>563</studentid>
<name>Mahi</name>
<address>BHEL</address>
<gender>Male</gender>
</student>
<student>
<studentid>564</studentid>
<name>Manvi</name>
<address>KOTI</address>
<gender>Female</gender>
</student>
<student>
<studentid>565</studentid>
<name>Ammu</name>
<address>ECIL</address>
<gender>Female</gender>
</student>
</students-details>

DOMParserDemo.java


import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.util.Scanner;
import java.io.*;

public class DOMParserDemo{public static void main(String[] args) throws Exception{
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
    DocumentBuilder builder = factory.newDocumentBuilder();     // parser is created 
    Document doc = builder.parse("student.xml"); // file is parsed
    NodeList list = doc.getElementsByTagName("student"); 
    Scanner in = new Scanner(System.in); 
    System.out.print("Enter student ID:\t");
    int n = in.nextInt(); 
    int flag = 0;
    for(int i = 0; i < list.getLength(); i++){
        Node node = list.item(i);
        if(node.getNodeType() == Node.ELEMENT_NODE){
            Element e = (Element) node;
            int x=Integer.parseInt(e.getElementsByTagName("studentid").item(0).getTextContent()); 
            if(x==n){
                System.out.println("\n\n STUDENT-DETAILS"); 
                System.out.println("==================="); 
                System.out.println("student id :\t" + e.getElementsByTagName("studentid").item(0).getTextContent()); 
                System.out.println("student Name :\t" + e.getElementsByTagName("name").item(0).getTextContent()); 
                System.out.println("Adress :\t" + e.getElementsByTagName("address").item(0).getTextContent()); 
                System.out.println("Gender :\t" + e.getElementsByTagName("gender").item(0).getTextContent()); 
                flag=1;
                break;
            }
            else{
                flag=0;
            }
        }
    }
    if(flag==0)
        System.out.println("student Id is not present.Try Again!!!");
    }
}

Output:

image

Related Content :

Web Technologies Lab Programs

1) Write an HTML page including JavaScript that takes a given set of integer numbers and shows them after sorting in descending order. View Solution

2) Write an HTML page including any required JavaScript that takes a number from one text field in the range of 0 to 999 and shows it in another text field in words. if the number is out of range, it should show “out of range” and if it is not a number, it should show “not a number” message in the result box. View Solution

3) Write an HTML page that has one input, which can take multi line text and a submit button. Once the user clicks the submit button, it should show the number of characters, words and lines in the text entered using an alert message. Words are separated with white space and lines are separated with new line character. View Solution

4) Write an HTML page that contains a selection box with a list of 5 countries. When the user selects a country, its capital should be printed next to the list. Add CSS to customize the properties of the font of the capital (color, bold and font size). View Solution

5) Create an XML document that contains 10 users information. Write a java program which takes users id as input and returns the users details by taking the user information from the XML document using DOM parser. View Solution

6) Create an XML document that contains 10 users information. Write a java program which takes users id as input and returns the users details by taking the user information from the XML document using SAX parser. View Solution

7) A user validation web application, where the user submits the login name and password to the server. The name and password are checked against the data already available in database and if the data matches, a successful login page is returned. Otherwise a failure message is shown to the user. View Solution

8) A user validation web application, where the user submits the login name and password to the server. The name and password are checked against the data already available in xml file (users.xml) and if the data matches, a successful login page is returned. Otherwise a failure message is shown to the user. View Solution

9) A user validation page web application, where the user submits the login name and password to the server. The name and password are checked against the data already available in database and if the data matches, a successful login Message is returned. Otherwise a failure message is shown to the user. Use AJAX to show the result on the same page below the button. View Solution

10) A simple calculator web application that takes two numbers and an operator (+,-,/,* and %)from an HTML page and returns the result page with the operation performed on the operands. View Solution

11) Modify the above program (Simple Calculator) such that it stores each query in a database and checks the database first for the result. If the query is already available in the DB, it returns the value that was previously computed (from DB) or it computes the result and returns it after storing the new query and result in DB. View Solution

12) A web application takes a name as input and on submit it shows a hellopage where is taken from the request. It shows the start time at the right top corner of the page and provides the logout button. On clicking this button, it should show a logout page with Thank You message with the duration of usage. (Use session to store name and time). View Solution

13) A web application that takes name and age from an HTML page. If the age is less than 18, it should send a page with “hello<name> you are not authorized to visit this site” message, where <name> should be replaced with the entered name. Otherwise it should send “Welcome <name> to this site “message. View Solution

14) A web application for implementation: The user is first served a login page which takes user’s name and password. After submitting the details the server checks these values against the data from a database and takes the following decisions.   • If name and password matches serves a welcome page with user’s full name. • If name and password doesn’t match, then serves “password mismatch” page. • If name is not found in the database, serves a registration page, where user’s full name is asked and on submitting the full name, it stores, the login name, password and full name in the database (hint: use session for storing data, submitted login name and password). View Solution

15) A web application that lists all cookies stored in the browser on clicking “list Cookies ”button .Addcookies if necessary View Solution




Suggestion/Feedback Form :




Excellent  Very Good  Good  Average  Poor


This is a Compliment
This is a Suggestion for improvement
This is Feedback
This is Grievance