Home Answers Viewqa XML parser xml one page to another

 
 


Java Coder
parser xml one page to another
1 Answer(s)      a year and 2 months ago
Posted in : XML

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 Pages:
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
JavaScript XML Parser
JavaScript XML Parser    ... to access and manipulate XML document using DOM parser in javascript. XML parser.... The method xmlDoc.load("data.xml") allows the parser to load an XML
parser - XML
parser  how to convert XML file to flat file(text file) using DOM and SAX parser
Xml Parser
Xml Parser  Hi... please tell me about What parser would you use for searching a huge XML file? Thanks
Truncating issue while parsing XML with SAX Parser.
Truncating issue while parsing XML with SAX Parser.  I am Parsing one xml file and after parsing I have to enter the data into the database using... could understand was while calling the event handler of the SAX Parser i.e.
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
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
How to parse the attributes values from XML using KXML parser in j2me
How to parse the attributes values from XML using KXML parser in j2me  hai team, i did xml parsing from serverside...i got a resultant value from xml,but here tag value name only came from parsing attribute name cant come
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>
XML Interviews Question page11,xml Interviews Guide,xml Interviews
;    How do I include one XML file in another... not have an XML or DOCTYPE Declaration on it. If you've been using one for editing...: they contain a parser which reads XML and identifies the function of each
Parsing The XML File Using JDOM Parser in JSP
Parsing The XML File Using JDOM Parser in JSP... with JDOM parser to parse the xml document. JDOM can read existing XML documents... native parser. XML parsing produces an xml parse tree from an XML document. Using
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
Java Interview Questions - Page 2
and applications that process that XML. The parser is responsible... Java Interview Questions - Page 2       Question: Parsers? DOM vs SAX parser
XML Interviews Question page24,xml Interviews Guide,xml Interviews
validating a document that uses XML namespaces and validating one that doesn't... is built on top of a namespace-unaware parser. Another common situation is when... XML Interviews Question page24   
XML Tutorial
, and the parser invokes them as it reads the XML data.) Finally, you can't "back up... XML Tutorial XML Tutorial: XML stands for EXtensible Markup Language. In our XML tutorial you will learn what XML is and the difference between
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
Reading xml file using dom parser in java with out using getelementby tag name
Reading xml file using dom parser in java with out using getelementby tag name  Hi, How to read the xml file using java with dom parser, but without...-Beginners/8384-java-with-xml-parsing.html but it is not reading attribute
Parsing The XML File using DOM parser in JSP
Parsing The XML File using DOM parser in JSP... the processing are displayed on to the present page. DOM parser is not an ideal... the xml page in jsp. 'parsingxml.jsp' uses 'roseindia.xml' file and display its
SAX Parser
; The Simple API for XML (SAX) is a serial access parser API for XML. It is used... executes, the SAX parser recognizes and responds to each XML structure taking... the parser encounters a new XML tag or encounters an error, or wants to tell
XML Parsing Using Sax Parser in J2ME for serverside
XML Parsing Using Sax Parser in J2ME for serverside  Hai team, i have doubt in Parsing using sax parser in serverside plz help me for xml parsing in j2me using sax parser on server side thanks in advance... regards Selva
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.*"%> <
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 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
XML Parsers
; XML parser is used to read, update, create and manipulate an XML document. Parsing XML Documents To manipulate an XML document, XML parser is needed. The parser... and manipulate XML documents using any programming language (and a 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>
XML Parsing Using Sax Parser in J2ME
XML Parsing Using Sax Parser in J2ME  Hai team, I hope you, You should help me, I have trouble in Xml parsing... I have decoded value, what... that value append to send web service and got reult...here i got xml feed now i want
Read Complex XML using DOM/SAX Parser.
Read Complex XML using DOM/SAX Parser.  I have a XML file which is having two types of Items. I want to extract all details of a type only. My XML goes something like this <Movie> <Bollywood> <Actor> Shah Rukh
how to create a xml page
how to create a xml page  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML...;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <...;One Roof For All...</h2> <div id="header-links">
JPA One-to-One Relationship
will learn  about the one-to-one relationship. In the one-to-one relation mapping a single value association to another entity.  One-to-One: In one-to-one... JPA One-to-One Relationship   
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
The Simple API for XML (SAX) APIs
applications to configure and obtain a SAX based parser to parse XML... to the parser. This parser processes the XML file and invokes the appropriate method... when the parser encounters the text in an XML element or an inline
Parsing repeatitive xml elements using SAX Parser - XML
Parsing repeatitive xml elements using SAX Parser  Hi, I'm using SAX Parser to read an XML file. My XML file contains repeatitive tags. I'm able to retrieve all the values from the xml file. However, for repeatitive tags
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
XML Interviews Question page19
document to another document. An early draft of the XML namespaces recommendation... names to be prefixed is so that attributes defined in one XML language can be used in another XML language.    
How to store data entered in JSP page by a user in XML file & later retrieval of data using id at other page
How to store data entered in JSP page by a user in XML file & later retrieval... in another jsp page using retrieve submit button.Please tell step by step instructions... one or two textboxes to enter data and store in xml. thanking you a lot
calling one jsp from another jsp - JSP-Servlet
calling one jsp from another jsp  Hi All, In my web application I have two jsp files(one.jsp and two.jsp). I have written a seperate method... pageContext.include("./nextjsppage.jsp"); when you use this statement the jsp page
Hibernate one-to-one relationships
Hibernate one-to-one relationships  How does one to one relationship work in Hibernate?   Hibernate Mapping One-to-One Hibernate provides.... here is an example showing one to one relationship using hbm.xml. We have two
parsing word xml file using SAX parser - XML
parsing word xml file using SAX parser  i am parsing word 2003's XML file using SAX.here my question is,i want to write some tag elements which... this xml file and write that xml part into file? can somebody
How to parse the attributes from XML using KXML parser in j2me
How to parse the attributes from XML using KXML parser in j2me  Dear Sir, I have doubt in How to parse the attributes from XML using KXML parser in j2me ..I parse the dge name value..but i didn't do parsing the attributes
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
XML Interviews Question page17,xml Interviews Guide,xml Interviews
the prefix used in an XML namespace declaration, you simply declare another XML... XML Interviews Question page17       Where can I declare an XML namespace? You can
XML
XML  create flat file with 20 records. Read the records using xml parser and show required details
XML Interviews Question page16,xml Interviews Guide,xml Interviews
. One area of confusion is the relationship between XML namespaces and validating... XML Interviews Question page16       Do I need to use XML namespaces? Maybe, maybe
XML Interviews Question page25,xml Interviews Guide,xml Interviews
XML Interviews Question page25       How do I use XML namespaces with Internet Explorer 5.0 and/or the MSXML parser? WARNING! The following applies only to earlier
XML Interviews Question page26,xml Interviews Guide,xml Interviews
this as an error, or it can treat the document as one that does not use XML... this. The reason is that most applications understand a particular XML language, such as one... XML Interviews Question page26   
XML Interviews Question page1,xml Interviews Guide,xml Interviews
). HTML is just one of many SGML or XML applications—the one most frequently... for choosing XML by citing a few real world examples. For instance, one appropriate answer... XML Interviews Question page2   
XML Interviews Question page14,xml Interviews Guide,xml Interviews
is a markup language [two (seemingly) contradictory statements one after another.... With XML (or SGML), they maintain one set of carefully validated information..., this is not a useful long term solution. One of the hopes of XML is that people
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
JAXP API using DOM Parser
;   Introduction to XML Parser: In computing... into easily manageable parts. XML parser is used to read, update, create and manipulate an XML document. Whenever the XML document executes, the parser

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.