Clean up filenames from XML

Post Reply
cwswitch
Member
Posts: 78
Joined: Fri Feb 24, 2017 12:25 am

Clean up filenames from XML

Post 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.
jan_suhr
Advanced member
Posts: 586
Joined: Fri Nov 04, 2011 1:12 pm
Location: Nyköping, Sweden

Re: Clean up filenames from XML

Post 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 8803 times

Jan
Jan Suhr
Color Consult AB
Sweden
=============
Check out my apps
cstevens
Member
Posts: 103
Joined: Tue Feb 12, 2013 8:42 pm

Re: Clean up filenames from XML

Post 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.
Shawn_Anderson
Newbie
Posts: 8
Joined: Mon Apr 17, 2017 3:45 pm

Re: Clean up filenames from XML

Post 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}"
taylorgodiva28
Newbie
Posts: 1
Joined: Fri Jun 16, 2023 4:37 am

Re: Clean up filenames from XML

Post 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
Post Reply