Plugging Into XML: Facilitating Plug-in Registration with XML
by Beverly Voth <bvoth@moonbow.com>

RATING: Intermediate
VERSION: FileMaker 5
PLATFORM: Macintosh & Windows
TECHNIQUE FILE: Plugin.XML.FP5

FileMaker, Inc. provides a registry for plug-in developers on its website <http://www.filemaker.com/products/new_plugins.html>. When a new plug-in is released, developers fill out an online form and the plug-in information is listed in the registry. In addition, developers can list their plug-ins or new version releases on ISO FMPlugins.com <http://www.fmplugins.com>, the DIGFM site <http://www.digfm.org> and send announcements to listservs and newswires.

This leads to multiple submissions via browser and email, which often request different information or even similar information - but with dissimilar input field names. Bottom line: Each field must be entered separately for each plug-in on each website making registering and announcing a plug-in time consuming work.

Recently, the idea to institute a "one-form" system lead to the development of an XML-based plug-in registry to save plug-in developers the time of having to re-enter registration data to various plug-in sites. This article presents the XML-based "one form" and how it was developed.

Enter XML

XML is a method of formatting data to make it easier to transmit between diverse Operating Systems and applications. It's text based and contains tags similar to HTML - the tags used to format pages viewed by web browsers):

<fieldName>field data contents</fieldName>

To be "well-formed" XML, the tags are paired with an opening and closing tag. The only difference is the slash "/" in the ending tag. This makes it very easy to distinguish the contents between the pairs. This also makes it easy to use FileMaker Pro's text calculations to extract the actual data.

The markup language is "extensible" because there are no required tags. You can create your own tags as long as you remember to make them well-formed. In contrast, HTML contains precise tags that format the look of the output. Essentially, XML is the data surrounded by a definition of the type of data.

Using the XML data in a web page, requires an additional format page with XSL (eXtensible Stylesheet Language) or CSS (Cascading StyleSheets) or JavaScript with HTML to present the look of the data on the page and placement of the XML fields' contents. Usage of XML for our purposes is to just pass the data between files (whether web-based submission or import) - not viewing by browser.

Output XML From FileMaker Pro 5

You could create XML formatted text by using calculations and exporting these calculated fields, but you'd need to know all the fields:

Set Field [ xml, "<fieldName1>" & fieldName1 & "</fieldName1>" ]
Set Field [ xml, xml &"?<fieldName2>" & fieldName2 & "</fieldName2>" ]

There is an easier way! The Web Companion Plug-in with FileMaker Pro 5 will create the XML for you. Currently, only Internet Explorer version 5 or greater will display this XML. You'll also need to have Web Companion enabled and the database shared for Web Companion.

http://127.0.0.1/fmpro?-db=pluginreg.fp5&-lay=web&-format=-dso_xml&-findall

The above link means:

"127.0.0.1" is the loop-back default IP address (if you are testing this with your computer serving and viewing the pages at the same time). If you have the file hosted on a server, substitute your IP address or domain path. Depending on your configuration of Web Companion, you may need to include the port number (127.0.0.1:591).

"fmpro?" is the call to Web Companion to begin the action on the rest of the link.

"-db=" and the name of the database that is shared for the web and containing the data you want to view.

"-lay=" and the name of the layout with the fields you want to view.

"-format=" is the tag to display a page in your browser.

"-dso_xml" is the special format page to display the data in XML format. DSO stands for Data Source Object (which can be used to bind XML to HTML) and is one of three formats for XML output with Web Companion. It's the FMPDSORESULT grammar showing the fieldnames and data of the found set.

"-findall" is the action telling the database to find all the records and display them.

sample output:

<?xml version="1.0" encoding="UTF-8" ?>
<FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">
<ERRORCODE>0</ERRORCODE>
<DATABASE>pluginreg.fp5</DATABASE>
<LAYOUT>web</LAYOUT>
<ROW MODID="2" RECORDID="32880">
<DevCompany>Troi Automatisering</DevCompany>
<primary_use />
<cRequired>Required</cRequired>
<PlugInDescription>adds powerful File Manipulation functions to FMP4: * save the field contents to a file * read from a file into a field * create and delete files* creating folders * rename, copy or move files * and more...</PlugInDescription>
<SupportContact>Peter Baanen</SupportContact>
<SupportContactEmail>peter@troi.nl</SupportContactEmail>
<Category />
<WebSiteURL>http://www.troi.com/</WebSiteURL>
<PlugInName>Troi File Plug-in</PlugInName>
<PlugInVersion />
<compatible>Yes</compatible>
<PluginSiteURL>http://www.troi.com/software/fileplugin.html</PluginSiteURL>
<platform>Both</platform>
</ROW>
</FMPDSORESULT>

Note the tags that are NOT paired, "<Category />" for example. This is an empty value and also well-formed according to XML rules. As long as this kind of tag ends with "/>" it is considered "legal." Keep in mind that this type of tag is much harder to parse (get the value of the contents), but since it's empty our calculations can ignore it for this example.

Since Web Companion creates the XML quite easily, the plug-in developers can view a page in the browser, copy the output and paste into a text file or simply save as Text. Using this XML formatted text, the information can be sent to several sources for import and parsing.

XML Import into the Database

If the XML text is pasted into a single field on a web page and submitted, it's possible to populate the remaining fields in the receiving database. FileMaker Pro does not have an import for the XML text, nor does it translate XML formatted text. But the simple example of "<tag>-data-</tag>" can be parsed using FileMaker Pro's functions Middle(), Position() and Length().

