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



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. sooooooooooooooooo gr8 jop!!
View Tutorial          By: monti at 2011-06-14 08:40:55

2. i want to SCJP exam ,tell how to apply for this ex
View Tutorial          By: jasmina at 2013-04-22 11:05:53

3. these above examples of overloading and overriding
View Tutorial          By: janmejay pant at 2011-03-02 22:06:16

4. Hi i am sanjay ,
I got the exact difference

View Tutorial          By: Sanjay Patel at 2012-05-06 11:36:00

5. Thanks for the Topic. But there are many more comp
View Tutorial          By: Uditha Madumal at 2010-09-15 19:39:13

6. Hi Jon,

It really depends on the ap

View Tutorial          By: Hong at 2009-05-04 20:40:28

7. Hi can anyone help me out, i need a full jsp code
View Tutorial          By: thangaraj at 2007-03-20 12:40:05

8. I lit'l modified the above program for main class,
View Tutorial          By: Adil khan at 2013-02-12 06:37:17

9. It work fine with message below 160 chars. How can
View Tutorial          By: Milind at 2011-12-15 06:20:33

10. javax.comm.NoSuchPortException
at javax.co

View Tutorial          By: vijay at 2013-12-03 07:32:38