hi guys,
This is murali krishna. i have a small problem,
i have one xml file (books.xml)

<?xml version="1.0" encoding="iso-8859-1"?>
<library>
<book id="1">
<name>Head First Java, 2nd Edition</name>
<author>Kathy Sierra and Bert Bates</author>
<publication-date>09-Feb-2005</publication-date>
</book>
<book id="2">
<name>Effective Java</name>
<author>Joshua Bloch</author>
<publication-date>28-May-2008</publication-date>
</book>
<book id="3">
<name>Java How to Program, 7th Edition</name>
<author>Harvey M. Deitel and Paul J. Deitel</author>
<publication-date>6-Jan-2007</publication-date>
</book>
</library>

I tried to read this xml file in jsp as shown below

<%@ page language="java" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="javax.xml.parsers.DocumentBuilder" %>
<%@ page import="javax.xml.parsers.DocumentBuilderFactory" %>
<%
DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
DocumentBuilder db =dbf.newDocumentBuilder();
Document doc=db.parse("c:\\books.xml");


NodeList nl = doc.getElementsByTagName("book");

%>
<html>
<head>
<title>How to read XML file in JAVA</title>
</head>
<body>
<%

for(int i=0;i<nl.getLength();i++)
{
NodeList nameNlc= doc.getElementsByTagName("name");
Element nameElements=(Element)nameNlc.item(i);
String nameTagValue=nameElements.getChildNodes().item(0). getNodeValue();


NodeList authorNlc= doc.getElementsByTagName("author");
Element authorElements=(Element)authorNlc.item(i);
String authorTagValue=authorElements.getChildNodes().item (0).getNodeValue();

NodeList dateNlc= doc.getElementsByTagName("publication-date");
Element dateElements=(Element)dateNlc.item(i);
String dateTagValue=dateElements.getChildNodes().item(0). getNodeValue();

out.println("name :"+nameTagValue+"<br>");
out.println("author :"+authorTagValue+"<br>");
out.println("publication-date :"+dateTagValue+"<br><br>");
}

%>

</body>
</html>

so, my problem is I was unable to read the attribute of the tag book , that is "id".
can any one tell me how to read this "id" attribute.

Murali Krishna
himacherla@gmail.com