Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] XML - Resursive functions .........has a question

jack

2004-08-03

Replies:

Hello for everyone,
I have the following xml file...
<?xml version="1.0" encoding="BIG5"?>
<books>
<book id="A01">

<title ISBN="A1195">JAVA PRIMER</title>
<author>Dr.1</author>
<author>Dr.2</author>
<author>Dr.3</author>
</book>
<book id="A02">

<title ISBN="C8254">JSP reference</title>
<author>Dr.4</author>

</book>
</books>
=================================================
I use the following code...to parse the data out
from this xml but not really getting the correct
result(this author can't correct show the window).
How can i show Resursive functions
==========================================
<%@ page import="org.jdom.*" %>
<%@ page import="org.jdom.input.*" %>
<%@ page import="java.util.*,java.io.*" %>
<%@ page contentType="text/html;charset=MS950" %>
....
....
<%
Element bookElement;
Element titleElement;
Element authorElement;

//Element idElement;

SAXBuilder builder = new SAXBuilder(false);


Document doc = builder.build("http://localhost:8080/JSPBook/CH17/Books.xml");

Element rootElement = doc.getRootElement();
List books = rootElement.getChildren("book");
Iterator i = books.iterator();

while (i.hasNext())
{
bookElement = (Element) i.next();

String id1 = bookElement.getAttributeValue("id");


titleElement = bookElement.getChild("title");
String ISBN = titleElement.getAttributeValue("ISBN");

// test
List authors = titleElement.getChildren("author");
Iterator j = authors.iterator();
while ( j.hasNext() ) {
Element author = (Element) j.next();

//authorElement = bookElement.getChild("author");
out.println("author&#65306;" + author.getText() + "</BR>");
}
//
out.println("ID&#65306;" + id1 + "</BR>");
out.println("book name&#65306;" + titleElement.getText() + "</BR>");
out.println("ISBN&#65306;" + ISBN + "</BR>");

out.println("------------------------------------" + "</BR>");


}
%>

©2008 junlu.com - Jax Systems, LLC, U.S.A.