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. my requirement is i have a source string as src{&q
View Tutorial          By: Anil at 2014-10-27 08:36:23

2. one have to store .wav file in res folder of your
View Tutorial          By: swetha at 2013-06-14 06:47:57

3. this text is overlapping the existing text what if
View Tutorial          By: Alda at 2015-10-02 18:22:22

4. thanks becase i am very confuse what is work how t
View Tutorial          By: arvind at 2011-01-09 14:41:42

5. Thanks ... nice one with clear picture.
View Tutorial          By: Nithin at 2012-04-01 06:58:41

6. oh tnx a lot!i'v been lookin for a code like this!
View Tutorial          By: LES at 2012-01-13 12:55:09

7. Nice Article.
View Tutorial          By: Swathi Kumar at 2012-04-15 10:44:14

8. hi frnds help me please .javamail program not bee
View Tutorial          By: sella at 2011-10-05 18:33:22

9. This is pretty straightforward and got me to under
View Tutorial          By: Renoir Boulanger at 2009-09-01 09:49:24

10. i cannot add attachment
its saying
&

View Tutorial          By: Rintu Das at 2012-05-04 18:07:48