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. super excellent
View Tutorial          By: mani at 2013-05-27 05:32:06

2. i avinash can i know how ur problem is resolved ,i
View Tutorial          By: santosh at 2011-12-06 10:35:42

3. i want to learn j2me basic to ....
View Tutorial          By: gopiraj at 2012-12-21 11:52:01

4. Excellent Article.
View Tutorial          By: Praveen Kumar S at 2011-03-24 23:14:44

5. dis prgrm is not giving me any ouput..i need to re
View Tutorial          By: singh at 2015-02-19 12:16:31

6. Hello friends can anybody tell me how to assign in
View Tutorial          By: gnvkdramesh at 2010-09-10 04:27:46

7. This Example program is very useful.
good w

View Tutorial          By: sathya at 2008-03-28 02:21:41

8. hi sir
im a student of aitm im doing speec

View Tutorial          By: sinan ahmed at 2015-02-09 05:45:49

9. it s good ,understanding clearly and with out conf
View Tutorial          By: vasudeva kumar at 2012-01-06 14:04:30

10. can u access by a tutorial by using java script
View Tutorial          By: Benjtaz at 2011-07-11 06:22:16