Read XML file using Jsp

This is simple example to read/parse xml file using jsp web application.
 
name.xml
<?xml version="1.0" encoding="utf-8"?>

<xmldata>
    <student>
        <RegistrationNo>1</RegistrationNo>
        <StudentID>1110708058</StudentID>
        <Name>Jatin</Name>
        <FName>Patel</FName>
    </student>
    <student>
        <RegistrationNo>2</RegistrationNo>
        <StudentID>1110708048</StudentID>
        <Name>Ashvin</Name>
        <FName>Patel</FName>
    </student>
</xmldata>
 
 
ReadXML.jsp
 
<%@ page contentType="text/html; charset=utf-8" language="java" import="javax.xml.parsers.DocumentBuilderFactory,javax.xml.parsers.DocumentBuilder,org.w3c.dom.*" errorPage="" %>
<%
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

DocumentBuilder db = dbf.newDocumentBuilder();

Document doc = db.parse("name.xml");

NodeList RegistrationNo = doc.getElementsByTagName("RegistrationNo");
NodeList StudentId = doc.getElementsByTagName("StudentID");
NodeList Name = doc.getElementsByTagName("Name");
NodeList FName = doc.getElementsByTagName("FName");
%>

<html>
<head>
<title>Read Xml Data</title>
</head>

<body>
<table border="1">
<%
int i;
for(i=0;i<=RegistrationNo.getLength()-1;i++)
{
%>

<tr>
<td>

 <%= RegistrationNo.item(i).getFirstChild().getNodeValue()%>
</td>
<td>
    <%= StudentId.item(i).getFirstChild().getNodeValue()%>
</td>
<td>
    <%= Name.item(i).getFirstChild().getNodeValue()%>
</td>
<td>
    <%= FName.item(i).getFirstChild().getNodeValue()%>
</td>
</tr>
<%
}
%>
</table>
</body>
</html>