i am trying to parse an xml document, after searching i found out that sax is the best choice, but the document is very large (1.5 GB) waited like 7 minutes but its still running my question is, is that normal ? or i can do better ?
public static void main(String argv[]) {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser saxParser = factory.newSAXParser();
DefaultHandler handler = new DefaultHandler() {
int c = 0;
boolean id = false;
boolean value = false;
boolean orgin = false;
boolean note = false;
@Override
public void startElement(String uri, String localName, String eName,
Attributes attributes) throws SAXException {
if (eName.equalsIgnoreCase("ID")) {
id = true;
}
if (eName.equalsIgnoreCase("VALUE")) {
value = true;
}
if (eName.equalsIgnoreCase("ORGIN")) {
orgin = true;
}
if (eName.equalsIgnoreCase("NOTE")) {
note = true;
}
}
@Override
public void endElement(String uri, String localName,
String eName) throws SAXException {
}
@Override
public void characters(char ch[], int start, int length) throws SAXException {
if (id) {
System.out.println(new String(ch, start, length));
id = false;
System.out.println("record num : "+c++);
}
if (value) {
System.out.println(new String(ch, start, length));
value = false;
}
if (orgin) {
System.out.println(new String(ch, start, length));
orgin = false;
}
if (note) {
System.out.println(new String(ch, start, length));
note = false;
}
}
};
saxParser.parse("./transactions.xml", handler);
} catch (Exception e) {
e.printStackTrace();
}
}