Reputation: 1
I'm having a problem passing an XML page into the SAXParser as a variable. My code below obtains a URL and tries to pass it into the SAXParser, but I get an error.
However, when I explicitly define the URL (rather than use the variable), if works fine. Does anyone no why this is failing.
Thanks to anyone who may be able to help. I've trimmed the code for viewing purposes.
public class Parser extends DefaultHandler
private String link;
public void parseDocument() {
SAXParserFactory spf = SAXParserFactory.newInstance();
try {
SAXParser sp = spf.newSAXParser();
link = coll.getGcollId(id); // this successfully gets a string (url) to link to xml page over http string
//parse the file and also register this class for call backs
sp.parse(link, this); // when I run this code this line gets a "java.io.FileNotFoundException: http://foo.com/foo.xml"
Upvotes: 0
Views: 4287
Reputation: 134
Use the following instead
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
String link = coll.getGcollId(id);
URL linkURL = new URL(link);
sp.parse(new InputSource(url.openStream()));
Upvotes: 3