Menu

#35 SAXParser truncating value of some records

open
nobody
None
5
2014-08-15
2005-02-13
Arun
No

I’m parsing a long XML file at runtime in my web
application. I’m facing a problem here that after parsing
a long set of data towards the end the SAX Parser is
truncating the value of an entry. It’s a long XML file
generated dynamically and there are around 83 records
in the resultset. The parser parses fine till the 81st
record and at 82nd entry value it truncates the value.
The sample xml is follows:

<XMLRESULTSET>
<ROW>
<COL name="ERRORCODE"></COL>
<COL name="ERRORDESCRIPTION"></COL>
<COL name="COMPANYNO">3345672</COL>
<COL name="NEWJOBPROVIDER">0</COL>
<COL name="NOOFJOBRECORDS">83</COL>
<MULTIVALUEDCOL name="RECORDS">
<ENTRYSET>
<ENTRY name="HIGHLIGHT">0</ENTRY>
<ENTRY name="JOBOPENINGRECORDNO">3124</ENTRY>
<ENTRY name="JOBTITLE">Admin Manager</ENTRY>
<ENTRY name="JOBOPENINGSTATUS">1</ENTRY>
<ENTRY name="JOBOPENINGPOSTDATE">2004-12-
14</ENTRY>
<ENTRY name="NOOFAPPLICANTS">0</ENTRY>
<ENTRY name="NOOFCANDIDATES">0</ENTRY>
<ENTRY name="NOOFINTERVIEWEES">0</ENTRY>
</ENTRYSET>
….
….
….
(82nd)
<ENTRYSET>
<ENTRY name="HIGHLIGHT">0</ENTRY>
<ENTRY name="JOBOPENINGRECORDNO">3140</ENTRY>
<ENTRY name="JOBTITLE">Execut
Representative./wireline</ENTRY>
<ENTRY name="JOBOPENINGSTATUS">1</ENTRY>
<ENTRY name="JOBOPENINGPOSTDATE">2004-12-
22</ENTRY>
<ENTRY name="NOOFAPPLICANTS">0</ENTRY>
<ENTRY name="NOOFCANDIDATES">0</ENTRY>
<ENTRY name="NOOFINTERVIEWEES">0</ENTRY>
</ENTRYSET>
<ENTRYSET>
<ENTRY name="HIGHLIGHT">0</ENTRY>
<ENTRY name="JOBOPENINGRECORDNO">3141</ENTRY>
<ENTRY name="JOBTITLE"> Execut
Representative./wireline</ENTRY>
<ENTRY name="JOBOPENINGSTATUS">1</ENTRY>
<ENTRY name="JOBOPENINGPOSTDATE">2004-12-
22</ENTRY>
<ENTRY name="NOOFAPPLICANTS">0</ENTRY>
<ENTRY name="NOOFCANDIDATES">0</ENTRY>
<ENTRY name="NOOFINTERVIEWEES">0</ENTRY>
</ENTRYSET>
</MULTIVALUEDCOL> </ROW>
</XMLRESULTSET>

Now when my java application parses the above xml, it
provides truncated result for 82nd record date as 2004-
12 not 2004-12-22 without giving any exception. Also its
parsing the next record correctly that is 83rd date
comes fine as 2004-12-22. I have tried all possible
debugging and procedure to get this sorted out, but
nothing result. Also, I’m reading all entry value in
StringBuffer as I read in other forum threads that its
preferred than normal String object. Following is my
block of code with method: characters().

StringBuffer sbInhalt = null;
String entryVal = “”;

public void startElement(String uri, String localName,
String qName, Attributes attrs) throws
SAXParseException {
sbInhalt = new StringBuffer();
}

public void characters(char[] ch, int start, int length) {

if(name.equalsIgnoreCase("COL")){
colValue = new String(ch,start,length).trim();

}else if(name.equalsIgnoreCase("ENTRY")){
sbInhalt = sbInhalt.append(ch, start, length);
entryValue = sbInhalt.toString();

System.out.println("In Char Start,
Length==>>"+start+", "+length);
System.out.println("EntryVal in
Char==>>"+entryValue);
}
}

public void endElement(String uri, String localName,
String qName)
throws SAXParseException{

System.out.println(“The result Entry in Buff
Format==>>”+ sbInhalt); //This is Printing truncated
82nd Entry
System.out.println(“The result
Entry==>>”+entryVal); //This is Printing truncated 82nd
Entry
entryVal = “”;
sbInhalt = null;
}

Also, I observed that after about every 16384 start
character position, the start value gets resets. And in
this 82nd record the date value returns length as 7 not
10. Is these any way I can control the char[] length
passed in SAXParser? Is there any configuration for SAX
in this effect. I’m completely puzzled with this behavior
of my parser application. Any suggestions and solution
will be highly appreciated.

Discussion


Log in to post a comment.