parser xml one page to another

parser xml one page to another

parser xml one page to another

View Answers

February 29, 2012 at 3:22 PM

1)file.xml:

<school>
<student>
<name>Angelina</name>
<address>Delhi</address>
</student>
<student>
<name>Martina</name>
<address>Mumbai</address>
</student>
</school>

2)Student.java:

class Student 
{
    String name;
    String address;

    Student(String name,String address){
        this.name=name;
        this.address=address;
    }
    public String getName(){
        return name;
    }
    public String getAddress(){
        return address;
    }
}

3)ParseXmlFile.java:

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

public class ParseXmlFile{

 public static void main(String argv[]) {
 ArrayList<Student> list=new ArrayList<Student>();
  try{
  File file = new File("c:\\file.xml");
  DocumentBuilderFactory dbf = 
  DocumentBuilderFactory.newInstance();
  DocumentBuilder db = dbf.newDocumentBuilder();
  Document document = db.parse(file);
  document.getDocumentElement().normalize();
  System.out.println("Root element "+ document.getDocumentElement().getNodeName());
  NodeList node = document.getElementsByTagName("student");
  System.out.println("Information of the students");

  for(int i = 0; i < node.getLength(); i++) {
  Node firstNode = node.item(i);

  if(firstNode.getNodeType() == Node.ELEMENT_NODE) {

  Element element = (Element) firstNode;
  NodeList firstNameElemntList = element.getElementsByTagName("name");
  Element firstNameElement = (Element) firstNameElemntList.item(0);
  NodeList firstName = firstNameElement.getChildNodes();
  Node n1=firstName.item(0);
  String name=n1.getNodeValue();

  NodeList lastNameElementList = element.getElementsByTagName("address");
  Element lastNameElement = (Element)lastNameElementList.item(0);
  NodeList lastName = lastNameElement.getChildNodes();
  Node n2=lastName.item(0);
  String address=n2.getNodeValue();
  list.add(new Student(name,address));
   }
  }
  for(Student st:list){
      System.out.println(st.getName()+"\t"+st.getAddress());
  }
  }
  catch (Exception e) {
  e.printStackTrace();
  }
 }
}









