MCQs Test!! VB Basic Test !! Essentials of VB !! Creating User Services !! function !! Anatomy !! GK March-2019 !! DATA TYPES IN JAVA !! Classes ,Constructor ,Methods,Inheritance !! Ecology-I !! Biology 2019 !! Gk april 2019 !! Biology (living world) !! Plant anatomy !! CELL STRUCTURES AND FUNCTION !! General biology !! Human physiology !! Data structure !! Ecology-II !! GK TEST !! Reproduction in plants !! Human reproduction !! The ABC of C !! Operating system set1 !! Operating system set2 !! Gk and current affairs !! Animal kingdom !! Number system !! Animal kingdom-II !! Gk TEST-III !! Number series !! Microorganisms !! Interview question in c !! Time and Work !! Percentage !! General history !! Average !! Cells !! Locomotion and Movement !! paging !! Bacteriology !! Page replacement policy !! Secondary memory and Disk scheduling !! Introduction of Nervous System and neurons !! Plant harmones !! Transport and Mineral Nutrition in Plants !! Neurotransmitters !! Modern Indian History !! Photosynthesis in Plants !! Modern Indian History-II !! Plant respiration !! Environment & Biodiversity !! Environment & Biodiversity - II !! Algae, Bryophytes, Pteridophytes !! Area !! Cricket !! Days of the Year (India and the World) !! Plant Pathology - I !! Indian Transport System !! Plant Pathology - II !! Aptitude !! Biology !! Botany !! C language !! Computer Science !! Core Java !! Gate !! GK !! Mysql !! Operating system !! Physics !! VB-Visual Basic !! Zoology


JavaXml Projects

JavaXml Project 1

JavaXml Examples


Regenerating XML Document
Previous Home Next

In this page of tutorials, we will be learn to get the elements and its value using DOM APIs. In this program parses a xml file and regenerates it at the console using the DOM APIs. In This program we are take a XML file and check it is available or not . If file is exist then it creates DocumentBuilderFactory. This object creates a DocumentBuilder which parses the XML document using the parser() method. It invokes the DocumentBuilder object and creates a Document object. Through this object you create DOM tree nodes by using the getDocumentElement() method and passes it to the DOMSource(). The DOMSource constructor creates a new input source with a DOM node. And the destination source uses the StreamResult() constructor.

<?xml version = "1.0" ?>
<stu_Id> s-001 </stu_Id>
<stu_Name> samir </stu_Name>
<stu_E-mail> </stu_E-mail>
[an error occurred while processing this directive] <Student>
<stu_Id> s-002 </stu_Id>
<stu_Name> Ajit </stu_Name>
<stu_E-mail> </stu_E-mail>
<stu_Id> E-003 </stu_Id>
<stu_Name> Deepti </stu_Name>
<stu_E-mail> </stu_E-mail>


Here is the Java File:

package r4r;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.parsers.*;
import javax.xml.transform.*; 
import javax.xml.transform.dom.*; 
public class studentrecord {
	public static void main(String[] arg)throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(;
		System.out.print("Enter the XML File Name: ");
		String xmlFile = br.readLine();
		File file = new File(xmlFile);
		try {
		DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
		DocumentBuilder build = fact.newDocumentBuilder();
		Document docu = build.parse(xmlFile); 
		TransformerFactory tFact = TransformerFactory.newInstance(); 
		Transformer trans = tFact.newTransformer(); 
		Node node =docu.getDocumentElement();
		Source src = new DOMSource(node); 
		Result rs = new StreamResult(System.out);
		trans.transform(src, rs);
		catch (Exception e) {
		System.out.print("File not found!");
Previous Home Next