on 02-19-2009 9:49 AM
Hi friends,
I have one txt file which has following data:
:20:2000001305
:32A:001031SAR9101,90
:50: Corporate Name
BOX 12345
Riyadh
Saudi Company XYZ
:52A:SAMBSARI
:53B:/106202529
:57A:AAALSARI
:59:/01313078585009
Corporate Name
BOX 12345
Riyad
Corporate Name
:70:INV/0000000899
Now I want to convert in following form and send to partner :
<?xml version="1.0"?>
<PaymentMessage>
<PaymentTransaction>
<CompanyCode>Corporate code</CompanyCode>
<SequenceNum>0000000000107007</SequenceNum>
<TransactionData>:20:2000001305
:32A:001031SAR9101,90
:50: Corporate Name
BOX 12345
Riyadh
Saudi Company XYZ
:52A:SAMBSARI
:53B:/106202529
:57A:AAALSARI
:59:/01313078585009
Corporate Name
BOX 12345
Riyad
Corporate Name
:70:INV/0000000899
</TransactionData>
<TransactionComment>Testing</TransactionComment>
</PaymentTransaction>
</PaymentMessage>
How can I do using PI?
Hi,
The below is the java code that i have created for building the XML file, similar to your requirement. Follow this as an example and change accodign to your requirement.
public class XMLGenarator {
private String xmlstr = null;
private int fl_doc = 0;
private File fle = null;
private FileReader fr = null;
private FileWriter fw = null;
public int genarateXMLDoc(String docname,String targetname) {
String line_read = null;
String[] str_val = null;
xmlstr = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
xmlstr =
xmlstr + "<ns0:Output_Data xmlns:ns0=\"urn:javamapping_test\">";
File fle = new File(docname);
if (fle.isFile()) {
try {
fr = new FileReader(docname);
fw = new FileWriter(targetname);
PrintWriter pr = new PrintWriter(fw);
pr.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
pr.println("<ns0:Output_Data xmlns:ns0=\"urn:javamapping_test\">");
BufferedReader br = new BufferedReader(fr);
while ((line_read = br.readLine()) != null) {
str_val = line_read.split(",");
// for (int i = 0; i < str_val.length; i++) {
if (str_val[0].equals("1")) {
pr.println("<Data>");
pr.println("<Header>");
pr.println("<Name>" + str_val[1] + "</Name>");
pr.println("<Comapany>" + str_val[2] + "</Company>");
pr.println("<Place>" + str_val[3] + "</Place>");
pr.println("</Header>");
} else if (str_val[0].equals("2")) {
pr.println("<Item>");
pr.println(
"<Designation>"
+ str_val[1]
+ "</Designation>");
pr.println("<Since>" + str_val[2] + "</Since>");
pr.println("</Item>");
pr.println("</Data>");
}
// }
str_val = null;
line_read=null;
}
br.close();
br=null;
pr.println("</ns0:Output_Data>");
pr.close();
pr=null;
} catch (IOException ioe) {
ioe.printStackTrace();
System.out.println("IOException " + ioe.getMessage());
System.out.println("IOException " + ioe.getStackTrace());
}
finally{
try{
fr.close();
fr=null;
fw.close();
fw=null;
}catch(IOException ioe){
ioe.printStackTrace();
}
}
fl_doc = 1;
}
fle=null;
return fl_doc;
}
}
Regards..
Krishna..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
Use File Content Conversion in File Adapter ,it will automatically convert in to xml payload.(Check you text file is inj standard Structure.
or other way is using XSLT Mapping we can acieve easily.
Regards,
Raj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Another option would be use of adapter module to convert this data into xml.
Regards,
Prateek
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi there,
You can also use XSL for this message. Just ensure you enclose the data as a CDATA object.
Greets
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use java Mapping and render your XML required by partner.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.