Page 1 of 1

How to parse XML Response from Chili Publish API in Switch Legacy Scripter

Posted: Mon Jul 26, 2021 8:11 pm
by bkromer
Hey folks,

how can I parse the XML from a "theHTTP.getServerResponse()"-string.
Looks like this. So need to enter the "key" element. "<apiKey succeeded="true" key="MYNEWAPIKEY" validTill="2021-07-27 03:56:15Z" superAdmin="false" />"

Is there no parse function like there is one for JSON.parse() ?

Re: How to parse XML Response from Chili Publish API in Switch Legacy Scripter

Posted: Tue Jul 27, 2021 8:31 am
by freddyp
There is not. You have to place the output in a temporary file and then load that:

Code: Select all

var response = new ByteArray( "it is a ByteArray when coming in as an HTTP response");
var tempPath = job.createPathWithName( "response.xml");
File.writeByteArray( tempPath, response);
var xml = new Document( tempPath);
//now xml is an instance of Document
Two questions:
  • Why are not you using the Chili Publish configurators?
  • Why do you do this in legacy scripting?

Re: How to parse XML Response from Chili Publish API in Switch Legacy Scripter

Posted: Tue Jul 27, 2021 8:41 am
by bkromer
I tried this with the Chili Publish Flow Element and action documentCreatePDF.
ATM it's not working. Chili Support works on this ticket.

We haven't updated switch. Because it's risky and we ain't got the time and capacity to fix everything of those old flows.

Thanks Freddy.👍🏻

I will use a Nodejs server from Heroku and parse XML with fast-xml-parser library.