Page 1 of 1

Clean up filenames from XML

Posted: Fri Sep 01, 2017 4:33 am
by cwswitch
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

foo/bar/baz&bazz.pdf


Related file on the file server that I need to inject

Code: Select all

foo/bar/baz&bazz.pdf


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.

Re: Clean up filenames from XML

Posted: Fri Sep 01, 2017 8:38 am
by jan_suhr
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 9468 times

Jan

Re: Clean up filenames from XML

Posted: Fri Sep 01, 2017 9:33 pm
by cstevens
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.

Re: Clean up filenames from XML

Posted: Wed Sep 13, 2017 5:24 pm
by Shawn_Anderson
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/cleanupXML.sh

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

-----
content of cleanupXML.sh script

#!/bin/bash
sed "s/\&/\&/g" "${1}" >> "${2}"

Re: Clean up filenames from XML

Posted: Mon Jun 19, 2023 3:06 am
by taylorgodiva28
you can use ELEMENTS statements to replace <row> clauses with each row. Previously, we didn't specify the ELEMENTS directive, so it returned the default value.
Geometry Dash Scratch