Here is my situation: I currently get a very large xml file each month that contains data that I need to parse and load into a database. I just finished a very complex system to handle the data in this file, however I've run into a problem.
The problem is that I'm forced to open the file twice. There is a date in the header of the file that I need to grab and look at before I know if I want to parse the file. Currently, I'm using Dom4j to parse the file. I'm setting a callback handler to trigger when it finds my date node. What I'd like to be able to do is stop the parser once I find the date node. Currently, I've got this code:
public void handleEffectiveDate() {
reader.addHandler("/Package/PackageHeader/AsOfDate",
new ElementHandler(){
public void onStart(ElementPath path){}
public void onEnd(ElementPath path){
Element asOfDate = path.getCurrent();
String[] date = asOfDate.getStringValue().split("-");
((DataWarehouse32Assembler)getBatchUploadProcesser().getAssembler()).setUploadEffectiveDate(Integer.parseInt(date[0]), Integer.parseInt(date[1]), Integer.parseInt(date[2]));
System.out.println("Data Effective Date saved in assembler!");
//there can be only one, like the highlander, so once you find it stop looking
reader.removeHandler("/Package/PackageHeader/AsOfDate");
asOfDate.detach();
}
}
);
}
I was hoping that by removing the only handler the parser would stop, however it very obviously does not.
Any recommendations?