Solved

XML Paring  Error - Premature end of file.

Posted on 2016-09-27
7
56 Views
Last Modified: 2016-10-04
I am decrypting XML file and in memory, I am parsing it for searching particular XML element. If I store the file on disk after decypting and then read that file for parsing, program works fine. But when I decrypt the file and pass it to DOM Parser as InputStream then I am getting this exception. What possibly I am doing wrong:

[Fatal Error] :1:1: Premature end of file.
org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Premature end of
file.
        at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.
java:257)
0
Comment
Question by:MehtaJasmin
  • 3
  • 2
7 Comments
 
LVL 27

Accepted Solution

by:
BigRat earned 500 total points
ID: 41819505
It looks as if the InputStream was not set up properly. You'll have to post the code.
0
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 41820026
upload a sanitized copy of the file you are trying to read. you may only have
<tablename>data</tablename></xml>
0
 

Author Comment

by:MehtaJasmin
ID: 41820094
I fixed the issue indirectly by doing the needful for the InputStream object within the calling method. Rather than caller method.

Below is now the code inside method decrypt(). And in main() method I am using the Document object. If I get InputStream/Reader/InputSource by invoking this decrypt() method in main(), it does not keep the stream object and gives me the same 'premature end of file' exception. But if I also build the Document object in the decrypt() method and than invoke/use that object in main() method, I don't get the exception.

xmlDoc is Document object

               
                               InputStream unc = ld.getInputStream();
                Reader reader = new InputStreamReader(unc,"UTF-8");
                
                InputSource xmlSource = new InputSource(reader);
                xmlSource.setEncoding("UTF-8");                

                DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
  		        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
  		        this.xmlDoc = docBuilder.parse(xmlSource);

Open in new window

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 27

Expert Comment

by:BigRat
ID: 41820185
I have never understood the weird way of getting an XML "Document" for SAX parsing. But still I'm glad it's working.
0
 
LVL 27

Expert Comment

by:BigRat
ID: 41827841
Sorry, but I did suggest that you look at InputStream which you did and that fixed the problem.
0
 

Author Closing Comment

by:MehtaJasmin
ID: 41827916
Thanks for giving tip on InputStream
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now