Comment on Tutorial - XML and Java - Parsing XML using Java Tutorial By totheriver.com



Comment Added by : Mark Nelson

Comment Added at : 2011-11-14 20:16:41

Comment on Tutorial : XML and Java - Parsing XML using Java Tutorial By totheriver.com
The SAX Parser code has a problem for files of greater than 2048 bytes. The SAX Parser only reads in 2048 bytes at a time which could lead to an error if the 2048-byte sections split your element's data. The solution I found is to create your tempVal String (or StringBuffer in my case) in your startElement method call and then add to it in the characters method call.

public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
//reset
tempVal = new StringBuffer();
if(qName.equalsIgnoreCase("Employee")) {
//create a new instance of employee
tempEmp = new Employee();
tempEmp.setType(attributes.getValue("type"));
}
}


public void characters(char[] ch, int start, int length) throws SAXException {
tempVal.append(new String(ch, start, length));
}


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. hi,.. i have used this code to sending sms. It see
View Tutorial          By: dana at 2008-08-05 03:38:48

2. sir, thanks sir. very help to me. its simple and e
View Tutorial          By: kannathasan.M at 2012-10-01 07:59:28

3. this tutorial is awesome.. solved my doubt in seco
View Tutorial          By: Natasha at 2015-07-29 09:03:42

4. Hi Guys, thanks for sharing this... I have some mo
View Tutorial          By: Fins at 2011-12-14 04:40:09

5. Nice Work... Keep it..
View Tutorial          By: Ashok at 2010-02-28 05:12:31

6. me too got the same problem....
but m sure

View Tutorial          By: HEHE at 2008-11-19 01:49:04

7. Hi..thx for the hadoop info..i m learning hadoop..
View Tutorial          By: Kirti at 2015-10-26 11:42:02

8. can anyone explain the output of this recursive ex
View Tutorial          By: vipul at 2012-08-12 19:41:19

9. very nice keep sharing thanks a lot
View Tutorial          By: Adeel at 2014-09-24 09:50:00

10. hi! im new in j2me applications so i just cleaned
View Tutorial          By: resego at 2010-08-04 07:29:29