Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Development-process retrievin xml data
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ranjani
retrievin xml data
1 Answer(s)      4 years ago
Posted in : Development process


If i need to retrieve some node elements from xml and then store it in seperate file!!


Advertisement
View Answers

December 13, 2010 at 5:38 PM


Hi Friend,

Try the following code:

import java.io.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.transform.*; 
import javax.xml.transform.dom.DOMSource; 
import javax.xml.transform.stream.StreamResult;

public class GetData{
  static public void main(String[] arg) {
    try{
      String xmlFile ="C:/employee.xml";
      File file = new File(xmlFile);
      if (file.exists()){
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(xmlFile);
        Transformer tFormer = TransformerFactory.newInstance().newTransformer();
        tFormer.setOutputProperty(OutputKeys.METHOD, "text");
        Source source = new DOMSource(doc);
        Result result = new StreamResult(new File("C:/employee.txt"));
        tFormer.transform(source, result);
      }
      else{
        System.out.println("File not found!");
      }
    }
    catch (Exception e){
      System.err.println(e);
      System.exit(0);
    }  
  }
}

For the above code, we have used following xml file:

<?xml version = "1.0" ?>
<EmployeeDetail>

<Employee>
<Emp_Id> E-001 </Emp_Id>
<Emp_Name> A </Emp_Name>
<Emp_E-mail> aa@roseindia.net </Emp_E-mail>
</Employee>

<Employee>
<Emp_Id> E-002 </Emp_Id>
<Emp_Name> B </Emp_Name>
<Emp_E-mail>bb@roseindia.net </Emp_E-mail>
</Employee>

<Employee>
<Emp_Id> E-003 </Emp_Id>
<Emp_Name> C </Emp_Name>
<Emp_E-mail> cc@roseindia.net </Emp_E-mail>
</Employee>

</EmployeeDetail>


