xml file reading using java

xml file reading using java

hi deepak

I want to read some data from xml file and send that output to particular email address using java

View Answers

July 27, 2011 at 10:25 AM

import org.w3c.dom.*;
import org.w3c.dom.Node;
import javax.xml.parsers.*;
public class ParseXML{
    public static boolean isTextNode(Node n){
    return n.getNodeName().equals("#text");
  }
    public static void main(String[]args)throws Exception{
  DocumentBuilderFactory docFactory =  DocumentBuilderFactory.newInstance();
  DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
  Document doc = docBuilder.parse("roseindia.xml");

          Element  element = doc.getDocumentElement(); 
          NodeList personNodes = element.getChildNodes();     
          for(int i=0; i<personNodes.getLength(); i++){
            Node emp = personNodes.item(i);
            if(isTextNode(emp))
            continue;
            NodeList NameDOBCity = emp.getChildNodes(); 

            for(int j=0; j<NameDOBCity.getLength(); j++ ){
            Node node = NameDOBCity.item(j);
            if(isTextNode(node)) 
              continue;
            System.out.print(node.getFirstChild().getNodeValue()+"\t ");
          } 
          System.out.println();
        }
    }
}









Related Tutorials/Questions & Answers:
xml file reading using java
xml file reading using java  hi deepak I want to read some data from xml file and send that output to particular email address using java   import org.w3c.dom.*; import org.w3c.dom.Node; import javax.xml.parsers.
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
Advertisements
Reading RDF file using Java code in Eclipse
Reading RDF file using Java code in Eclipse  Could you please tel me what this statement means - Model model = ModelFactory.createDefaultModel
Reading a xml file - JSP-Servlet
Reading a xml file  how to read a xml file using jsp and then i have to retrive a data from that file use it in code?  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/parsing-xml.shtml
Reading a xml file - JSP-Servlet
Reading a xml file  Thanks for ur answer sir but problem is that i have to do a reading a xml file of a employee record and then i have to use a employee details to send mail to those employees how to do i sir please help me
Reading .doc file using swing
Reading .doc file using swing  Sir, Could U Please Tell me the Way To Read .doc file in java using swing,with code
How to Split a large XML file using java?
How to Split a large XML file using java?  How can we split a 500MB Xml file?I know how to split xml file after reading the entire document in a file.Here we cannot load the entire file as it is a large file
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
Reading a text file in java
in java.io.* package for reading and writing to a file in Java. To learn more about reading text file in Java see the tutorial Read File in Java. Thanks...Reading a text file in java  What is the code for Reading a text file
Err while reading CSV file using POI - Java Beginners
Err while reading CSV file using POI  Hi, When i am trying to read a CSV file using POI Dile system, the below error is coming up... know, why this is coming up. Is there any other way to read the CSV file. Thanks
how to read and write an xml file using java
how to read and write an xml file using java  Hi Can anyone help me how to read and write an xml file which has CData using java
Reading big file in Java
Reading big file in Java  How to read a big text file in Java program?   Hi, Read the complete tutorial at How to read big file line by line in java? Thanks
read XML file and display it using java servlets
read XML file and display it using java servlets  sir, i can't access Xml which is present in my d drive plz can u should go through my code n tell me the things where i went wrong java servlet program protected void
Best way to reading file in java
Best way to reading file in java  Hi, As a beginner I want to learn about Java programming and make a program for reading a text file in java. What is the best way for reading file in Java? Thanks
Video Tutorial of reading file in Java
get the source code of reading a text file in Java. This source code can... file line by line in Java using Eclipse Project: In this video... Java example for Reading file into byte array Learn how
download xml file from website using java code
download xml file from website using java code  how to download xml file from website using java code
Reading a file from Jar JAVA
Reading a file from Jar JAVA  I have added one excel sheet into a jar file. can anybody tell me how i can read that file. actually when i am running code from eclipse i able to read it but when i am adding that jar file
Reading a file from Jar JAVA
Reading a file from Jar JAVA  I have added one excel sheet into a jar file. can anybody tell me how i can read that file. actually when i am running code from eclipse i able to read it but when i am adding that jar file
validation in struts2 using .xml file
validation in struts2 using .xml file  how to do xml validation in struts2 on dynamic fields   Hello Friend, Please visit the following link:ADS_TO_REPLACE_1 http://www.roseindia.net/struts/struts2/struts2validation
Reading XML from a File
Reading XML from a File       This Example shows you how to Load Properties from the XML file via a DOM document. JAXP (Java API for XML Processing) is an interface which provides
reading and displaying svg file through java
reading and displaying svg file through java  sample program for reading a svg file
Line by Line reading from a file using Scanner Class
In this section, you will get to know about reading line by line a text file using java.util.Scanner class
Reading an XML document using JDOM
Reading an XML document using JDOM   ..., it is a tree based Java api. JDOM represents an XML document as a tree composed... are some of the methods used in code given below for reading an XML document
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file
reading data using struts and jsp java
reading data using struts and jsp java  how can i read data entered by user into a textbox (jsp page) into struts action class ex emp id,so that after reading emp_id it can be read into struts action class for retrieving other
How to generate xml file using xpath
How to generate xml file using xpath  Hi, I have a requirement... to make a xml using that,. It would be great is you can help me out with how to make a xml using xpath. Thanks in Advance, SanjayADS_TO_REPLACE_1   Hi
Read XML using Java
of all i need to read xml using java . i did good research in google and came to know.../xmlParsing/java-xml-parsing-using-sax.shtml http://www.roseindia.net/xml/sax... two codes i think reading xml using JDOM is simple. But my XML size ranges from
accessing xml using java
accessing xml using java  I need to retrieve some elements in xml file using java   Hi Friend, Please visit the following links:ADS_TO_REPLACE_1 http://www.roseindia.net/xml/Listingnode.shtml http://www.roseindia.net
Reading multiple xml files
Reading multiple xml files  How can we read many xml files from a folder? The same procedure as that of "listfiles
Java example for Reading file into byte array
Java example for Reading file into byte array. You can then process the byte... in Java for reading file into byte array. Sometimes it becomes necessary... of reading file into byte array: Java file to byte array
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
Writing to and reading from a binary file in java.
Writing to and reading from a binary file in java.  I have written the following code to convert an ASCII text file to a binary file: public static... work, but the records obtained after reading the binary file are much less than
initialise array by reading from file - Java Beginners
initialise array by reading from file  Hello, I wnat to know how i would initialise an array by reading a text file, which contains a simple pattern. for example the file may look as shown below, with the star character
XML parsing using Java - XML
XML parsing using Java  I'm trying to parse a big XML file in JAVA..." in element "MIRate"(THE XML code is below).once he enters coverage rate I need... for it skipping all the elements in Table 1. I'm usin using saxparser, startelement
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
xml file creation in java
xml file creation in java  how to create xml file in java so...; Please visit the following links: http://www.roseindia.net/tutorial/java/xml...;Please visit the following links: http://www.roseindia.net/tutorial/java/xml
Create XML File using Servlet
Create XML File using Servlet   ... file using Servlet  We have created  file XmlServlet.java. It creates XML file with its version and encoding and display a message 'Xml File Created
svg file reading and display
svg file reading and display  i want a sample program for reading and displaying the content of a svg file
Java error reading from file
Java error reading from file       Java error reading file are the common error occurred  in java that when the user encounter a corrupt file
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
Reading binary file into byte array in Java
Example code of reading binary file into byte array in Java This example shows you how to read a binary file into byte array from Java program. This type... is the complete code of the Java program that reads the binary file into byte array:ADS
Reading file into bytearrayoutputstream
to read file using byteinputstream and then write to another file using... input stream and byte output stream. This is and good example of reading file... In this example we have used the class InputStream for reading the file
Thread for reading txt file
Thread for reading txt file  how to use 3 thread to read 3 txt file? To create three threads for reading the file and three threads for getting the strings out of the queue and printing them. thanks
How to get xml file form http port using web service
How to get xml file form http port using web service  hi I am suresh i am using netbeans 6.9 to develop a web service for getting xml from http port and use the xml data to convert it to java file and store it to DB. But i am
Convert text file to XML file in Java
Convert text file to XML file Java In this section, you will learn how to convert the text file into xml file in Java language. To do this, we have used StreamResult which acts as an holder for a transformation result in XML. After
External file reading in jsp
External file reading in jsp  i have written a jsp page(ReadExt.jsp) in my application which reads a text file content from a system... with using local host address.. plz help me in solving this problem.. here i have
Reading a big file effeciently
Reading a big file effeciently  How to read a large text file quickly without memory error in Java? What is the best method to read a big file very efficiently? Thanks   Hi, Kindly check the program Java Read File
read xml using java
read xml using java  <p>to read multiple attributes and elements from xml in an order.... ex :component name="csl"\layerinterfacefile="poo.c"\interface type=""\level="0"\source_file="ppp" etc as wise each attribute n
Problem reading word file
Problem reading word file  Deepak you provide me code for extarcting equation from a word file and also to write in a word file.But when I again want to read preveously created word file(created by your code) it gives an error
Reading an excel file into array
Reading an excel file into array  Hi, I'm trying to read in an excel file, search a column for containing key words (entered by a user) and then displaying the matching rows in a table. I'm fairly new to JavaScript. Can anyone

Ads