Stuck and totally out of ideas

Hi all,

I have been stuck for a while on something and I feel like it should be simple yet… it’s so not (for me at least). This all started via a shortcut project but I have sense tried to branch out to find a solution and thought I would ask here.

I am attempting to develop a shortcut based database login. I have worked through the connection issues, encoding and such and figured out the commands (it’s ugly but it works). However the API is older and returns results in XML. I am hoping to find a way to fix this via shortcuts but I know JS might be me best option.

The issue I have is when I try to interact with the data it disappears. If I try to convert to text… poof. If I try to add a dictionary… poof. If I try and use rich html it cuts up the response and I loose data (happens other ways too). I have been able to save it out as a txt file and reference it that way but doing that means A LOT of regex and a huge shortcut and it will run like a dog and honestly take ages to build.

I was looking at some html to json shortcuts but they all kick it back saying no valid input (as xml or json). I can get the Jayson app to view them with a few odd steps but no I want to be able to use them not see them :slight_smile:

Hopefully someone here has a good idea.

Data Example

<PersonAttributeListResult xmlns:i=“http://www.w3.org/2001/XMLSchema-instance”><AttributeGroups><AttributeGroup><AttributeGroupID>32</AttributeGroupID><AttributeGroupName>Care</AttributeGroupName><Attributes><PersonAttribute><AttributeID>505</AttributeID><AttributeName>Pastoral Care Notes</AttributeName><DisplayValue>Caring contact to all encouragement group leaders; MS</DisplayValue><StringValue>Caring contact to all encouragement group leaders; MS</StringValue></PersonAttribute><PersonAttribute><AttributeID>507</AttributeID><AttributeName>Care Contact</AttributeName><DateValue>2018-01-09T00:00:00</DateValue><DisplayValue>1/9/2018</DisplayValue></PersonAttribute></Attributes></AttributeGroup></AttributeGroups></PersonAttributeListResult>

Can you edit the post and repaste the data enclosed in triple backticks please? That will make it much easier to read.

```
data here
```

What’s really needed is an action that can parse XML. Sounds like you might want to shell out to eg Scriptable or Pythonista. Former has an XML parser - and you don’t seem to need attribute support so it’s probably good enough.

I’ve put your XML in here to format it: https://www.freeformatter.com/xml-formatter.html but it gave me this error:

Unable to parse any XML input. Error on line 1: Open quote is expected for attribute "xmlns:i" associated with an element type "PersonAttributeListResult".

The problem is that the quotes are not straight quotes " but others. After changing them it have me this:

<?xml version="1.0" encoding="UTF-8"?>
<PersonAttributeListResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance 1">
    <AttributeGroups>
        <AttributeGroup>
            <AttributeGroupID>32</AttributeGroupID>
            <AttributeGroupName>Care</AttributeGroupName>
            <Attributes>
                <PersonAttribute>
                    <AttributeID>505</AttributeID>
                    <AttributeName>Pastoral Care Notes</AttributeName>
                    <DisplayValue>Caring contact to all encouragement group leaders; MS</DisplayValue>
                    <StringValue>Caring contact to all encouragement group leaders; MS</StringValue>
                </PersonAttribute>
                <PersonAttribute>
                    <AttributeID>507</AttributeID>
                    <AttributeName>Care Contact</AttributeName>
                    <DateValue>2018-01-09T00:00:00</DateValue>
                    <DisplayValue>1/9/2018</DisplayValue>
                </PersonAttribute>
            </Attributes>
        </AttributeGroup>
    </AttributeGroups>
</PersonAttributeListResult>

I then tried it with my XML to JSON shortcut, but it just returns null, so I don’t know what is wrong…

A bit of a sledgehammer to crack a nut, but I’ve put together a Shortcuts shortcut that takes the XML and converts it to what looks like a suitable set of JSON that I can then load successfully into Jayson and navigate as verification of its validity.

The shortcut has to do some pre-processing as the way I’m pushing this through means in effect I can’t put an XML document within another, and stripping out the namespace definition. I don’t really have the time right now to fully analyse the cause and resolve it, so It also does some crude post-processing and strips out an “undefined” entry that appears at the end of processing this particular set of XML.

FYI, this is based on Goessner’s XML conversion routine for JavaScript - directory.

Here’s the shortcut. Hopefully it is easy enough to follow the shortcuts steps it utilises.

Hope that helps.

1 Like

Okay so a few updates.

First thank you to everyone who threw out ideas. I was able to figure it all out using a solution similar to the shortcut posted in the last response (I am saving that one for other things so thank you).

The response from here is long so if your just looking for a problem solved update you can stop reading here.

After many hours this week in shortcuts, Xcode, visual studio, regex, Reddit and Google it appears to have been a combination of a old and picky API and a known issue back when shorcuts was workflow.

The API in question was written before JSON was widely in use and it was written… picky with not much in the way of feedback for bad request. So in the end I had to use set name (not the file one I prefer) and set it to text THEN run it through a series of stuff similar to the shortcut posted to brute force it into a JSON style.

One of the API issues is the odd use of mixed quotes hence the time spent in regex. Even though things like make rich text, treat as a file, get text etc… all should have worked they didn’t which also goes back to the old bug I heard about.

So good new is that yes it’s working. I was able to actually parse it inn shortcuts to pull data to make a name plate of sorts via list for multiple returns (that trick only worked once for some reason… the other times it’s more regex lol).

Now I have a different issue all together. I am attempting to figure out the modify and create side of the API now. Supposedly if I want to add or modify something I send it to various endpoints (x/11/x/x) and then pass the values XML style. But the same kind of approach I used for login won’t work. I am getting into the system but I get a error bad end point so gotta figure that one out.

I tried using form encoded, json and file type for post. As well as sending individual keys and files but so far nothing. But that’s a whole other thing so thank you all for your help.

1 Like