Script: Parse XML
Set Field [ DevCompany , Case(PatternCount(xml, "<DevCompany>"),
Middle(
xml,
Position(xml, "<DevCompany>", 1, 1) + Length("<DevCompany>"),
Position(xml, "</DevCompany>", 1, 1) - Position(xml, "<DevCompany>", 1, 1) - Length("<DevCompany>")
),
"") ]
Set Field [ SupportContact , Case(PatternCount(xml, "<SupportContact>"),
Middle(
xml,
Position(xml, "<SupportContact>", 1, 1) + Length("<SupportContact>"),
Position(xml, "</SupportContact>", 1, 1) - Position(xml, "<SupportContact>", 1, 1) - Length("<SupportContact>")
),
"") ]
Set Field [ SupportContactEmail , Case(PatternCount(xml, "<SupportContactEmail>"),
Middle(
xml,
Position(xml, "<SupportContactEmail>", 1, 1) + Length("<SupportContactEmail>"),
Position(xml, "</SupportContactEmail>", 1, 1) - Position(xml, "<SupportContactEmail
", 1, 1) - Length("<SupportContactEmail>")
),
"") ]
Set Field [ WebSiteURL , Case(PatternCount(xml, "<WebSiteURL>"),
Middle(
xml,
Position(xml, "<WebSiteURL>", 1, 1) + Length("<WebSiteURL>"),
Position(xml, "</WebSiteURL>", 1, 1) - Position(xml, "<WebSiteURL>", 1, 1) - Length("<WebSiteURL>")
),
"") ]
Set Field [ PlugInName , Case(PatternCount(xml, "<PlugInName>"),
Middle(
xml,
Position(xml, "<PlugInName>", 1, 1) + Length("<PlugInName>"),
Position(xml, "</PlugInName>", 1, 1) - Position(xml, "<PlugInName>", 1, 1) - Length("<PlugInName>")
),
"") ]

Position(field, text, start, occurrence) is the function that will find text in a field from a starting character at a particular occurrence. We're using the position of a start tag in our field and adding the length of that tag (in characters), so that we may actually extract just the data. We also use the position of the end tag and subtracted the start tag position (and length) to know how many characters are in the data: Middle(field, start, how many characters).

The order of the parsing script steps or of the fields in the database doesn't matter. PatternCount() function is used to verify that the field/tag exists in the XML text. This database happens to have fields named the same as the XML tags. Because this script uses Set Field [] you need not have the same names in two different sources, just a "map" of what the fields are.

The DIGFM database uses the field "link" instead of "WebSiteURL" so the script would contain:

Set Field [ link , Case(PatternCount(xml, "<WebSiteURL>"),
Middle(
xml,
Position(xml, "<WebSiteURL>", 1, 1) + Length("<WebSiteURL>"),
Position(xml, "</WebSiteURL>", 1, 1) - Position(xml, "<WebSiteURL>", 1, 1) - Length("<WebSiteURL>")
),
"") ]

Parsing for Multiple Records or Related Data

The above XML output happens to contain ONE record from one flat-file database. Do you see the <ROW MODID= RECORDID=>...</ROW> tags? If the output had found more than one record, this would be repeated in the XML text. See the Bonus file and create the XML for all records. You could create a loop script to search for each set of records (rows) and parse into separate records. You will need to test for the occurrence of these tags and create a new record (or find a particular record) to parse each row into a single record.

If you have related files for your data, parsing is more complex, but possible. Set Field [] could also populate these fields, if you have a proper relationship. This example places data into a single related field.

Set Field [ Developer::DevCompany , Case(PatternCount(xml, "<DevCompany>"),
Middle(
xml,
Position(xml, "<DevCompany>", 1, 1) + Length("<DevCompany>"),
Position(xml, "</DevCompany>", 1, 1) - Position(xml, "<DevCompany>", 1, 1) - Length("<DevCompany>")
),
"") ]

XML data will show the relationship and its field like this: "Relationship.field" Note the "." separating them. Keep this in mind when you are reading in the data and place the contents into the proper field(s).

Summary

You'll find the Technique file - PluginXML.FP5 - with the necessary URLs to send XML data to a browser to show you all three formats for all records or just the current record. The "Parse XML" script uses text functions to populate the fields for XML "import." You can paste the XML or use a plug-in to read the XML in. Remember to check for data over 64,000 characters, as the field size cannot exceed this.

While FileMaker Pro doesn't have an automatic import of XML text, it can easily calculate the data between the tags and place it into proper fields. You need not have the correct field names, but know which tags in the XML equate to your fields like a "map." This could save you from changing field names in existing databases!

All the fields do not have to exist in a database to use the XML input text. You can extract only the fields and data you want from an XML text file. Any unused data is still text and if you save the XML record in a field, you could search on that field, too. Perhaps you will use a Plug-in to read an XML-formatted file and parse it into the correct fields.

Other databases or applications may be able to use the XML data from your files. This increases the flow of information and enhances the communication between disparate sources. Using XML output (and subsequent parsing) will make it easier for the plug-in developers to register on multiple sites. You can use the same techniques for exchanging XML data.

    Author's note: Special thanks to Peter Baanen <peter@troi.com> for this idea and for learning about XML. To Tim Woodruff <tim@isoproductions.com> for working with me on getting the fmplugin site XML-ready. To Rick Kalman at FileMaker, Inc. for helping me get the Plug-in registry converted to accept XML text.

Happy FileMaking!

Beverly Voth is the web ma'am for DIGFM, a database interest group in Santa Clara, CA <http://www.digfm.org>. Currently she is Vice President of Web Development for Moonbow Software, Inc. <http://www.moonbow.com> and co-developer of "Theme Creator" which creates and imports the XML-formatted Theme files used by the New Layout/Report assistant.