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. could you send me a code for a music video mobile
View Tutorial          By: Christian at 2009-08-28 23:03:45

2. awesome.........
View Tutorial          By: tar at 2013-03-14 07:36:56

3. can i use comma operator in simbolic constant in c
View Tutorial          By: Madheswaran at 2011-12-05 18:44:22

4. I have use the above code, Am getting the below er
View Tutorial          By: RameshKumar at 2011-07-25 05:02:12

5. What is the difference between an Interface and an
View Tutorial          By: RAJA at 2015-06-26 17:28:31

6. NICE SITE
View Tutorial          By: MAEN ZIAD HUDAIB at 2009-07-01 01:55:28

7. Hi mounika, Did you download and install the javac
View Tutorial          By: Ramlak at 2008-04-27 05:49:42

8. where to copy the file " speech.properties&qu
View Tutorial          By: Mohan at 2012-09-16 01:47:32

9. This was the first clear and straight-forward exam
View Tutorial          By: Steve at 2013-01-02 22:58:32

10. 27: What happens if the producer and the customer
View Tutorial          By: Spender at 2010-07-25 14:42:08