Thursday, December 4, 2008

A rather cryptic Java SAX XML error

So, i received this error "The processing instruction target matching "[xX][mM][lL]" is not allowed." from an rss feed using JRSST. Not the most transparent message ever. I found by Googling that this means '<' wasn't the very first character in the file. Sure enough. So here's the Java i wrote to get around this (assuming you already have an InputStream from URL openConnection and connect):
PushbackInputStream pbis = new PushbackInputStream (inputstream);

int c;
while ((c = pbis.read()) != '<') {}

pbis.unread (c);

inputsource = new InputSource (pbis);

No comments: