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. it's very easy simple progremme in java
View Tutorial          By: sambasiva rao at 2010-09-24 23:53:00

2. "Invalid Password at the jsp bcos RuntimeExce
View Tutorial          By: Ogah I. G at 2013-01-08 16:44:54

3. haii , i am fully happy by searching all component
View Tutorial          By: AJEET KUMAR DALEI at 2011-04-23 21:20:00

4. i want to know how to connect to a remote mysql da
View Tutorial          By: lixiang at 2013-04-23 04:32:58

5. great, thnak you very much !!!!
View Tutorial          By: geek at 2014-05-11 00:10:32

6. hello
i am developing a budget application

View Tutorial          By: anu at 2010-04-16 04:26:36

7. Sir , I am doing B.Tech . I want to know more abou
View Tutorial          By: amita saini at 2011-08-05 13:07:35

8. its really a good post... very informative..
View Tutorial          By: javagava at 2011-12-13 19:49:08

9. Nice example.
I got it finally
Thank

View Tutorial          By: Bo at 2015-05-05 06:28:43

10. For me it is executing without error, But not send
View Tutorial          By: Vijay at 2011-02-19 01:51:08