作者Andyleee (我是大猪头哇哈哈哈哈)
看板java
标题[问题] 关於dom4的NoClassDefoundError..
时间Sat Mar 11 18:44:51 2006
小弟不才, 利用xml书籍附的程式码来测试xml文件
dom4j的程式码如下:
import org.dom4j.*;
import org.dom4j.io.*;
import java.io.*;
import java.util.*;
public class XPathDemo
{
public static void main(String[] args)
{
try
{
SAXReader reader = new SAXReader();
Document doc = reader.read(new File("bookshelf.xml"));
// get XPath
XPath xpath = DocumentHelper.createXPath("/bookshelf/level/book");
List list = xpath.selectNodes(doc);
for(int i = 0; i < list.size(); i++)
{
System.out.println("Book " + (i+1));
Element el = (Element)list.get(i);
// get childen of element book
Iterator it = el.elementIterator();
while(it.hasNext())
{
Element childEl = (Element)it.next();
System.out.println(childEl.getName() + ": " + childEl.getText());
}
}
}
catch(DocumentException e)
{
// error in the XML document
System.out.println(e);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
xml的程式码如下:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- My Bookshelf -->
<bookshelf>
<level name="Physics">
<book><title>Mechanics</title>
<author>Symon</author>
</book>
<book><title>Optics</title>
<author>Hecht</author>
</book>
</level>
<level name="Math">
<book><title>Principles of Mathematical Analysis</title>
<author>Rudin</author>
</book>
<book><title>Linear Algebra</title>
<author>Lang</author>
</book>
</level>
</bookshelf>
因为是书的光碟附的程式码...所以应不至於有错
我有去dom4j的官网下载dom4j.jar放在C:\java\j2sdk1.4.5\jre\lib\ext
但是还是发生"NoDefoundClassError"
有人说是因为要使用"dom4j-full.jar" package才能正常执行
但是我在官网根本看不到有dom4j-full.jar载点
拜托救救我吧><
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.161.7.138