Hello,
 
i am trying to read an xml file from a zip archieve end execute some xpath expressions.
 
the problem is, that i get always en xml parser error:

SXXP0003: Error reported by XML parser: Premature end of file.

net.sf.saxon.s9api.SaxonApiException: org.xml.sax.SAXParseException: Premature end of file.

at net.sf.saxon.s9api.DocumentBuilder.build(DocumentBuilder.java:338)

at CodesMapping.main(CodesMapping.java:65)

Caused by: net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException: Premature end of file.

at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:417)

at net.sf.saxon.event.Sender.send(Sender.java:182)

at net.sf.saxon.Configuration.buildDocument(Configuration.java:3272)

at net.sf.saxon.s9api.DocumentBuilder.build(DocumentBuilder.java:335)

... 1 more

Caused by: org.xml.sax.SAXParseException: Premature end of file.

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:236)

at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:215)

at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:386)

at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:316)

at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:230)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:798)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)

at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)

at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)

at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:397)

My code listing:

public static void main(String[] args) {

try {

    Configuration config = new PropertiesConfiguration("properties/sidcom-aspim-mapper.properties");

    ZipFile zipfile = new ZipFile(config.getString("path.zipfile"));

    for (Enumeration<? extends ZipEntry> e = zipfile.entries(); e.hasMoreElements();) {

        ZipEntry entry = e.nextElement();

        if (entry.getName().equals("Elements/Product_Technology/Product_Technology.xml")) {

            InputStream is = zipfile.getInputStream(entry);

            Processor processor = new Processor(false);

            XPathCompiler compiler = processor.newXPathCompiler();

            XPathSelector selector = compiler.compile("//ProductTehnologyAbs[PRODUCT_CODE/@value='I1100']/ACCESS_TYPE/@value").load();

            XdmNode node = processor.newDocumentBuilder().build(new StreamSource(is));

            // XdmNode node = processor.newDocumentBuilder().build(//new StreamSource("test.xml"));

            //When i use an xml file from my local disk (which content is exactly the same  as from the zipped xml file) it works fine.

            selector.setContextItem(node);

            for (XdmItem item : selector) {

                System.out.println(item.getStringValue());

            }

}

} catch (IOException e) {

    e.printStackTrace();

} catch (ConfigurationException e) {

    e.printStackTrace();

} catch (Exception e) {

    e.printStackTrace();

}

}

So what am i missing here... is there a problem with the inputstream?? that there are some bytes missing or whatever?

thx in advance fpr ur help. i appreciate it.

Kind regards

Stefan Theissen 
                                                                                  

7P Solutions & Consulting AG
Sitz der Gesellschaft: Köln
Amtsgericht: Köln
Handelsregister: HRB 32361

Aufsichtsratvors.: Jens Harig

Vorstand: Klaus Mahle, Jens Perpeet 
USt-ID-Nr.: DE 197820124
Steuer-Nr.: 215/5917/1764

                                                                                                             
Der Inhalt dieser e-Mail ist ausschließlich für den bezeichneten Adressaten bestimmt. Wenn Sie nicht der vorgesehene Adressat dieser e-Mail oder dessen Vertreter sein sollten, beachten Sie bitte, dass jede Form der Veröffentlichung, Vervielfältigung oder Weitergabe des Inhalts dieser e-Mail unzulässig ist. Wir bitten Sie sofort den Absender zu informieren und die E-mail zu löschen.

The information contained in this e-mail is intended solely for the addressee. Access to this e-mail by anyone else is unauthorized. If you are not the intended recipient, any form of disclosure, reproduction, distribution or any action taken or refrained from in reliance on it, is prohibited and may be unlawful. Please notify the sender immediately and destroy this e-mail.