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 is very useful to others............,thanx
View Tutorial          By: jey at 2012-01-06 08:53:22

2. Hi sir just send me the code sir .... i am interes
View Tutorial          By: maruthi at 2013-10-30 05:14:15

3. Hi.
How we can create list with menuitem in

View Tutorial          By: omid at 2008-09-08 02:09:50

4. what is differences between application scope and
View Tutorial          By: suresh at 2013-05-13 13:03:12

5. very bad example.......can v call overrided functi
View Tutorial          By: abdul nasir khayam at 2011-10-27 20:57:00

6. can any beginners can try creating web pages

View Tutorial          By: jo at 2015-07-28 19:35:11

7. good job.. i understand it clearly..
its in

View Tutorial          By: xmplexd at 2010-08-04 02:12:30

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

9. Hi, I need the complete working code for sending a
View Tutorial          By: Balaji Srikaanth at 2007-03-10 01:22:35

10. DO NOT USE QSORT IN A C++ CODE.

If

View Tutorial          By: paercebal at 2008-08-13 05:06:45