If you have ever tried writing an XSLT to import data into filemaker, you will know that it is not very easy, unless you know XSLT in detail.
Thinking about this, I decided that there had to be a way of getting data out of XML using FileMaker which can also be easily adapted to different XML feeds.
After some head scratching, I came up with a script that can be used to extract data from different XML documents and populate different Tables with minimal changes.
Here are the basics of the method I used.
NB The script is designed to be recursive and expects the field names that are to be set to be the same as the Tag names
First we set some variables.
Set $XML with the XML data.
Set $Data with everything that is within the first Tag.
Set $NewXML with everything after the first Tag
Then we test if $Data contains any Tags.
If it does we call this script but use $Data as the XML.
Else we Dynamically create a $tagname with the Tag name and set it to the data from the Tag.
Next we navigate to the correct layout based on the tag name and create a new record if required i.e. for child records
Set Field by Name [ Get(TableName) & “::” & $tagname ; Evaluate ( “$” & $tagname ) ]
Now we test the $NewXML for more Tags.
If it does we call this script but use $NewXML as the XML.
Else we have finished.
(See below to see how this looks in FileMaker)
This script will extract data from any XML it is given, however you do have to make sure you are on the correct layout before setting data. I have found it is easier to have different versions of this script for each XML feed as it avoids the section that defines the layouts and/or record creation from getting overly complicated.