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

Post Reply
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

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

Post 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() ?
Benjamin
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

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

Post 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?
bkromer
Member
Posts: 99
Joined: Thu Jul 11, 2019 10:41 am

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

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