/*
Joe
30
Rob
29
*/
<%@ page import="org.jdom.Element,
org.jdom.Document,
org.jdom.input.SAXBuilder,
java.util.List,
java.util.Iterator"
%>
<%
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build("http://localhost:8080/chapter11/people.xml");
List children = doc.getRootElement().getChildren(); // 2 person nodes
Iterator iter = children.iterator();
%>
Parsing using JDOM
List of people
Name Age
<%
while (iter.hasNext()) // for each "person" node
{
Element currentItem = (Element) iter.next(); // each "person"
List nameAndAge = currentItem.getChildren();
Iterator nameAgeIter = nameAndAge.iterator();
%>
<%
while ( nameAgeIter.hasNext() )
{
Element child = (Element) nameAgeIter.next(); // "name" or "age"
%>
<%= child.getText() %>
<%
}
}
%>