<%@page import="org.w3c.dom.Node, org.w3c.dom.Element, org.w3c.dom.Document, org.w3c.dom.NodeList, javax.xml.parsers.DocumentBuilder, javax.xml.parsers.DocumentBuilderFactory" %> <%! DocumentBuilder addressBookParser; Document addressBook; Element contact; int count; %> Contact Managment System [Home Page] <% DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setValidating( false ); DocumentBuilder addressBookParser = dbf.newDocumentBuilder(); Document addressBook = addressBookParser.parse("http://localhost:80/addressbook/AddressBook.xml"); addressBook.getDocumentElement().normalize(); NodeList contactsAll = addressBook.getElementsByTagName("Contact"); NodeList namesAll = addressBook.getElementsByTagName("Name"); count=contactsAll.getLength(); %>

Contact Management System

<% for (int ctr = 0; ctr < contactsAll.getLength(); ctr++) { int nodeIndex = ctr+1; Node contactName = namesAll.item(ctr); Element names = (Element)namesAll.item(ctr); NodeList lastNameList = names.getElementsByTagName("Last"); Node lastNameElement = lastNameList.item(0); Node lastNameTextNode = lastNameElement.getFirstChild(); String lastNameText = lastNameTextNode.getNodeValue().trim(); NodeList firstNameList = names.getElementsByTagName("First"); Element firstNameElement = (Element)firstNameList.item(0); Node firstNameTextNode = firstNameElement.getFirstChild(); String firstNameText = firstNameTextNode.getNodeValue().trim(); %> <% } // end of firstname, lastname loop %>
This application uses JavaServer Pages (JSPs), Servlets, and Java classes to parse an XML file (AddressBook.xml) and display a listing of all names. You can search for a specific name to display the entire infoset about that contact, you can add new contacts, delete existing contacts, and update the infoset about a specific contact, all from this starting page.
Add a new contact Search for a specific contact
 
AddressBook Listing
Last name First name Contact id   Manage this contact:
<%= lastNameText + "" + firstNameText + "" + nodeIndex %>   Edit Delete

Total records displayed from Kelli's contact AddressBook.xml: <%= count %>