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. can i ask question? on how to make a statement by
View Tutorial          By: alas at 2012-09-27 00:42:08

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

3. Thanks, it solved my problem with "sun.securi
View Tutorial          By: haasdg at 2013-10-29 14:12:51

4. hi, how do i turn it into a gui with swing allowin
View Tutorial          By: psychicjava at 2011-02-06 13:18:08

5. Sir, can you give me an example of Isalnum in java
View Tutorial          By: Angeline at 2011-07-13 06:43:54

6. I know core java jsp and sql. I want to retrieve d
View Tutorial          By: Vinoth at 2011-08-16 07:22:15

7. Hi it is working fine .but when my server we imple
View Tutorial          By: mohan at 2014-11-28 10:57:22

8. very easy to understand ... a quite a good example
View Tutorial          By: Dinesh at 2012-09-22 18:19:45

9. When copying this code into my java IDE, should i
View Tutorial          By: Barabas at 2010-02-11 03:57:09

10. The SAX Parser code has a problem for files of gre
View Tutorial          By: Mark Nelson at 2011-11-14 20:16:41