Parsing and sending XML
In this article, we'll explore ways of parsing and sending XML in UI Bakery. Review the sections below to learn how to do that.
Parsing an XML string to a JS Object
Navigate to the Custom code tab and specify the following script:
<script src="https://cdnjs.cloudflare.com/ajax/libs/fast-xml-parser/4.3.2/fxparser.min.js" ></script>
Create an HTTP Request action selecting the GET method and specifying the necessary URL.
Next, turn on the Transform result toggle to open the mapper field and specify the following code:
const xmlContent = atob({{data.base64}});
const parser = new XMLParser();
return parser.parse(xmlContent);
Click Execute action.
Sending an XML string from UI Bakery
Navigate to the Custom code tab and specify the following scripts:
<script src="https://cdnjs.cloudflare.com/ajax/libs/fast-xml-parser/4.3.2/fxparser.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jstoxml.min.js"></script>
Now, create a new action consisting of two steps:
For the first step, add a JavaScript Code action that will generate an XML from JSON:
const jsonData = await {{actions.requestData.trigger()}}; return jstoxml.toXML(jsonData); //where requestData is an action that returns data to be sent as XML (for example, HTTP Request or Load Table action)
For the second step, add an HTTP Request action that will send the request: — Select POST method and specify the URL — For Headers - specify
Content-Type
application/xml
— For Body -{{data}}
, as the result of the first step
Click Execute action.
Last updated
Was this helpful?