-
Missing bytes with JAVA SAX Parser
I am using JAVA SAX parser to parse a XML file and write the contents to a text file. When the XML file size is small, my program is working fine and contents are retreived correctly but when the XML file size is big (the file size I got the problem with is 1MB), few bytes are missing in contents randomly.
XML file:
<Record>
<id>S</id>
<Sender>PETER</Sender>
<PayIdNum>123456789</PayIdNum>
<ContractNumber>150738</ContractNumber>
<StartDate>20060101</StartDate>
<EndDate>20061231</EndDate>
<Auto>N</Auto>
<check>Y</check>
</Record>
When parsed the file with above records,
content in <PayIdNum> is extracted as 789 for few records,
content in <Sender> is extracted as ER for few redords and
for few other records Date fields as 060101.
Number of records missing the bytes is very less in comparision with the total number of records in the file, for a XML file with 2100 records this problem happened to only 10 records.
when debugged the program:
public void characters(char[] ch, int start, int len) throws SAXException {
String str=new String(ch, start, len);
}
in this methos for <PayIdNum> it showed len=3, start=0 and str=789;
actual size of this field is 9, it showed the same size for all other records but only for the bytes missing records it showed the length lesser than the actual length.
I did not get any clue where else I need to check when parser itself is showing the wrong character array size.
Any help on this problem please? it's an urgent requirement.
-
Missing data using SAX parser
You need add each chunk of data given in the characters(char[], int, int) event callback.
The javadoc states:
"The Parser will call this method to report each chunk of character data. SAX parsers may return all contiguous character data in a single chunk, or they may split it into several chunks"
In the endElement() method, reset the accumulated string.
Similar Threads
-
Replies: 2
Last Post: 06-14-2006, 03:16 PM
-
Replies: 1
Last Post: 05-13-2005, 06:46 AM
-
By Rob Abbe in forum Talk to the Editors
Replies: 44
Last Post: 01-13-2003, 02:57 PM
-
By Mike Tsakiris in forum .NET
Replies: 11
Last Post: 10-04-2002, 05:32 PM
-
By JJ in forum Enterprise
Replies: 1
Last Post: 07-06-2000, 04:50 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks