DefaultHandler characters() method behavior



I have just read that characters(char[] ch, int start, int length) can get called multiple times for one inner XML data (e.g. <name>John Smith</name>).


In my project I have to parse big XML file (1.5 GB) and put it in the database, so I cant just manually go through the database and the file to see if everything is OK. So my question is is it safe to do something like this:



public void characters(char[] ch, int start, int length) throws SAXException {
dataForDatabase = new String(ch,start,length);
}


Where dataForDatabase is this parser's class member.


and after that in endElement...



public void endElement(String uri, String localName, String qname) throws SAXException {
putDataToDatabase(dataForDatabase);
}


Won't dataForDatabase get overridden if characters() method gets called multiple times?


Thanks in advance!


No comments:

Post a Comment