In my Eclipse project, I'm trying to parse an xml file into a String List to display in a jsp file.
My parser works perfectly with this code:
public class XMLReader{
public static void main(String [] args){
System.out.println(getXML());
}
public static String getXML(){
try{
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
XMLHandler handler = new XMLHandler(); // class I created extending DefaultHandler
saxParser.parse("file.xml",handler);
urls = handler.getXMLList();
}
catch(Exception e){
e.printStackTrace();
}
return urls.toString();
}
}
The string list is printed to my console as desired. But when I try to rewrite the methods to return a string so that I can use it in my jsp file:
public class XMLReader{
public String returnXML(){
return getXML().toString();
}
public List<String> getXML(){
...
}
}
I receive a java.io.FileNotFoundException. In my console, it shows that Eclipse is trying to find the file in the folder containing my eclipse.exe, rather than in my workspace folder. I've been searching the Internet for a couple hours but I have no idea what's causing to look in a different folder. I'm not sure if making the methods non-static or using a jsp file is causing the file path to change, but I'm only encountering this issue with my saxParser.parse(file,handler) line of code, and I have no clue how to fix it. Any help would be great!