Hello, I'm trying to parse this file on Android using the DOM method.
The code in question is:
try {
URL url = new URL("https://www.beatport.com/en-US/xml/content/home/detail/1/welcome_to_beatport");
InputSource is = new InputSource(url.openStream());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(is);
document.getDocumentElement().normalize();
} catch(Exception e) {
Log.v(TAG, "Exception = " + e);
}
But I'm getting the following exception:
V/XMLParseTest1( 846):Exception = org.xml.sax.SAXParseException: name expected (position:START_TAG <null>@2:176 in java.io.InputStreamReader@43ea4538)
The file is being handed to me gzipped. I've checked the is
object in the debugger and its length is 6733 bytes (the same as the content length of the file in the response headers) however if I save the file to my harddrive it's size is 59114 bytes. Furthermore if I upload it to my own server which doesn't gzip XML-s when it serves them and set the URL the code runs just fine.
I'm guessing that what happens is that Android tries to parse the gzipped stream.
Is there a way to first unzip the stream? Any other ideas?