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



Ask a Question

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. In listing 6.2 I don't see the variable name itsAg
View Tutorial          By: JC at 2013-04-16 01:49:52

2. Unable to connect with https:\\localhost:8443 but
View Tutorial          By: gopala krishna at 2012-04-02 07:17:09

3. thanks a lot it was really helpful...........for d
View Tutorial          By: Joshi Rocky at 2010-01-29 14:13:40

4. hello, that was very useful
but i have a by

View Tutorial          By: echo at 2011-04-05 11:50:41

5. sr
thanks 4 information provided
b

View Tutorial          By: veer kumar at 2012-07-25 18:30:38

6. nice...cleared this example....
View Tutorial          By: Waqas Mughal at 2010-03-13 21:21:46

7. Clear explaination..Thank You Sir...
View Tutorial          By: nishanth at 2014-06-16 08:58:04

8. super......... thanks 4 ur great example...
View Tutorial          By: jithinraj at 2013-03-13 08:34:07

9. Good Tutorial.
Thanks.

View Tutorial          By: Oki Wicaksono at 2012-05-29 04:09:05

10. Great ! done a gud job
View Tutorial          By: Manju at 2012-11-02 06:43:58