Topics
All
MacOS
(Only)
Windows
(Only)
Linux
(Only, Not)
iOS
(Only, Not)
Components
Crossplatform Mac & Win
Server
Client
Old
Deprecated
Guides
Examples
Videos
New in version:
12.2
12.3
12.4
12.5
13.0
13.1
13.2
13.3
13.4
13.5
Statistic
FMM
Blog
XML.Import
Imports XML and creates tables, fields and records.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
XML | 5.3 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
XML | The XML data to import. | ||
InsertFileName | The file name of where the insert table is inside. | Get(FileName) | Optional |
TableNamePrefix | The prefix to put in front of all tables. | "Import" | Optional |
Flags | Sum of flags. Add 1 to ignore errors in xml and continue parsing. Add 2 to ignore outer XML wrapper nodes. Add 4 to import flat, so no subtables for included nodes. Add 8 to convert CDATA to text nodes. CData should contain ASCII or UTF-8 text! Add 16 to trim values. Add 128 to skip table creation (since v12.3). Add 256 to skip field creation (since v12.3). |
0 | Optional |
Result
Returns number or error.
Description
Imports XML and creates tables, fields and records.This function can import any XML into FileMaker tables with all fields and attributes.
Returns number of records to be added. This function prefers the import and runs it later at idle time. In a script please call XML.Import and then loop and do script pauses. Then use XML.Import.Status to check regularly for updates. When you get back Finished as status, the script can continue with other work.
If you have a XML file you need to import regularly into FileMaker and you have no XSLT to transform it for FileMaker, you can use this plugin function. On the first run, it creates for a sample xml file the required tables and fields. Then you can define any layout or script to process values, e.g. copy into your tables. On further runs the plugin may add more fields (if newer xml file has more fields) and import newer records.
All tables have three default fields. _RecordUUID is a unique identifier for the record. _ParentRecordUUID provides a link to the record one level higher in the XML. This can be used to find child/parent records. The _CreationTimeStamp is the creation date, so you can distinguish different imports.
As a lot of records with a lot of data is imported and you may not need everything, you may want to put the imports in an extra FileMaker file. You decide if you clear tables before import or you want to keep history of all imports.
If the XML has errors like a missing < in the xml, you get an error. If you switch on IgnoreError parameter, the plugin reads everything until the error is reached which may give less records than possible.
This function works at idle time which is not supported on server. But you can use the function XML.Import.Work to perform the work instead of the idle handler. This enables importing of data, but not table/field creation.
Requires FileMaker 12 or newer.
See also XML.Import.SetBaseFields and XML.Import.SetExtraField.
We use SQL to create records, so you can check FM.ExecuteSQL.LastErrorMessage and FM.ExecuteSQL.LastSQL after the import for SQL errors.
Please wait for an import to finish before calling JSON.Import or XML.Import again since it will cancel the last import and start a new one.
Import fails if a table or field name matches a reserved word in FileMaker like RowId. Please rename entries if needed.
Examples
Imports test.xml into FileMaker:
Set Variable [$text; Value:MBS("Text.ReadTextFile"; "/Users/cs/Desktop/test.xml"; "UTF-8")]
Set Variable [$r; Value:MBS("XML.Import"; $text; ""; "")]
Set Variable [$text; Value:""]
If [MBS("IsError") = 0]
Set Variable [$total; Value:MBS("XML.Import.Total")]
Loop
Set Variable [$todo; Value:MBS("XML.Import.Todo")]
Pause/Resume Script [Duration (seconds): 1]
Set Variable [$s; Value:MBS("XML.Import.Status")]
Exit Loop If [$s ≠ "Working"]
End Loop
Show Custom Dialog ["XML Import"; $r & " " & $s]
End If
Import script with progress bar for importing XML with Windows ANSI encoding:
Go to Layout [“XML Import” (Import2Row)]
Delete All Records [No dialog]
Set Variable [$r; Value:MBS("ProgressDialog.SetBottomText"; "")]
Set Variable [$r; Value:MBS("ProgressDialog.SetTopText"; "Importiere XML")]
Set Variable [$r; Value:MBS("ProgressDialog.SetTitle"; "Import...")]
Set Variable [$r; Value:MBS("ProgressDialog.SetButtonCaption"; "Abbrechen")]
Set Variable [$r; Value:MBS("ProgressDialog.SetProgress"; -1)]
Set Variable [$r; Value:MBS("ProgressDialog.Show")]
Pause/Resume Script [Duration (seconds): ,1]
Set Variable [$text; Value:MBS("Text.ReadTextFile"; "/Users/cs/Desktop/test.xml"; "Windows")]
Set Variable [$r; Value:MBS("XML.Import"; $text; ""; "Import2")]
Set Variable [$text; Value:""]
If [MBS("IsError") = 0]
Set Variable [$total; Value:MBS("XML.Import.Total")]
Loop
Set Variable [$todo; Value:MBS("XML.Import.Todo")]
Set Variable [$r; Value:MBS("ProgressDialog.SetProgress"; ($total - $todo) * 100 / $total)]
Set Variable [$r; Value:MBS("ProgressDialog.SetBottomText"; "Schritt " & ($total - $todo) & " von " & $total)]
Pause/Resume Script [Duration (seconds): 1]
Set Variable [$s; Value:MBS("XML.Import.Status")]
Exit Loop If [$s ≠ "Working"]
If [MBS("ProgressDialog.GetCancel") = 1]
Set Variable [$r; Value:MBS("ProgressDialog.Hide")]
Set Variable [$r; Value:MBS("XML.Import.Cancel")]
Exit Script []
End If
End Loop
Set Variable [$r; Value:MBS("ProgressDialog.Hide")]
Show Custom Dialog ["XML Import"; $r & " " & $s]
End If
Set Variable [$r; Value:MBS("ProgressDialog.Hide")]
Read Database Design Report:
#read XML from file in UTF-16
Set Variable [$text; Value:MBS("Text.ReadTextFile"; "/Users/cs/Desktop/test.xml"; "UTF-16")]
# now remove the UTF-16 encoding marker
Set Variable [$text; Value:Substitute($text; "<?xml version=\"1.0\" encoding=\"UTF-16\"?>"; "")]
#read XML from file
Set Variable [$r; Value:MBS("XML.Import"; $text; ""; "Import")]
Explicit import with passing database filename:
MBS("XML.Import"; $text; Get(FileName); "Import")
See also
- ProgressDialog.SetButtonCaption
- ProgressDialog.SetProgress
- ProgressDialog.SetTopText
- ProgressDialog.Show
- XML.Import.SetBaseFields
- XML.Import.SetExtraField
- XML.Import.SetExtraFieldDefinitions
- XML.Import.Todo
- XML.Import.Work
- XML.InsertRecords
Release notes
- Version 13.5
- Added XML.Import.GetExtraFieldDefinitions and XML.Import.SetExtraFieldDefinitions functions to create custom fields.
- Version 12.4
- Added flags for JSON.Import and XML.Import functions to skip table and field creation.
- Improved XML.Import and JSON.Import to better report progress on slow connections.
- Version 11.4
- Fixed an issue with XML.Import not parsing huge XML files with big text nodes correctly.
- Version 11.3
- Changed JSON.Import and XML.Import to be per thread, so they work better on server with multiple parallel scripts.
- Version 9.3
- Version 9.1
- Changed XML.Import to ignore BOM character.
- Version 8.5
- Improved XML.Import to better detect lists of XML nodes.
- Version 7.5
- Fixed problem with XML.Import and CData nodes.
- Version 7.1
- Added flags to XML.Import to trim and convert CData to text.
- Added new flags for XML.Import function for easier import of XML from SOAP Webservices.
- Added XML.Import.SetBaseFields and XML.Import.SetExtraField.
Example Databases
Blog Entries
- MBS Plugin 12.4 for Claris FileMaker
- MBS FileMaker Plugin, version 12.4pr5
- MBS FileMaker Plugin, version 12.4pr2
- The magic of our XML.Import function
- FileMaker 19.2 and the new fmplugin extended privilege
- MBS FileMaker Plugin 7.1 - More than 4400 Functions In One Plugin
- MBS FileMaker Plugin 5.4 for OS X/Windows
- JSON Import for FileMaker
- [ANN] MBS FileMaker Plugin 5.3 for OS X/Windows
- XML Import for FileMaker
FileMaker Magazin
This function checks for a license.
Created 8th September 2015, last changed 18th September 2023
