Small snippet of program challenging me from a day,
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import com.rometools.rome.io.FeedException;
public class Test {
public static void main(String[] args) throws IllegalArgumentException, FeedException, IOException {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
InputStream openStream = new URL("http://www.livemint.com/rss/money").openStream();
Document doc = db.parse(openStream);
System.out.println(doc.getDocumentURI());
} catch (Exception e) {
e.printStackTrace();
}
}
}
All this experiment started from the rome tools parser code, which was giving me same error in different approaches also.
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(url));
feed.getEntries();
Exception was getting thrown in creating new xml Reader, so i wrote a test program in different approach. Now both are throwing the same error,
[Fatal Error] :1:1: Premature end of file.
I have to fetch xml response from a url, but not able to do.