Related Tutorials/Questions & Answers:
retrievin xml data
retrievin xml data  If i need to retrieve some node elements from xml...(0); } } } For the above code, we have used following xml file: <?xml version = "1.0" ?> <EmployeeDetail> <Employee> <Emp_Id>
storing data in xml - XML
storing data in xml  Can u plz help me how to store data in xml using java  Hi Friend, Try the following code: import java.io....,name,address,contactNo,email); System.out.println("Xml File Created
Advertisements
XML data binding
XML data binding   hello, What is XML data binding?   hii, XML data binding refers to the process of representing the information in an XML document as an object in computer memory
database data in xml format
database data in xml format  HI, i want to display the database data in the xml format(not as xml file ) on the console using DOM. help will be appreciated. THANKS K.K
Data read. - XML
Data read.  How to store or read data in XML from Struts.Plz give me example. Thanx
saving data in xml
saving data in xml  Hi, I have an xml file with spring map, in that i have parent child nodes. I have jsp form in that i have put same parent child elements. when i submit jsp form I want to append same data into xml file
xml displaying a drives data.....
xml displaying a drives data.....  Hi all, I need a solution for displaying content of a drive(Ex: c , d , e ) in the browser using the XML... the XML. Thanks in advance.......   Hi, You can't access the your drive
data retrivel code - XML
data retrivel code  Can someone help me in retriving data from MySql database into an XML file using java.  Hi Shruti, Please visit.../servlets/login-Xml-servlet.shtml I hope this will help you a lot. Thanks
data retrival and presentation - XML
data retrival and presentation  I want to present the data which is retrieved from xml file. Which contains 1000 records.so i want to present them...://www.roseindia.net/jsp/data-grid.shtml http://www.roseindia.net/jsp/parsing-xml.shtml
Java Xml Data Store
Java Xml Data Store  I have to do this project and i'm finding it so... be followed up and/or purchased. You will need to store the data in a local binary or XML file. As a good Java programmer you will use correct Object-Oriented
how to write java data - XML
how to write java data  how to write data to xml file  Hi friend, Read for more information, http://www.roseindia.net/xml/dom/ Thanks
project in JSP and XML(to store data)
project in JSP and XML(to store data)  I need to complete an assignment in JSP and using XML as Database ,Please help me to complete this assignment.Ill be very very thankful to you,i am new to JSP.Please provide full code
Retrieving XML Data Using GWT
Retrieving XML Data Using GWT       This Example Describes the way of retrieving XML file Data from...;static final String XML_LABEL_STYLE = "xmlLabel"
Hibernate Data Filter using XML
In this section, you will learn to filter data using XML mapping file
data insertion from xml file to database table
data insertion from xml file to database table  Hi all, I have data in the XML file. I need to insert it into table in the database using servlet. so please reply me . ThankYou
Retrieve data from xml using servlets
Retrieve data from xml using servlets  Hi plz send me the code for retrieving the data from xml File using Servlets.   Hi, Do you want... Thanks   Hi, Learn Get Data From the XML File. Thanks
JSP and XML .data store nd retrieve
JSP and XML .data store nd retrieve  I have made a form in jsp having emp id, projectname and emp name.I want to store data related to employee in xml file.How can i store data entered by user in XML file and later retrieve data
how to store data in XML file - JSP-Servlet
how to store data in XML file  hi i have to store the data for example user id and password in a xml file the input userid and password..., To solve the problem visit to : http://www.roseindia.net/servlets/login-Xml
how to search data in xml files using php
how to search data in xml files using php  So I want to create a website that allows me (or others) to type in a words and select a relevent search, and have it search multiple XML pages on server The XML documents are setup
Produces XML file but format not correct for storing data using JSP and XML
Produces XML file but format not correct for storing data using JSP and XML  hii I have created a project using JSP and XML as database to store data entered by user in XML file ,It stores data entered in XML file
Get Data From the XML File
Get Data From the XML File       Here you will learn to retrieve data from XML file using SAX parser. We use the JAXP APIs to retrieve data from XML document . Description
Delete and edit data in xml file using JSP
Delete and edit data in xml file using JSP   I want to know how to delete and edit data from an XML file by use of JSP. I have XML file having tasks... in the xml file,I want to delete and edit some tasks using task id then how can i do
Insert XML file data to database
Insert XML file data to database In this tutorial, you will learn how to insert the xml file data to database using dom parser. You all are aware of XML... to read the xml file data and save the values of an XML file to a Database
JAXB Create XML File And Get Data From XML
JAXB Create XML File And Get Data From XML In this section we will read about how to create XML file and how to convert XML file's data to Java Object... using Java Object then we will read that XML data as Java Object again
Getting Data from XML File (Document)
Getting Data from XML File (Document)   ... from a XML file. All xml files store the data. You can add and modify the data...: This program helps you in retrieving the data from a XML file. It takes a xml file
Data Binding with XML Data Model in Flex4
Data Binding with XML DataModel in Flex4: The <fx:XML> tag contains... compiles the <fx:XML> tag into literal XML data. You can use this data...; <s:Panel title="Data Binding with XML DataModel"
Reading XML Data from a Stream
Reading XML Data from a Stream       This Example shows you how to Read XML Data via a Stream in a DOM document. JAXP (Java API for XML Processing) is an interface which provides
java program to create xml file with append data in well-formed
java program to create xml file with append data in well-formed   Sorry sir your given xml append data program is not well-formed. I'll make you more clear what I want. If this is my xml file Tom Cruise 45 Now when I append
Sava data from Form to XML file using strutrs
Sava data from Form to XML file using strutrs  I'am a biginner with struts want so save data from my form in an Xml file using struts but i'm searching witout finding a solution thanks fo your help
Retrieving XML Data Using GWT
Retrieving XML Data Using GWT       This Example Describes the way of retrieving XML file Data from the server using GWT. The basic building block for running
Display data from xml file to Swings - Swing AWT
Display data from xml file to Swings  Hi, We are Preparing a stand alone application. Where the Swings is the front end. There will be only... clicking the buttons in swings it has to display 20 record in one shot in table
Advertisements
 

 

 

DMCA.com