The last days I chatted with a FileMaker developer who had a need for some XML handling functions. So I added a few functions, first one to extract node names from an XML: XML.NodeNames. You pass in a XML and it can give you the list of node names in the first layer or if you want recursively all layers.
Next we got a function to get a subtree (XML.SubTree). So you may have a big XML with a smaller chunks and we can query nodes inside a bigger tree. This includes getting the nth entry like the nth record in a list of records.
The XML.ExtractText extracts the text inside an XML tree. So all text portions are returned as a list. You can first use the subtree function to get a part of a XML to only get a portion of the texts.
We got a few functions to handle attributes. XML.GetAttribute returns the value for the attribute.
Now we got something special for FileMaker Scripts.
We parse an XML with the XML.SetVariables function, identify all nodes with text values and create variables for you automatically. The plugin sets those variables and returns a list of the names. Later you can pass the list to XML.ClearVariables to clear them for another run.
For example the script looks like this:
Set Variable [$XMLVariables; Value:MBS( "XML.SetVariables"; test::input; 1)]
Set Variable [$otherVariable; Value:1]
#See Variables in Data Viewer
Set Field [test::output; MBS( "XML.ClearVariables"; $XMLVariables)]
Set Variable [$someVariable; Value:1]
The test XML:
<?xml version="1.0" encoding="UTF-8"?>And in the debugger all the variables may look like this for a test XML:
<Comment>Just a test.</Comment>
So you can have an input XML, split the values into variables using our plugin and process them in your script. I hope this is handy for you. What do you think?
Plugin will be available soon. If you like to test today, you can email me.