XML
Modified on Thu, 30 May at 10:06 AM
The XML app enables you to:
parse an XML formatted text via the XML > Parse XMLmodule and convert it to a bundle to make the data available to other modules
convert a bundle to an XML formatted text via the XML > Create XML module
The XML > Parse XML module parses an XML formatted text and outputs a single bundle containing all the information extracted from the XML.
Data structure | The Data structure describes the structure of the XML to make the output of the module available in the mapping panel for the following modules. If you have a sample of the XML you would like to parse, you can use it to generate the Data structure:
NoteYou may skip the steps 2-5 to supply an empty Data structure. This way the output of the module will not be available in the mapping panel until the module has been executed at least once to process an XML input. |
XML | The XML formatted text you would like to parse. CautionIf you use a formula, make sure its result value type is (or can be automatically coerced to) Text type. If the result value type is Buffer (binary data) then use |
A typical use case is to download an XML file from a URL and parse its content. Here is a step by step guide how to achieve this:
Create a new scenario
Insert HTTP > Get a file module
Open the module's configuration and configure it as follows:
URL
URL of the XML file (e.g.
https://siftrss.com/f/rqLy05ayMBJ
)Close the module's configuration.
Add XML > Parse XML module, connect it after the HTTP > Get a file module and configure it as follows:
Data structure
Click on Add.
Click on Generator
In your web browser, open a new tab/window.
Put the URL you used in the third step in the address bar and fetch the XML file.
Select all the XML text and copy it into the clipboard.
Close the tab/window and get back to your scenario
Paste the copied XML text into the Sample data field.
Click on Save.
Verify that the Data structure has been successfully generated.
Click on Save to save the Data structure.
Note
You may skip the steps 2-9 to supply an empty data structure. This way the output of the module will not be available in the mapping panel until the module has been executed at least once to process an XML input.
XML
Map the
Data
item from the output of the HTTP > Get a file into the field. Use thetoString()
function to convert its value from Buffer (binary data) type to Text type.You may copy and paste the formula's code into the field:
{{toString(1.data)}}
By default, the XML > Parse XML module will put attributes in a special collection _attributes
as a child of the node, that has these attributes. If the node is a text node and it has attributes, then two special properties will be added: _attributes
for attributes and _value
for the text content of the node.
This XML:
<root attr="1"> <node attr="ABC">Hello, World</node>
</root>
will be converted into this bundle:
The XML > Create XML module converts a bundle to an XML formatted text.
Data structure | The Data structure describes the structure of the resulting XML. If you have a sample of the XML you would like to create, you can use it to generate the Data structure:
|
A typical use case is to transform data from a Google spreadsheet into XML. Here is the procedure on how to transform the data to an XML file in ten steps:
Place the Google Sheets > Select rows module in your scenario to fetch the data. Setup the module to retrieve rows from your Google spreadsheet and set the Maximum number of returned rows to a small number, but larger than one for testing purposes (e.g. three). Execute the Google Sheets module (right-click it and choose "Run this module only") and verify the output of the module.
Connect the Array Aggregator module after the Google Sheets module. In the module's setup choose the Google Sheets module in the Source node field. Leave the other fields as they are for the moment.
Connect XML > Create XML module after the Array Aggregator module. The module's setup requires a Data structure that describes the structure of the XML output. Click on Add to open the Data structure setup. The easiest way to create this Data structure is to generate it automatically from an XML sample. Click on Generator and paste your XML sample to the Sample data field:
Click on Save. The specification field in the Data structure setup should now contain the generated structure.
Change the name of your Data structure to something more specific (e.g. "My XML data structure") and click on the Save. If everything goes well, a field corresponding to the root XML element should appear as a mappable field in the XML module's setup.
Click on Map next to the field and map the
Array[]
item outputted from the Array aggregator module to it:Click on OK to close the XML module's setup.
Open the setup of the Array Aggregator module. Change the target structure from Custom to a XML module's field corresponding to the parent XML element. Map items outputted from the Google Sheets module to appropriate fields:
Click on the OK to close the Array Aggregator module's setup.
Run the scenario. If everything goes well, the XML module should output the correct XML file. Open the setup of the Google Sheets module and increase the Maximum number of returned rows number to be larger than the number of rows in your spreadsheet to process all the data. The resulting XML can be then saved to Dropbox, sent as an attachment via email, uploaded via FTP to a server, etc.
If you want to add attributes to a complex node (a node, that will contain other nodes), you have to add a collection with the name _attributes
for this node in your custom Data structure, and this collection will be mapped to node attributes
If you want to add attributes to a text node (example: <node attr="1">abc</node>
), you have to add a collection _attributes
for attributes and a text property _value
for the node value for this node in your custom Data structure.
{ "name": "node", "type": "collection", "spec": [ { "name": "_attributes", "type": "collection" "spec": [ { "name": "attr1", "type": "text" } ] }, { "name": "_value", "type": "text" } ] }
Make sure the Data structure is defined correctly. Alternatively you may use an empty data structure and execute the module at least once to process an XML input.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article