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. The code gives the following exception :-
<

View Tutorial          By: swetha at 2009-03-12 07:19:23

2. nice to read thank you for the notes. that helps m
View Tutorial          By: V.Ranjith kumar at 2010-08-12 06:13:03

3. I think u've done well, just that more examples wi
View Tutorial          By: Mac at 2011-01-23 10:22:10

4. the best!! it helps me a lot.....
View Tutorial          By: shin at 2009-02-15 18:12:31

5. tnx.
i have problem why is that to slow???

View Tutorial          By: rozhin at 2015-08-21 07:54:42

6. Good one
View Tutorial          By: Soumya Anoop at 2010-05-13 23:23:44

7. Can anybody tell me how to send and receive SMS us
View Tutorial          By: Bharat Lahori at 2010-02-04 07:14:19

8. excellent notes
View Tutorial          By: jawahar at 2010-08-03 00:23:52

9. @Vaibhavn if you use an IP instead of a host name
View Tutorial          By: RDMA at 2011-01-04 14:30:15

10. using a same name ,return type and parameter type
View Tutorial          By: sam at 2011-06-24 15:13:34