Related Tutorials/Questions & Answers:
parser xml one page to another
parser xml one page to another  parser xml one page to another
calling one jsp from another jsp page
calling one jsp from another jsp page  need coding for calling one jsp from another jsp including the xml file.Its urgent
Advertisements
to bring checked data from one page to another
to bring checked data from one page to another  thanks for your help... there is one jsp page , on it there is a link, on click of which it is opening second jsp page which is connected with servlet at the back and through which i am
calling one jap page from another jsp page
calling one jap page from another jsp page  i created a button in one jsp page i need to call another jsp page as an action to that button. so how can i call.. plz any one explain. its urgent
Xml Parser
Xml Parser  Hi... please tell me about What parser would you use for searching a huge XML file?ADS_TO_REPLACE_1 Thanks
parser - XML
parser  how to convert XML file to flat file(text file) using DOM and SAX parser
passing textbox value from one page to another page using html n javascript
passing textbox value from one page to another page using html n javascript  on button onclick event pass text box value and i want to pass value... on the othe (next/prevoious)page please help me   1)page1.html: <html>
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
program to enter values from one jsp page and then do calculation on some formula and that results is displayed in another jsp
program to enter values from one jsp page and then do calculation on some formula and that results is displayed in another jsp  <%@ page language="java" import="java.util.*;"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
JavaScript XML Parser
JavaScript XML Parser    ... to access and manipulate XML document using DOM parser in javascript. XML parser reads and loads the xml into computer memory and converts it into DOM object
sax parser for xml
sax parser for xml  sax parser code that works with any XML i.e independent of any XML to extract data from XML
add one row after another
add one row after another  how i add one row after another on click of add button $(document).ready(function() { var counter = 2; $("#addData").click(function() { if (counter > 10
converting one file format to another
converting one file format to another  Hi ser I need a code to export data from data grid to PDF and XL format plz help me out
Copy one file into another
Copy one file into another In this section, you will learn how to copy content of one file into another file. We will perform this operation by using...;This string is copied from one file to another\n"); bf.close(); InputStream
ModuleNotFoundError: No module named 'Another_One_Messenger_Client'
ModuleNotFoundError: No module named 'Another_One_Messenger_Client'  ...: No module named 'Another_One_Messenger_Client' How to remove the ModuleNotFoundError: No module named 'Another_One_Messenger_Client' error
ModuleNotFoundError: No module named 'Another_One_Messenger_Client'
ModuleNotFoundError: No module named 'Another_One_Messenger_Client'  ...: No module named 'Another_One_Messenger_Client' How to remove the ModuleNotFoundError: No module named 'Another_One_Messenger_Client' error
ModuleNotFoundError: No module named 'Another_One_Messenger_Server'
ModuleNotFoundError: No module named 'Another_One_Messenger_Server'  ...: No module named 'Another_One_Messenger_Server' How to remove the ModuleNotFoundError: No module named 'Another_One_Messenger_Server' error
how to use string of one class into another Class
how to use string of one class into another Class  I created textField(JTextField t1=new JTextField();(it is in ClassA. The input of this textField i.e t1.getText() is to be used in different(another Class say in ClassB. How can
Hibernate one to one mapping using xml
Hibernate one to one mapping using xml  Hi, How to create hibernate one to one mapping using xml? I have to create the mapping using the *.hbm.xml..., In case of one-to-one mapping for each reach in a table there is corresponding only
Hibernate One to One Mapping using XML
In this section, you will learn One to One mapping of table in Hibernate using Xml
Two Pagination in one page
Two Pagination in one page  hai friends any one help me. how do u make two pagination script in same page i'm used some ajax coding one pagination script is working but another pagination is not working please help me urgent
File copy from one directory to another in java
File copy from one directory to another in java  I am trying to find very good code example for copying a file from one directory to another...? Is there any size issue while copying the file from one directory to another
Convert One Unit to Another
Convert One Unit to Another       Again in this section, you will learn to convert One Unit to Another. The following program helps you in converting some more units to another
ModuleNotFoundError: No module named 'xml-parser'
ModuleNotFoundError: No module named 'xml-parser'  Hi, My Python... 'xml-parser' How to remove the ModuleNotFoundError: No module named 'xml... have to install padas library. You can install xml-parser python
ModuleNotFoundError: No module named 'xml-parser'
ModuleNotFoundError: No module named 'xml-parser'  Hi, My Python... 'xml-parser' How to remove the ModuleNotFoundError: No module named 'xml... have to install padas library. You can install xml-parser python
how to change password into one jsp to another jsp
how to change password into one jsp to another jsp  i have two jsps in one jsp i give one password and confirm password, in another jsp i want change...; </html> 2)changePassword.jsp <%@page import="java.sql.*"%> <
how to set the tables one is left and another one is right - JSP-Servlet
how to set the tables one is left and another one is right  Here two tables are combined.i need to set the one table is left another one is right and ineed to gap between the two tables Document document=new Document
update one table from another table
update one table from another table  hello, i need to update one table fields by using another table fields. I have to tables Products... enter the Quantity field in table 'Products_Purchased'In table 'Products' one item
Java - Copying one file to another
Java - Copying one file to another   ... how to copy contents from one file to another file. This topic is related.... Explanation This program copies one file to another file. We
passing data from one jframe to another
passing data from one jframe to another  I have two JFrame,built... in the first Jframe to another JLabel in the other JFrame.Can you please help me,how...){ String value=text.getText(); NextPage page=new NextPage(value
How to forward the control from one jsp to another?
How to forward the control from one jsp to another?  Hi! This is Prasad Jandrajupalli. I have the 3 JSP's, but I want communicate with each other.i.e. First JSP is communicating with the second JSP, Second JSP
copying data from one table to another
copying data from one table to another  i need to copy data from one table to another table.. i.e the 1st eid of employee table must be copied to the 1st eid in appusers table, 2nd eid of employee to the 2nd eid of appusers
force a page to go to another page using JavaScript
force a page to go to another page using JavaScript  How to force a page to go to another page using JavaScript
How to navigate from one jsf to another in eclipse
How to navigate from one jsf to another in eclipse  Hi there is my jsf code... <%@ page language="java" contentType="text/html; charset... using the above code for my welcome page which ask for user name and after
how to pass a string from one class to another
string from one class to another. import java.util.*; class A{ static String... string from one class to another. import java.io.*; class Class1 { public...how to pass a string from one class to another  hi all, Good morning
How to create one xml file from existing xml file's body?
How to create one xml file from existing xml file's body?  Hi, i'm working with content optimization system.I want to know how we can take all data from an xml doc's body to develope another xml with that content.I'm using JDOm
swings:how to link from one form to another form
swings:how to link from one form to another form  how to link from one form to another form
Java - Copying one file to another
Java - Copying one file to another   ... copies one file to another file. We will be declaring a function called copyfile which copies the contents from one specified file to another specified file
create a one web page
create a one web page  create a one web page with stored values in a database
Spliting Large XML and one by one Moved to Output Folder
Spliting Large XML and one by one Moved to Output Folder  How to Spliting Large XML and one by one Moved to Output Folder
java program to copy the contents of one folder to another folder
java program to copy the contents of one folder to another folder  java program to copy the contents of one folder to another folder   Have a look at the following link: Java Copy one folder to another
Java XML parser
Java XML parser  Hi friends, i am new to java XML parsing. i need to parse the following xml response which i got from a url hit: <response> <status>SUCCESS</status> <app-config> <CHECK_LOW_SCORE>
how to copy file from one directory to another in java with examples
how to copy file from one directory to another in java with examples  how to copy file from one directory to another in java with examples? I want... copy from one directory to another in java. Thanks
ModuleNotFoundError: No module named 'yandex-xml-parser'
ModuleNotFoundError: No module named 'yandex-xml-parser'  Hi, My... named 'yandex-xml-parser' How to remove the ModuleNotFoundError: No module named 'yandex-xml-parser' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'yandex-xml-parser'
ModuleNotFoundError: No module named 'yandex-xml-parser'  Hi, My... named 'yandex-xml-parser' How to remove the ModuleNotFoundError: No module named 'yandex-xml-parser' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'django-rss-xml-parser'
ModuleNotFoundError: No module named 'django-rss-xml-parser'  Hi...: No module named 'django-rss-xml-parser' How to remove the ModuleNotFoundError: No module named 'django-rss-xml-parser' error? Thanks   Hi
SAX Parser for huge XML file
SAX Parser for huge XML file  Hi.... if the XML file is small...("Enter XML file name:"); String xmlFile = bf.readLine(); File file = new File(xmlFile); if (file.exists()){ System.out.print("Enter XML tag name
Copy One Database Table to Another
Copy One Database Table to Another   ... to another database table. That means we copy one table to a different table... Copy data from one database table to another! 4 row(s)affected
problem in sending data from one ip to another ip in JAVA
problem in sending data from one ip to another ip in JAVA  Hi guys . this is naveen kumar...i need a help. i want to connect one ip to another ip (like ping),after that i want send the data with my system(Ip) to another ip
how to pass an array from one jsp to another jsp - JSP-Servlet
how to pass an array from one jsp to another jsp  hi friedns, can any One tell me how to send an array from one jsp to another jsp,pls any one send the code for this.also porvid the code how to retrive the arry in another jsp

Ads