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



Home Answers Viewqa Java-Beginners xml file reading using java
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mazeed
xml file reading using java
1 Answer(s)      3 years and 4 months ago
Posted in : Java Beginners


hi deepak

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


Advertisement
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
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
parsing xml file using java code
parsing xml file using java code  parsing a xml file using java code
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
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
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
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
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
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
Reading text from image file - Java Beginners
Reading text from image file  How Read text from image file
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: http://www.roseindia.net/xml/Listingnode.shtml http://www.roseindia.net/xml/getting
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 to read a file into byte array for certain type of business processing. This Java
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
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
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 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
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
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
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
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: http://www.roseindia.net/struts/struts2/struts2validation.shtml Thanks
Advertisements
 

 

 

DMCA.com