- Create a flat file dictionary with all the different cvs formats you will need.
- Then create a flat file schema for each transaction (referencing the object in the dictionary).
- Create a document definition from the schema
- Take the csv data and send it to pub.flatFile:convertToValues. Send in the appropriate schema into the ffSchema entry on the service input. (You can just copy the schema from the navigator and paste it into the value for ffSchema).
- map ffValues to a document reference list of the document you created in step 3.
I've been working with webMethods for about a year now (wow, 3 years now) and I have found there are lots of items that are hard to figure out via the documentation and very few posts on the web about them. I thought I'd post them here as I find them to help out other people (hopefully).
Tuesday, December 28, 2010
Handling CSV files
We were interfacing to external vendor who had a CSV restful interface. I had built a system for creating and parsing the xml files. Then my co-worker reminded me about the built in flat file handling routines. Duh!
Subscribe to:
Post Comments (Atom)
or
ReplyDelete/*
Developed by Michael a. Robinson - andremichaels@gmail.com
Built using basic Java
*/
String fileName=IDataUtil.getString(pipeline.getCursor(),"File");
String Source=IDataUtil.getString(pipeline.getCursor(),"Source");
String Message_Type=IDataUtil.getString(pipeline.getCursor(),"Message_Type");
StringBuffer xmlstrGlobal = new StringBuffer();
ArrayList fieldNames = new ArrayList();
ArrayList fieldvalues = new ArrayList();
try {
StringBuffer xmlstr = new StringBuffer();
xmlstr.append("");
xmlstr.append(""+fileName+"");
xmlstr.append(""+Message_Type+"");
xmlstr.append(""+Source+"");
xmlstr.append("");
xmlstr.append("");
xmlstr.append("");
xmlstr.append("");
BufferedReader br = new BufferedReader(new FileReader(fileName));
String strLine = null;
StringTokenizer st = null;
int lineNumber = 0, tokenNumber = 0;
fileName = br.readLine();
String[] result = fileName.split(",");
// xmlstr.append(""+result.length+"");
for (int x = 0; x < result.length; x++) {
fieldNames.add(result[x]);
// System.out.print(result[x] +" ");
}
while ((fileName = br.readLine()) != null) {
xmlstr.append("");
result = fileName.split(",");
fieldvalues = new ArrayList();
for (int y = 0; y < result.length; y++) {
//xmlstr.append("");
//xmlstr.append(" "+fieldNames.get(y)+"");
String eval = result[y];
if (eval == null || eval.equalsIgnoreCase("")
|| eval.equalsIgnoreCase(null)) {
fieldvalues.add("***");
} else {
fieldvalues.add(result[y]);
}
xmlstr.append(" <"+fieldNames.get(y).toString().toUpperCase()+">"+fieldvalues.get(y)+"");
//xmlstr.append(" "+fieldvalues.get(y)+"");
//xmlstr.append("");
}
xmlstr.append("");
lineNumber++;
}
xmlstr.append("");
xmlstr.append("");
xmlstr.append("");
xmlstrGlobal.append(xmlstr);
xmlstr=null;
// System.out.println(xmlstr);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
fileName=null;
IDataUtil.put(pipeline.getCursor(),"xmlstr", xmlstrGlobal.toString());
fieldNames = null;
fieldvalues = null;
xmlstrGlobal = null;
We have one requirement of converting dynamic IS document to csv excel file
ReplyDeleteDo you have any idea for the same.
Your assistance would be much appreciated.
Cool and I have a swell supply: How Much House Renovation Cost Philippines house renovation channel
ReplyDelete