Clean up filenames from XML

Post Reply
Posts: 43
Joined: Fri Feb 24, 2017 12:25 am

Clean up filenames from XML

Post by cwswitch » Fri Sep 01, 2017 4:33 am

An XML is sent to Switch, and that is the first point that I have any control over what is sent. There's no ability (or interest) upstream to help me here.

As the information is in the XML, and XML can't have certain characters in it, then I have trouble injecting jobs.

Example filename in the XML

Code: Select all


Related file on the file server that I need to inject

Code: Select all


I'm looking to pull the XML path into private data, clean it up, then call Inject using the clean name. It is not just &, it is any symbol that can't be rendered in XML in plain text.

I've gone several ways and fallen every time. I'm sure others must have come across this issue but I've not found anything on line.

Any help greatly appreciated.

Posts: 125
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Clean up filenames from XML

Post by jan_suhr » Fri Sep 01, 2017 8:38 am

The XML pickup tool will handle the & and translate it to the proper baz&bazz.pdf filename. As long as the XML is valid it will work in Switch. The inject tool will pickup your file.
Screen Shot 2017-09-01 at 08.36.58.png
Screen Shot 2017-09-01 at 08.36.58.png (43.92 KiB) Viewed 853 times

Jan Suhr
Color Consult AB
Check out my apps

Posts: 72
Joined: Tue Feb 12, 2013 8:42 pm

Re: Clean up filenames from XML

Post by cstevens » Fri Sep 01, 2017 9:33 pm

You could open it as a standard file and do a simple string.replace(/&/g, '&'), then save the file and send it to an XML pickup for further processing. I did something similar for corrupted csv files.

Posts: 3
Joined: Mon Apr 17, 2017 3:45 pm

Re: Clean up filenames from XML

Post by Shawn_Anderson » Wed Sep 13, 2017 5:24 pm

I had to use Switch to help pass XML from one workflow to another and ran into the same issue. One way of doing this is to use Execute Command with sed. This should comment out any ampersands in the incoming XML, but you can edit the sed command for any other chars you want to replace.

Command: path/to/bash/script/

Arguments: "%1" "%2"
Output: File at Path

content of script

sed "s/\&/\&/g" "${1}" >> "${2}"

Post Reply