Parsing XML inside zip memory

I have a zip that contains two files: XML and thumbnail. I would like to open an XML file and parse it WITHOUT having to extract it to disk.

One of the parse methods of DocumentBuilder requires an InputStream. Is there a way to get InputStream XML in a zipped file? I somehow got lost. I am sure that ZipInputStream or ZipFile can offer something, but I cannot understand: /

Thank you in advance!

+7
source share
2 answers

I believe that you are looking for something like this:

FileInputStream fin = new FileInputStream("your.zip"); ZipInputStream zin = new ZipInputStream(fin); ZipEntry ze = null; while ((ze = zin.getNextEntry()) != null) { if (ze.getName().equals("your.xml")) { // pass zin to DocumentBuilder } } 
+4
source

There are several input classes in java.util.zip , not sure if they help, but it looks promising, especially ZipInputStream .

0
source

All Articles