Extracting Data from XML without writing XSLT

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.

XML Parsing Script in FileMaker Pro

XML_Demo.fp7

Simon Ward

Simon has been developing FileMaker databases since the late 90s and joined Linear Blue in 2006. Over this time he has developed database systems for clients in many different industries from Order Processing to Book Publishing. Simon’s BSc in Chemistry from Thames Valley University comes to the fore in his analytical skills and he is certified in FileMaker versions 7 through 12.

More Posts - Website

5 thoughts on “Extracting Data from XML without writing XSLT”

  1. Simon, this is the best use of Set Field By Name I have ever seen!

    To be honest, XSLT has alwas been a reason for me to look at alternatives when I had to import XML. Yes, it’s easy to learn but not easy to remember unless you use it regularly. And since typical XML import/export XSLT is done once and then left untouched for months or years, writing XSLT is really not something you would end up doing regularly as a FileMaker developer.

    So your script alternative is extremely valuable. Thanks for sharing it.

  2. Hi Simon,

    I second Simon (and Kirk).
    I had this on a back burner for some time now.

    We also would very much appreciate a short demo.

    In Kindness

    JM

Leave a Reply