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. wen i run i get dis error

jdbc:mysq

View Tutorial          By: sandeep at 2009-11-24 08:24:20

2. GOOD FOR BIGGENERS
View Tutorial          By: naresh at 2012-08-04 11:19:03

3. what's the purpose of indexOf('t',10)
View Tutorial          By: pevi at 2011-02-22 04:23:20

4. haiiiiiiiii sir , i have error in this program, er
View Tutorial          By: Vinod at 2012-07-31 12:23:19

5. through this i understand functional overloading e
View Tutorial          By: mahwash at 2012-09-19 15:29:21

6. When the Value Is Returned To The Method Then How
View Tutorial          By: nitin deep singh at 2011-08-09 11:43:07

7. It's good working very well...............
View Tutorial          By: avinash at 2013-03-07 09:38:21

8. Great!!!!!!!!!!!!!!!!!!!!
View Tutorial          By: Raghbendra Nayak at 2012-03-28 12:54:35

9. Thank you very much..
This helped me a lot

View Tutorial          By: Rabeea AS at 2010-11-15 00:28:29

10. hi can u send me the complete working code for sen
View Tutorial          By: Amit Adhikaree at 2011-03-22 17:47:49