Background
I am writing a xml converter that takes input from textfiles and translates them to xml. In the text file each record is represented by a line and each field is represented with a tab between them. So in the text file two records would look like:
fieldA fieldB fieldC
fieldA fieldB fieldC
Problem
I am loading the text file into a bufferedReader and using the StAX implementation WoodStox to create the XML. I can see that I am getting the correct record data from my getColumnValue method. But for some reason WoodStox is writing the first record over and over, rather than taking the data that is being delivered each time through the while loop. Since I know inputs (from getColumnValue) are coming in correct, I can only conclude that the problem lies with Woodstock but so far I haven't been able to understand why...
Code:
while ((strRead = buffer.readLine()) != null) {
String recordInputs[] = strRead.split("\t");
writer.writeStartElement("Record");
writer.writeStartElement("FIELDA");
writer.writeCharacters(getColumnValue("BSTYPE", tableColumns, recordInputs));
writer.writeEndElement();
writer.writeStartElement("FIELDB");
writer.writeCharacters(getColumnValue("BSDDT", tableColumns, recordInputs));
writer.writeEndElement();
writer.writeStartElement("FIELDC");
writer.writeCharacters(getColumnValue("BSACTIVE", tableColumns, recordInputs));
writer.writeEndElement();
writer.writeEndElement();
}
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
writer.close();
I never found a good answer to why this didn't work but I did manage to fix it.
Non Working:
writer.writeCharacters(getColumnValue("BSTYPE", tableColumns, customer));
Working:
String bsType = getColumnValue("BSTYPE", tableColumns, customer);
writer.writeCharacters(csType);
Like I previously said getColumnValue() returns a string so I have no idea why that change fixes the problem, but it does.