<%@page contentType="text/xml"%> <%@page pageEncoding="UTF-8"%> <%@page import="javax.xml.parsers.*,org.w3c.dom.*,java.io.*" %> <% //Grab category String val = request.getParameter("category"); //Get reference to xml file File booksFile = new File(application.getRealPath("/allBooks.xml")); //Create DocumentBuilderFactory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); //Create DocumentBuilder DocumentBuilder db = null; db = dbf.newDocumentBuilder(); //Parse xml to Document object Document allBooks = null; allBooks = db.parse(booksFile); //All data stored in elements NodeList allRecords = allBooks.getElementsByTagName("record"); //Get number of records for loop int len = allRecords.getLength(); //Create StringBuffer to hold xml for matching records StringBuffer buffer = new StringBuffer(256); buffer.append(""); //Loop through records and grab those with matching category for(int i=0; i"); int cLen = allRecords.item(i).getChildNodes().getLength(); for(int j=0; j"); buffer.append(allRecords.item(i).getChildNodes().item(j).getTextContent()); buffer.append(""); } buffer.append(""); } } buffer.append(""); //Write StringBuffer to response out.print(buffer.toString()); %>