retrievin xml data

retrievin xml data

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

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> [email protected] </Emp_E-mail>
</Employee>

<Employee>
<Emp_Id> E-002 </Emp_Id>
<Emp_Name> B </Emp_Name>
<Emp_E-mail>[email protected] </Emp_E-mail>
</Employee>

<Employee>
<Emp_Id> E-003 </Emp_Id>
<Emp_Name> C </Emp_Name>
<Emp_E-mail> [email protected] </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 and then store it in seperate file!!   Hi Friend, Try the following... xml file: <?xml version = "1.0" ?> <EmployeeDetail> <
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,ADS_TO_REPLACE_1 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... ) in the browser using the XML. Thanks in advance.......ADS_TO_REPLACE_2   Hi
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
Hibernate Data Filter using XML
In this section, you will learn to filter data using XML mapping file
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
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 to read and parse the XML file in servlet? Please ask your question in detail.ADS
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
Retrieving XML Data Using GWT
Retrieving XML Data Using GWT       This Example Describes the way of retrieving XML file Data from...;private static final String XML_LABEL_STYLE = "
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
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
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
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... an XML file using Java Object then we will read that XML data as Java Object
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
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
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..._TO_REPLACE_1 This program helps you in retrieving the data from a XML file
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
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..., 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
Data Binding with XML Data Model in Flex4
Data Binding with XML DataModel in Flex4: The <fx:XML> tag contains a data in tree format. It is just like a <fx:Model> tag. The flex builder compiles the <fx:XML> tag into literal XML data. You can use this data
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
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
sorting and filtering the displayed table data using jsp and xml
sorting and filtering the displayed table data using jsp and xml  I have created a xml file and a jsp file, which uses DOM parser to display the content of xml file in web page. Now I would like to sort and filter those data
XML
XML  Design an XML to maintain book details to do the following: (i) Separate Data (ii) Exchange Data (iii) Store Data (iv) Create new language
xml
xml  Design an XML to maintain book details to do the following: (i) Separate Data (ii) Exchange Data (iii) Store Data (iv) Create new language
org.opendaylight.yangtools - yang-data-codec-xml version 2.0.13 Maven dependency. How to use yang-data-codec-xml version 2.0.13 in pom.xml?
org.opendaylight.yangtools  - Version 2.0.13 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version...; org.opendaylight.yangtools - yang-data-codec-xml project have released the latest
org.opendaylight.yangtools - yang-data-codec-xml version 11.0.0 Maven dependency. How to use yang-data-codec-xml version 11.0.0 in pom.xml?
org.opendaylight.yangtools  - Version 11.0.0 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version...; org.opendaylight.yangtools - yang-data-codec-xml project have released the latest
org.opendaylight.yangtools - yang-data-codec-xml version 11.0.0 Maven dependency. How to use yang-data-codec-xml version 11.0.0 in pom.xml?
org.opendaylight.yangtools  - Version 11.0.0 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version...; org.opendaylight.yangtools - yang-data-codec-xml project have released the latest
org.opendaylight.yangtools - yang-data-codec-xml version 11.0.0 Maven dependency. How to use yang-data-codec-xml version 11.0.0 in pom.xml?
org.opendaylight.yangtools  - Version 11.0.0 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version...; org.opendaylight.yangtools - yang-data-codec-xml project have released the latest
org.opendaylight.yangtools - yang-data-codec-xml version 5.0.6 Maven dependency. How to use yang-data-codec-xml version 5.0.6 in pom.xml?
org.opendaylight.yangtools  - Version 5.0.6 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version 5.0.6... to use org.opendaylight.yangtools  - Version 5.0.6 of yang-data-codec-xml
org.opendaylight.yangtools - yang-data-codec-xml version 2.0.6.5 Maven dependency. How to use yang-data-codec-xml version 2.0.6.5 in pom.xml?
org.opendaylight.yangtools  - Version 2.0.6.5 of yang-data-codec-xml... 2.0.6.5 of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version...; org.opendaylight.yangtools - yang-data-codec-xml project have released
org.opendaylight.yangtools - yang-data-codec-xml version 1.2.3 Maven dependency. How to use yang-data-codec-xml version 1.2.3 in pom.xml?
org.opendaylight.yangtools  - Version 1.2.3 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version 1.2.3... to use org.opendaylight.yangtools  - Version 1.2.3 of yang-data-codec-xml
org.opendaylight.yangtools - yang-data-codec-xml version 2.0.22 Maven dependency. How to use yang-data-codec-xml version 2.0.22 in pom.xml?
org.opendaylight.yangtools  - Version 2.0.22 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version...; org.opendaylight.yangtools - yang-data-codec-xml project have released the latest
org.opendaylight.yangtools - yang-data-codec-xml version 2.1.10 Maven dependency. How to use yang-data-codec-xml version 2.1.10 in pom.xml?
org.opendaylight.yangtools  - Version 2.1.10 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version...; org.opendaylight.yangtools - yang-data-codec-xml project have released the latest
org.opendaylight.yangtools - yang-data-codec-xml version 2.0.4 Maven dependency. How to use yang-data-codec-xml version 2.0.4 in pom.xml?
org.opendaylight.yangtools  - Version 2.0.4 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version 2.0.4... to use org.opendaylight.yangtools  - Version 2.0.4 of yang-data-codec-xml
org.opendaylight.yangtools - yang-data-codec-xml version 4.0.6 Maven dependency. How to use yang-data-codec-xml version 4.0.6 in pom.xml?
org.opendaylight.yangtools  - Version 4.0.6 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version 4.0.6... to use org.opendaylight.yangtools  - Version 4.0.6 of yang-data-codec-xml
org.opendaylight.yangtools - yang-data-codec-xml version 4.0.6 Maven dependency. How to use yang-data-codec-xml version 4.0.6 in pom.xml?
org.opendaylight.yangtools  - Version 4.0.6 of yang-data-codec-xml Maven... of yang-data-codec-xml in pom.xml? How to use yang-data-codec-xml version 4.0.6... to use org.opendaylight.yangtools  - Version 4.0.6 of yang-data-codec-xml
xml
, sub-elements and attributes needed in a xml document. It defines the data...xml  what is name space,xml scema give an example for each   XML Namespaces provide a method to avoid element name conflicts.They are used
xml
(APIs) have been developed for software developers to use to process XML data...xml  what is xml   Extensible Markup Language (XML... that is both human-readable and machine-readable. It is defined in the XML 1.0
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
XML - XML
language much like HTML used to describe data. In XML, tags are not predefined... Definition (DTD) , XML Schema to describe the data. Hence it is self-descriptive too...XML  What is specific definatio of XML? Tell us about marits

Ads