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


Adding DOCTYPE in XML Document
Previous Home Next

In this program, we will be learn that how we can add a DOCTYPE to your XML file using the DOM application programming interfaces. This program is help to add a DOCTYPE in your XML file. Its Program takes a XML document name and checks it, the given file is exists or not. If the given file exists then it is parsed using the parse() method and a Document object tree is created . Abstract class Transformer is used to transform a source tree into a xml file The setOutputProperty() method invokes to the Transformer object and sets the system Id and public Id to the DOCTYPE in the XML file.


Here is the XML File: Student_Detail.xml

<?xml version = "1.0" ?>
<stu_Id> s-001 </stu_Id>
<stu_Name> samir </stu_Name>
<stu_E-mail> </stu_E-mail>
<stu_Id> s-002 </stu_Id>
<stu_Name> Ajit </stu_Name>
<stu_E-mail> </stu_E-mail>
<stu_Id> s-003 </stu_Id>
<stu_Name> Deepti </stu_Name>
<stu_E-mail> </stu_E-mail>

Here is the Java File:


package r4r;
import javax.xml.parsers.*;
import org.w3c.dom.*;
import org.xml.sax.*;
import javax.xml.transform.*; 
import javax.xml.transform.dom.DOMSource; 
public class studentrecord {
	static public void main(String[] args){
		  BufferedReader br = new BufferedReader(
		  new InputStreamReader(;
		  System.out.print("Enter the XML file name: ");
		  String str = br.readLine();
		  File file = new File(str);
		  if (file.exists()){
		  DocumentBuilderFactory fact = 
		  DocumentBuilder build = fact.newDocumentBuilder();
		  Document docu = build.parse(str);
		  Transformer tf = 
		  OutputKeys.DOCTYPE_SYSTEM, "systmId");
		  Source src = new DOMSource(docu);
		  Result result = new StreamResult(System.out);
		  tf.transform(src, result);
		  System.out.println("File not found!");
		  catch (Exception e){
Previous Home Next