XML

index.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();
 
    out.println(getServletContext().getRealPath("/"));
   
    Document doc = db.parse(getServletContext().getRealPath("/")+"datos.xml");

    NodeList NoEstudiante = doc.getElementsByTagName("NoEstudiante");
    NodeList Carnet = doc.getElementsByTagName("Carnet");
    NodeList Nombre = doc.getElementsByTagName("Nombre");
    NodeList Apellido = doc.getElementsByTagName("Apellido");
%>

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

    <body>
        <table border="1">
            <tr>
                <td>No.</td>
                <td>Carnet</td>
                <td>Nombre</td>
                <td>Apellido</td>
            </tr>
            <%
                int i;
                for (i = 0; i <= NoEstudiante.getLength() - 1; i++) {
            %>

           
            <tr>
                <td>

                    <%= NoEstudiante.item(i).getFirstChild().getNodeValue()%>
                </td>
                <td>
                    <%= Carnet.item(i).getFirstChild().getNodeValue()%>
                </td>
                <td>
                    <%= Nombre.item(i).getFirstChild().getNodeValue()%>
                </td>
                <td>
                    <%= Apellido.item(i).getFirstChild().getNodeValue()%>
                </td>
            </tr>
            <%
                }
            %>
        </table>
    </body>
</html>

xml
<?xml version="1.0" encoding="utf-8"?>

<xmldata>
    <Estudiante>
        <NoEstudiante>1</NoEstudiante>
        <Carnet>2017001</Carnet>
        <Nombre>Soyla</Nombre>
        <Apellido>Prim Era</Apellido>
    </Estudiante>
    <Estudiante>
        <NoEstudiante>1</NoEstudiante>
        <Carnet>2017002</Carnet>
        <Nombre>Soyel</Nombre>
        <Apellido>Segun Do</Apellido>
    </Estudiante>
    <Estudiante>
        <NoEstudiante>3</NoEstudiante>
        <Carnet>2017003</Carnet>
        <Nombre>Estudiante</Nombre>
        <Apellido>Tres</Apellido>
    </Estudiante>
</xmldata>