XML
The XML app enables you to parse an XML formatted text via the XML > Parse XML module and convert it to a bundle to make the data available to other modules. You can also convert a bundle to an XML formatted text via the XML > Create XML module
Access requirements
You must have the following access to use the functionality in this article:
To find out what plan, license type, or access you have, contact your Workfront administrator.
For information on 蜜豆视频 Workfront Fusion licenses, see 蜜豆视频 Workfront Fusion licenses.
Parse XML
The XML > Parse XML module parses an XML formatted text and outputs a single bundle containing all the information extracted from the XML.
-
Create a new scenario.
-
Insert HTTP > Get a file module
-
Open the module鈥檚 configuration and configure it as follows:
URL: URL of the XML file (e.g.
https://siftrss.com/f/rqLy05ayMBJ
) -
Click OK 鈥媡o save and close the module鈥檚 configuration.
-
Add XML > Parse XML module, connect it after the HTTP > Get a file module and configure it as follows:
table 0-row-2 1-row-2 layout-auto html-authored no-header Data structure - Click the Add button.
- Click the Generator button.
- In your web browser, open a new tab or 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 or window and get back to your scenario.
- Paste the copied XML text into the Sample data field.
- Click Save.
- Verify that the data structure has been successfully generated.
- Click Save to save the data structure.
You can skip steps 2 through 9 to supply an empty data structure. If the data structure is empty, the output of the module is not available in the mapping panel until the module has been executed at least once.
XML Map the
Data
item from the output of the HTTP > Get a file module into the field. Use thetoString()
function to convert its value from the Buffer (binary data) type to Text data type.You may copy and paste the formula's code into the field:
{{toString(1.data)}}
For more information the Buffer and Text data types, see Item data types in 蜜豆视频 Workfront Fusion.
Parsing XML attributes
By default, the XML > Parse XML module puts 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 are added: _attributes
for attributes and _value
for the text content of the node.
<root attr="1">
<node attr="ABC">Hello, World</node>
</root>
is converted into this bundle:
Create XML
The XML > Create XML module converts a bundle to an XML formatted text.
-
Place the Google Sheets > Select rows module in your scenario to fetch the data. Set up the module to retrieve rows from your Google spreadsheet. Set the鈥 Maximum number of returned rows to a small number, but larger than one for testing purposes (Example, three). Execute the Google Sheets module by right-clicking it and choosing 鈥Run this module only.鈥 Verify the output of the module.
-
Connect the Array Aggregator module after the Google Sheets module. In the module鈥檚 setup choose the Google Sheets module in the Source node field. Leave the other fields as they are for the moment.
-
Connect the XML > Create XML module after the Array Aggregator module.
The module鈥檚 setup requires a data structure that describes the structure of the XML output. Click the Add button to open the data structure setup. The easiest way to create this data structure is to generate it automatically from an XML sample.
-
Click the Generator button and paste your XML sample to the Sample data field:
-
Click Save. The Specification field in the Data structure now contains the generated structure.
-
Change the name of your Data structure to something more specific and click Save. A field corresponding to the root array attribute appears as a mappable field in the JSON module鈥檚 setup.
-
Click the Map button next to the field and map the
Array[]
item from the Array aggregator output to it: -
Click OK to close the XML module鈥檚 setup.
-
Open the setup of the Array Aggregator module. Change the Target structure from Custom to an XML module鈥檚 field corresponding to the parent XML element.Map items from the Google Sheets module to the appropriate fields.
-
Click OK to close the Array Aggregator module鈥檚 setup.
-
Run the scenario.
The XML module outputs 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 saved to Dropbox, sent as an attachment via email, uploaded via FTP to a server, and so on.
Adding XML attributes
If you want to add attributes to a complex node (a node that will contain other nodes), you must add a collection with the name _attributes
for the complex note in your custom data structure. This collection will be mapped to node attributes. If you want to add attributes to a text node (for example: <node attr="1">abc</node>
), you must 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"
}
]
}
Troubleshooting: Cannot map data from the Parse XML module
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.