As @Andremoniy pointed out, if you want to use a String object, it should always be created and the contents will be copied into it.
The only way to speed up your parser is to keep the number of new string objects to a minimum.
I believe that every element of your xml structure contains raw data between the start and end tags.
Therefore, I suggest creating rows only if you are in an element in which data is of interest. Moreover, I would suggest somehow limiting the possible elements. For example, by hierarchical level or parent to reduce the number of rows. But it depends on the xml structure.
protected boolean readChars = false; protected int level = -1; @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { ++level; if (level == 4) { if (qName.equalsIgnoreCase("TextElement")) { readChars = true; } } } @Override public void characters(char ch[], int start, int length) throws SAXException { if (readChars) { String value = String.copyValueOf(ch, start, length); ... readChars = false; } } @Override public void endElement(String uri, String localName, String qName) throws SAXException { --level; }
Alexs
source share