Atom Feed SITE FEED   ADD TO GOOGLE READER

My Bizarre XML Alternative

Originally, the Glazed Lists demo app would parse a file called "issues.xml" each time it was run. I got "issues.xml" by exporting my Issuezilla database from java.net. This worked okay, but the exported XML included everything in the database including attachments. Of course I did not want to include all of this in the download for the demo app.

About six months ago, I exported the xml file from the database and manually removed the attachments with jEdit and grep. This process was labour intensive and yielded only marginal success.

Recently I decided issues.xml file was out-of-date and I needed to bring it up to date. I did not want to fix it manually again.

Conventional thinking would have me create an XSLT transformation or a utility application that took in XML and wrote out trimmed XML. But that strategy is lame.

Instead, I took the parser for the issues.xml file that I already had. This parser read in the issues.xml file to produce an ArrayList of Issue objects. I modified this program so that whenever it modified an Issue object, it System.out.println'd the code that did that:

    public void addFieldAndValue(String currentField, String value) {

if(currentField.equals("issue_id")) {
currentIssue.setId(Integer.valueOf(value));
System.out.println("currentIssue.setId(Integer.valueOf(" + value + "));");
}
...
}


So now my XML parser outputs Java code. I simply compiled this code and now I have a program that produces an ArrayList of issues. But it does no parsing -- it just constructs the issues and returns.

Magic!