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

JAVA XML

JavaXml Projects

JavaXml Project 1

JavaXml Examples

JavaXml EXAMPLE

Access The XML Root Element
Previous Home Next

For accessing the root element of the XML document firstly need to create the XML document and in this the firstly element is declare as the root element and other is sub element of the document. for this the JAXP (java APIs for XML processing) is provide the interface for creating the XML document using the SAX, DOM and XSLT.

Here is the XML File: Student_Detail.xml

<?xml version = "1.0" ?>
<Student_Detail>
<Student>
<stu_Id> s-001 </stu_Id>
<stu_Name> samir </stu_Name>
<stu_E-mail> sam1@gmail.com </stu_E-mail>
</Student>
<Student>
<stu_Id> s-002 </stu_Id>
<stu_Name> Ajit </stu_Name>
<stu_E-mail> Ajit2@yahoo.com </stu_E-mail>
</Student>
</Student_Detail>

 

Here is the Java File: StudentRecord.java

package r4r;
import org.w3c.dom.*;
import javax.xml.parsers.*;
import java.io.*;
public class accessroot {
public static void main(String[] args) {
try{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
System.out.print("Enter the xml file name: ");
String str = br.readLine();
File file = new File(str);
if (file.exists()){
DocumentBuilderFactory docfact =
DocumentBuilderFactory.newInstance();
DocumentBuilder build = docfact.newDocumentBuilder();
Document docu = build.parse(str);
Node node = docu.getDocumentElement();
String str1 = node.getNodeName();
System.out.println("Root Node: " + str1);
}
else{
System.out.println("File not found!");
}
}
catch(Exception e){}
}
}
Previous Home Next