How to process contents of a file in Shortcuts

I’m trying to process the contents of a file passed in to a Shortcut via the sharesheet. The attached screen shot is the Content Graph as the first step of the Shortcut (ie, the input).

I’m simply trying to get to the info in the “data” object (3rd level of my series of screenshots)

Despite my attempts… can’t figure out how to get to the file contents. Ultimately…trying to get to the XML data to create a dictionary for subsequent processing.

Am I overlooking the action(s) needed to get to the file contents? Thanks, as always, for any tips…

1 Like

Not sure if you meant to include some other screenshots given the reference above, but perhaps you could share a copy of the file being passed in to the shortcut so we could get a better idea about what you are working with?

I am curious to learn how to do what I describe above, but… I’ve since realized the file I’m trying to process is not in a format that I will be able to convert to a dictionary. So… my question is no longer relevant, at least for this use case.

Here is an example file

But, again… I’m on a fools errand in terms of my overall Shortcut idea, so no need to spend time on this one! Scriptable may be a better path for me.

I suspect that the trick you need is to make Shortcuts think the input is actually just a text file like this:

In order to convert the XML to a dictionary, the path of least resistance is to probably convert the XML to JSON and the use a Get Dictionary from Input action on that. Unless you can use an external web service to do that, then a judicious use of find replace (perhaps the odd regular expression to speed things up) would set you up and you would be off.

I think in Scriptable you might get a similar position for needing to transform into JSON, but once you do, Javascript has (somewhat unsurprisingly given its origin) great features for working with JSON.

Whilst Javascript might traditionally be able to work with XML via the Document Object Model, Scriptable doesn’t have that … however, Simon did reference in another thread, something he’s working on that might actually address that sort of thing. Maybe there will be an option that requires less transformation in Scriptable’s future :slight_smile:

Hope that helps.

1 Like

Thanks @sylumer… that was just the action sequence I needed. Always learning!

Now, on to the more challenging work. As always… thanks for your insights and tips. Cheers! — jay