Hi:
Please help me to convert text file to xml using Switch Scripter:
Job1.txt input:
500 LABEL
500
1 1.72 500
1 1.72
21 01 04 HARDING'S SERVICES
Shipped Via :
Purolator Edmonton
Tracking # :
607431612227
PO # : 9197
L 1612296
Job1.xml output:
<tags>
<ShippedVia>Purolator Edmonton</ShippedVia>
<TrackingID>607431612227</TrackingID>
<PO>PO # : 9197</PO>
</tags>
Thanks
Text to XML using Node.js in Switch Scripter
Re: Text to XML using Node.js in Switch Scripter
Hi,
has your inputfile always the same structure?
has your inputfile always the same structure?
Re: Text to XML using Node.js in Switch Scripter
Hi,
I need in short a similar Script and I have to learn more TypeScript. So I think this is rudimentary, but it did what you need
I need in short a similar Script and I have to learn more TypeScript. So I think this is rudimentary, but it did what you need
Code: Select all
import fs from "fs";
async function jobArrived(s: Switch, flowElement: FlowElement, job: Job) {
let dateiname = await job.getName();
let dateipfad = await job.get(AccessLevel.ReadOnly);
let tempfile = "/tmp/tmp.xml"; // you can read the inputfile and put it here
// read the file
try {
var array = fs.readFileSync(dateipfad, { encoding: "utf8" }).toString().split("\n");
} catch(error) {
await job.log(LogLevel.Error, "We could'nt read the File " + dateiname);
}
// we know how much ARRAYs are here, because the Textfile has always the same lines
fs.writeFileSync(tempfile, '<tags>\n');
fs.appendFileSync(tempfile, '<ShippedVia>' + array[6] + '</ShippedVia>\n')
fs.appendFileSync(tempfile, '<TrackingID>' + array[8] + '</TrackingID>\n')
fs.appendFileSync(tempfile, '<PO>' + array[9] + '</PO>\n')
fs.appendFileSync(tempfile, '</tags>')
// we don't need the old txt-file
await job.sendToNull();
// we create an other job
const xmljob = await job.createChild(tempfile);
//send to outfolder
await xmljob.sendToSingle();
// delete tmpfile
fs.unlinkSync(tempfile);
}
Re: Text to XML using Node.js in Switch Scripter
Hi:
Yes. The input file has always the same structure. I tried the script in SwitchScripter but it returns error. Please see the screenshot.
https://ibb.co/zhRwnkw
Yes. The input file has always the same structure. I tried the script in SwitchScripter but it returns error. Please see the screenshot.
https://ibb.co/zhRwnkw
Re: Text to XML using Node.js in Switch Scripter
Hi,
yes, because you use legacy Script and not TypeScript.
Greetings
Michael
yes, because you use legacy Script and not TypeScript.
Greetings
Michael
-
- Newbie
- Posts: 5
- Joined: Wed Mar 31, 2021 6:33 am
Re: Text to XML using Node.js in Switch Scripter
Hello,
We have built custom solutions for customers that do similar operations.
If you would be interested in having some help, send me a private message.
Looking forward to hearing from you.
Ryan
We have built custom solutions for customers that do similar operations.
If you would be interested in having some help, send me a private message.
Looking forward to hearing from you.
Ryan