trying to feed a zip file containing an XML one to a SAX parser ...
~
the simple code below I use to feed an XMLReader with compressed ".bz2" and ".gz"
~
Since the zip file format is a container as well, I could imagine things are not that simple
~
How can you do the same (or a similar) thing with a zip file?
~
thanks
lbrtchx
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~
IFl = new File(aFlPth);
aFlPth = IFl.getCanonicalPath();
if(aFlPth.toLowerCase().endsWith(".gz")) {
BfrRdr = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(IFl)), "UTF-8"));
}
else if (aFlPth.toLowerCase().endsWith(".bz2")) {
BfrRdr = new BufferedReader(new InputStreamReader(new BZip2CompressorInputStream(new FileInputStream(IFl)), "UTF-8"));
}
else {
BfrRdr = new BufferedReader(new InputStreamReader(new FileInputStream(IFl), "UTF-8"));
}
// __
SAXParserFactory SAXFctry = SAXParserFactory.newInstance();
SAXFctry.setValidating(false);
SAXFctry.setNamespaceAware(true);
SchemaFactory SchmFctry = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI);
SAXParser SAXPrsr = SAXFctry.newSAXParser();
XMLRdr = SAXPrsr.getXMLReader();
// __ Register the content handler
XMLRdr.setContentHandler(new DefaultHandler2());
// __
lTm00 = System.currentTimeMillis();
XMLRdr.parse(new InputSource(BfrRdr));
System.err.println(TU.getElapsedTime(lTm00));
~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
~