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. Very good explanation along with the example. Can
View Tutorial          By: Divya at 2010-09-21 03:05:10

2. where do i download the DOM and SAX jar?
View Tutorial          By: David at 2011-11-11 03:04:11

3. Wow thx, this is really easy for me to understand
View Tutorial          By: brian at 2010-03-22 05:15:47

4. respected Sir , I am doing B.Tech . I want to know
View Tutorial          By: naveen juneja at 2011-09-18 07:58:04

5. Thanks.. really helpful:)
View Tutorial          By: Dolly at 2012-07-09 14:24:30

6. hello Ramlak I am getting Error Time Out At Step 6
View Tutorial          By: hardik at 2011-04-13 05:12:06

7. Hello Nishi,
The class names in your progra

View Tutorial          By: Kiran at 2011-12-16 06:32:54

8. I had downloaded all 5 the file
but i need

View Tutorial          By: Dhananjay at 2009-12-09 10:20:30

9. Cordial saludo, muchas gracias por ola ayuda pero
View Tutorial          By: Hernan Camilo Martínez at 2014-04-09 20:08:17

10. what are the required equipments to run j2me
View Tutorial          By: messi at 2012-11-13 13:15:18