EasyCatalog has the ability convert XML tags to EasyCatalog tags via a simple LUA script that maps tag attributes to the elements of a link (key, data source, field name).
The .lua script should be placed inside a folder called “Adopt Fields” in the “Scripts” folder of a data source. The file name of the script must contain “XML” – for example, ‘Adopt XML.lua’ – to differentiate this as an XML adoption (rather than an EasyCatalog link > EasyCatalog link adoption).
When correctly installed, the script name shows up on the “Adopt Fields->” sub menu. When actioned, all the XML tags in the document are processed. For each XML tag and attribute encountered, the LUA script will be passed a variable called ‘tagname’ which contains the name of the XML tag being processed. Each of the attributes on the XML node will be passed trough as separate variables so, for example when the following XML tag is encountered…
1 | <field id="12345" name="price"> |
… the LUA script will be called with the following variables:
1 2 3 | tagname = "field" id = "12345" name = "price" |
The script should set up to three strings, which instruct EasyCatalog which record in the panel to link the XML tag to:
- key – Key field value.
- datasource – Data source name (optional, will already be set to the name of the data source you’re adopting to).
- field – Name of a field.
Using the XML node above, the following LUA script will map the ‘id’ attribute to be EasyCatalog’s key field value and the ‘name’ attribute to be the field name in the panel:
1 2 | key=id field=name |