dom4j的问题
- Java code
public Document getDocument(URL url) throws Exception { Document document = null; SAXReader saxReader = new SAXReader(); document = saxReader.read(url); return document; }
saxReader.read(url); 这个url指的是什么啊?
我写了个测试的.但是不好用, 不明白URL该写什么??
测试如下:
- Java code
public static void main(String[] args) throws Exception { TestDom4j td = new TestDom4j(); URL url = td.getClass().getProtectionDomain().getCodeSource().getLocation(); System.out.println(url); Document doc = td.getDocument(url); }
出错了: org.dom4j.DocumentException: Error on line 1 of document file:/D:/workspace_j2ee/XML/build/classes/ : Content is not allowed in prolog. Nested exception: Content is not allowed in prolog.
[解决办法]
url指向一个xml文档