Hello,
I'm trying to load and parse XML file and get the
following errors:
org.dom4j.DocumentException: test.xml (The system
cannot find the file specified) Nested exception:
test.xml (The system cannot find the file specified)
at org.dom4j.io.SAXReader.read(SAXReader.java:266)
at
gov.loc.xmlbill.LoadAndParseXMLBill.parseUsingSAX(LoadAndParseXMLBill.java:34)
at
gov.loc.xmlbill.LoadAndParseXMLBill.main(LoadAndParseXMLBill.java:22)
Nested exception:
java.io.FileNotFoundException: test.xml (The system
cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at
java.io.FileInputStream.<init>(FileInputStream.java:106)
at org.dom4j.io.SAXReader.read(SAXReader.java:243)
at
gov.loc.xmlbill.LoadAndParseXMLBill.parseUsingSAX(LoadAndParseXMLBill.java:34)
at
gov.loc.xmlbill.LoadAndParseXMLBill.main(LoadAndParseXMLBill.java:22)
Nested exception: java.io.FileNotFoundException:
test.xml (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at
java.io.FileInputStream.<init>(FileInputStream.java:106)
at org.dom4j.io.SAXReader.read(SAXReader.java:243)
at
gov.loc.xmlbill.LoadAndParseXMLBill.parseUsingSAX(LoadAndParseXMLBill.java:34)
at
gov.loc.xmlbill.LoadAndParseXMLBill.main(LoadAndParseXMLBill.java:22)
Here is the code:
package gov.loc.xmlbill;
import java.io.*;
import java.util.*;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.dom4j.io.DOMReader;
public class LoadAndParseXMLBill {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try
{
LoadAndParseXMLBill landp = new
LoadAndParseXMLBill();
Document d = landp.parseUsingSAX();
landp.printElements(d);
}catch(Exception e)
{
e.printStackTrace();
}
}
public Document parseUsingSAX() throws
DocumentException, Exception
{
SAXReader reader = new SAXReader();
Document document = reader.read(new
File("test.xml"));
return document;
}
public void printElements(Document document) throws
DocumentException
{
Element root = document.getRootElement();
// iterate through child elements of root
for ( Iterator i = root.elementIterator();
i.hasNext(); )
{
Element element = (Element) i.next();
System.out.println("Element
Name:"+element.getQualifiedName() );
System.out.println("Element
Value:"+element.getText());
}
}
}
Please help, thanks.
My Pham
____________________________________________________________________________________
8:00? 8:25? 8:40? Find a flick in no time
with the Yahoo! Search movie showtime shortcut.
http://tools.search.yahoo.com/shortcuts/#news
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
dom4j-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dom4j-dev