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



Ask a Question

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. Thanks for the article. I finally finish my task a
View Tutorial          By: bali web at 2012-07-10 13:47:49

2. how to connect jdbc in java on mysql
View Tutorial          By: naseem at 2011-10-26 19:26:45

3. How can i add all the values of an multidimensiona
View Tutorial          By: jolly at 2015-04-11 11:54:47

4. plz send inheritance concept,how to use final,thi
View Tutorial          By: sobha at 2010-02-14 08:29:33

5. Unable to connect with https:\\localhost:8443 but
View Tutorial          By: gopala krishna at 2012-04-02 07:17:09

6. hi ,
this is prakash and i want to know how

View Tutorial          By: prakash at 2010-05-24 07:27:46

7. Dude, u xplaining lyk u already telling pros!Pls t
View Tutorial          By: Brianjambo at 2009-04-14 06:32:13

8. Hi divya, You will have to edit the SerialParamete
View Tutorial          By: Ramlak at 2008-04-27 05:54:47

9. I tried the first option i.e for refresh use Forwa
View Tutorial          By: dinesh at 2009-07-31 05:31:23

10. Thanks
View Tutorial          By: PARIKSHIT SHARMA at 2011-12-23 22:33:39