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. through this i understand functional overloading e
View Tutorial          By: mahwash at 2012-09-19 15:29:21

2. tis s very useful and easy to capture all persons
View Tutorial          By: Divya at 2013-12-19 05:42:32

3. You have mentioned that
to use this program

View Tutorial          By: Naasik at 2012-08-05 00:15:57

4. Hi am saving data in to the internal memory.But ho
View Tutorial          By: harsha at 2012-04-27 07:48:45

5. good
View Tutorial          By: qwerty at 2014-02-14 07:37:08

6. this is the one of the best site to search java pr
View Tutorial          By: gautam gorai at 2009-01-13 06:44:15

7. plz can u give me code for database connectivity f
View Tutorial          By: nilam at 2012-03-15 12:54:07

8. super explination.
View Tutorial          By: nagarjun reddy at 2013-01-19 13:55:16

9. Hi, I implemented those project in my NetBeans, cr
View Tutorial          By: Leshqo at 2008-11-14 07:09:13

10. its amazing for me i learn a lot from it thanks..
View Tutorial          By: sufyan at 2014-10-26 14:39:34