Sie sind auf Seite 1von 21

FileMaker XML Technology Overview

by Elliotte Rusty Harold


- March 2000 -

FILEMAKER TECHNOLOGY OVERVIEW

TABLE OF CONTENTS

XML AND FILEMAKER 5A TECHNOLOGY OVERVIEW


EXECUTIVE SUMMARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 More Customizable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Data Exchange Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3 Publishing FileMaker Pro Data on the Web . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 WHAT WHY
IS

XML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4 XML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5

USE

OTHER WEB SOLUTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 Export as HTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 Instant Web Publishing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6 Custom Web Publishing with Proprietary Tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 Other Web APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 The XML Advantage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7 HOW
DOES

FILEMAKER PRO SUPPORT XML? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8


DATA FROM

REQUESTING XML

FILEMAKER PRO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
GRAMMAR

CHOOSING A FILEMAKER PRO XML

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11

FMPDSORESULT, a database table-specific grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11 FMPXMLRESULT, a database table-independent grammar . . . . . . . . . . . . . . . . . . . . . . . . . . .11 FMPXMLLAYOUT, a grammar for layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 FORMATTING XML DOCUMENTS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12 Formatting XML using CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13 Formatting XML using XSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14 Scripting and the Document Object Model (JavaScript,VBScript) . . . . . . . . . . . . . . . . . . . . . . .15 Tools to help format XML documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17 DEPLOYING A FILEMAKER PRO XML
SOLUTION

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18

FURTHER READING . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19 GLOSSARY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

EXECUTIVE SUMMARY
XML, the Extensible Markup Language, is perhaps the most heavily hyped technology since Java. It's been touted as the solution for a multitude of problems in fields as diverse as web page design,database development,newspaper syndication, mortgage brokering, and muskrat trapping. But just maybe XML really does live up to the hype. (Well, maybe not in muskrat trapping, but the other four are real examples.) FileMaker, Inc. is moving to support XML throughout its award-winning software product line. We believe it is extremely important that third-party independent developers gain a working knowledge of how XML technology can be leveraged for FileMaker Pro users. As you'll see XML is an extremely convenient format for dynamically accessing FileMaker Pro data from the web or other databases and clients.With XML, the data becomes far more usable and closer to its native format than it would be if it were first flattened into HTML. And by applying a simple style sheet or JavaScript you can make the data look and behave however you like. In addition, XML lets FileMaker Pro send the information to the user more quickly and with less load on the web server. This Technology Overview shows you how to take advantage of XML to serve data-centric web pages from FileMaker Pro 5 or FileMaker Pro 5 Unlimited with a particular focus on how XML surpasses prior technologies for embedding data in web pages. To that end, it's assumed you've worked with FileMaker Pro before, though not necessarily version 5; that you're familiar with HTML, and that you've got some experience publishing web pages and sites. However, no prior knowledge of XML is assumed.

process has to be repeated.This is an inefficient use of limited server resources. Serving data in XML allocates server resources much more efficiently. The server that uses XML performs faster, is more customizable, and can more easily exchange data with other databases.

HIGHER

PERFORMANCE

Serving data encoded in XML is faster because it lets FileMaker Pro do what databases are designed to do: store, search and sort data. By using a web browser to format the XML and/or transform it into HTML, youre freeing up FileMaker Pro to accept more requests. When using XML, FileMaker Pro only sends data to the browser.The client then massages that data into a reasonable display and presents it to the user. More of the work is shifted to the client, which lets FileMaker Pro service a lot more requests in less time using the same network bandwidth.And, since what the client gets is more neatly organized as data than a typical HTML page, the client can treat it as data. It can use JavaScript to sort or search the result set FileMaker Pro sent in real time. Changing the display to sort by date instead of last name, for example, doesnt have to require a new request to the database server and accompanying expensive round trip.

MORE

CUSTOMIZABLE

THE ADVANTAGES OF XML FOR FILEMAKER PRO WEB SERVERS


XML offers many advantages to the FileMaker Pro developer who is serving data over the Web. Perhaps the single most important is raw speed. XML makes a very lightweight envelope to hold data so it's fast to read and fast to write. Many popular web sites are really just HTML views onto a FileMaker Pro database.These range from large sites like the FileMaker web store to relatively small operations.These sites and many others like them use FileMaker Pros built-in CGI or additional middleware products to connect their web pages to the underlying FileMaker Pro database. However, this requires the server to do a lot of work reading HTML files, finding the database queries embedded in the files, making those queries against the FileMaker database, then inserting the results back into the HTML before sending it to the client. Then, if the client wants something changed, for instance having the results sorted by date instead of price, the entire

The most common way to integrate XML with FileMaker Pro is through forms and style sheets. The web browser shows the user a standard HTML form. The user fills out and submits the form. FileMaker Pro receives the form data and sends a response in XML that includes the data and the details about where a style sheet for the data can be found. At this point the server's job is done, and it's ready to process the next request from some other client. The browser then retrieves a style sheet that tells it how to format the data for display to the user.The server can also send the browser a JavaScript program telling the browser how to make the data dynamic, so the user can sort or search it in real time. Supplying a different style sheet or JavaScript program shows the user a different view of the data. And all of this can be done without bothering the server again with more requests! One request to FileMaker Pro gives the browser all the information the user needs.

DATA

EXCHANGE STANDARD

XML isn't just for the Web either. It has other uses too. It's an ideal format for sharing and exchanging data with third parties. Your data may be in a FileMaker Pro database but your customers or suppliers might use other databases.You can move data from one system to the other by generating XML, using XSL to transform into an agreed standard XML format, and then importing the data into the new database or

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

system as Figure 1 diagrams. This format can be documented WHICH FILEMAKER PRODUCT IS RIGHT FOR YOU? using a document type definition (DTD) or, in the future, an FileMaker Pro software is available in several different varieties even more precise schema. Most importantly, particular XML for different customers with different needs. All FileMaker Pro documents can be easily compared against DTDs or products support XML and can publish XML data on the Web. schemas to determine whether they adhere to the agreed-on format.You get to validate the data your customers and supFileMaker Pro 5 is the entry level product designed for sinpliers are sending you before you store it in your database. gle-user databases and small web sites. It includes the This is key for the expanding busiFileMaker Web Companion, but is ness-to-business market segment. limited to connections from no FileMaker Pro generates XML more than 10 unique IP addresses in PUBLISHING FILEMAKER PRO any twelve hour period.
DATA ON THE WEB

FileMaker Pro 5 includes a plug-in web server called the FileMaker Web Companion. The FileMaker Web Companion can serve static HTML files and JPEG images just like a traditional web server like Apache. However, its real advantage is that it can serve HTML and XML straight out of a FileMaker Pro database. The data does not have to be exported and stored in static HTML files first.This means that the browser always gets the most current, up-to-the-minute information from the database.

Figure 1: Exchanging data between databases using XML

XSL processor transforms data into agreed format

XML parser validates data

Database imports data

FileMaker Developer 5 includes FileMaker Pro 5 along with a variety of tools useful to professional database developers such as ODBC and JDBC drivers, enhanced layout design tools, XML examples and documentation, and the ability to build and distribute stand-alone runtime copies of a database. FileMaker Developer 5 also includes the FileMaker Web Companion and is limited to connections from no more than 10 unique IP addresses in any twelve hour period.

Since the FileMaker Web Companion is a web server, it needs to run on a machine that's connected to the Internet at a static domain name and IP address.This machine must have the database(s) users are browsing open.The FileMaker Web Companion can handle the various web services the machine provides, or it can run in conjunction with a traditional web server like Apache. If so, the two servers will simply run on different ports. Generally requests for static HTML files will be directed to the traditional web server, while requests for dynamic data in XML format will be steered to the FileMaker Web Companion. Client browsers like Netscape Mozilla and Internet Explorer connect to a web server running FileMaker Pro just like they connect to any other web server. Clients don't need any browser plug-ins or special software. The user can interact with the FileMaker Pro database using standard technologies like HTML forms, JavaScript, and of course XML. The most common way a user queries a FileMaker Pro database is by filling out a form in their browser, submitting it, and receiving the results back as XML.FileMaker can also send a CSS or XSL style sheet or a JavaScript or VBScript program with the results to tell the browsers how best to format the data for display to the end user.

For medium-to-high volume web sites, you'll probably want to move up to FileMaker Pro 5 Unlimited. This offers all the features of FileMaker Pro 5 including the FileMaker Web Companion and full XML support.Additionally, it removes the 10 IP address in twelve hour restriction and offers scalable load balancing and fault tolerance by using a Redundant Array of Inexpensive Computers (RAIC), each running its own copy of FileMaker Pro 5 Unlimited

WHAT

IS

XML?

The Extensible Markup Language, XML for short, is a W3C-endorsed standard for structured markup of documents and data. XML defines a syntax for a hierarchically structured text document divided into elements. Elements are delimited by start and end tags.These tags look superficially like HTML tags; that is they begin with a < and end with a >.Attributes are provided in name="value" pairs in the start tag of an element. Closing tags begin with a </ and so forth. However unlike HTML, XML elements are not limited to a fixed set of tag names.You can define tags like <book>, <person>, <sku>, <ID_Number>, <integer>, <DATA>, <ROW>, <ERRORCODE>, and more. For example, in HTML, a listing for a book might look like this:

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

<img src=0140012133.gif width=87 height=140 align=left> <dt>Three Men in a Boat <dd>Jerome K. Jerome <ul> <li>0140012133 <li>$6.95 <li>1/3/1998 </ul>

There's a lot missing from this listing. For instance, is this a book or a video? What is the rather mysterious number 0140012133? Is $6.95 a sale price, a rental fee, the shipping cost or something else? The last item looks suspiciously like a date; but is that date January 3, 1998 or March 1, 1998? And what happened on that date? All of this information should be easily ascertainable from the database, but it's not so obvious from the HTML.However, in XML the same listing would look something like this:
<book isbn="0140012133"> <title>Three Men in a Boat</title> <author>Jerome K. Jerome</author> <cover source="0140012133.gif" width="87" height="140"></cover/> <price>$6.95</price> <publication_date> <month>1</month> <day>3</day> <year>1998</year> </publication_date> </book>

year element, but then there must also be a corresponding closing </month> tag in the year element as well. When you use FileMaker Pro to generate HTML, wellformedness comes for free. That is, all the XML FileMaker Pro serves is well-formed without any extra effort on your part, so you don't have to spend a lot of effort wor-rying about the detailed rules of wellformedness. Applications that read XML documents are required to reject malformed documents.They are not allowed to try to fix the mistake and go on.This makes it much easier to write software that processes XML and to exchange XML documents between FileMaker Pro and other software. It helps avoid the browser compatibility wars that plagued HTML from its early days. The set of possible documents with a given group of elements is sometimes called an XML vocabulary or XML grammar. However, the technical term is XML application. This is not an application like FileMaker Pro or Internet Explorer that uses XML, but rather an application of XML to a particular domain like book inventories or chemistry. You can go beyond simple well-formedness, by documenting your XML application with a document type definition (DTD) and requiring that documents be valid according to the DTD. The DTD very formally describes which elements are allowed in what contexts. The DTD can be embedded in the XML document or stored in a separate file, whichever is more convenient.When a validating parser reads an XML document, it not only checks to see that the document is well-formed. It also checks to see that every element in the document matches the declaration for that element in the document's DTD. By providing a DTD, you add rules that are specific to your document type. These are in addition to the well-formedness rules that must be adhered to by all XML documents. However, a DTD is optional. If it isnt useful to you, you don't need to use one.

There are several points to consider in this example: The tag names tell you what's inside the tag. XML retains not only the data, but can also reveal the meta-data about what the data is. If you're mapping documents to databases, XML retains not only the field values but in some cases, the field names as well. This XML sample says absolutely nothing about how the book record is to be displayed to the reader. It says that there is a book with the title Three Men in a Boat and the author Jerome K. Jerome, but it doesn't say that the title should be 14-point Helvetica bold. It says that the price is $6.95,but it doesn't say that $6.95 should be a bullet point in a list. XML tags add structure and semantics to the data in a document. However, they say nothing about how that data is formatted. Formatting is applied later via a style sheet. Different style sheets can change the presentation of the data without affecting the underlying document. This document is well-formed.That means that it adheres to several rules. First, all tags that are opened ar eventually closed.There are no opening <book> or <year> or <isbn> tags without corresponding closing </book>, </year>, and </isbn> tags. Furthermore the elements don't overlap.The <month> tag can be contained in the

WHY

USE

XML?

XML offers many advantages to the FileMaker Pro developer who needs to send data to or receive data from non FileMaker Pro clients. Firstly, there has been an explosion of third party tools on many platforms in many languages for parsing, displaying, editing, exchanging and validating XML documents. These tools run the gamut from public domain to open source to fully supported payware, from C to Java to Perl, from Macintosh to Unix to Windows. Chances are, whatever you're doing with XML, part of the work has already been done for you and can be easily incorporated in your project at low cost and little effort.

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

Even more importantly, XML is much faster than proprietary solutions. Web sites that use CDML, Java Server Pages (JSP), or other middleware products to connect their web pages to a backend FileMaker Pro database require the server to do a lot of work reading HTML files, finding the database queries embedded in the files, making those queries against the FileMaker Pro database, then inserting the results back into the HTML before sending it to the client. If the client wants anything changed, no matter how small, it has to go back to the server which has to repeat the entire process.This is an extremely wasteful use of finite server resources. XML works better because all the server has to do is send some simple query results to the client.The browser does all the tricky formatting and manipulation of the data. For smaller data sets it can even be more efficient to move all the data to the client as XML; then use Java or JavaScript to perform all the manipulations on the client side. Searches and sorts can be performed against the local XML view of the data rather than requiring a round trip to the server. Another possibility is to show the user only part of the data their query returned (say ten records out of a hundred); but give them a link or button to select the next ten records.As long as the data can be stored and manipulated on the client, the number of queries and consequently the load on the server are reduced.

an e-commerce site that needed to let customers know whether a product was in stock right this minute. Furthermore, it doesn't allow users to interact with the data, on either the client or server side, such as searching for all the books by a particular author.They cant choose to sort by price, or add items to or remove items from a shopping cart.This approach is only suitable for very static, slowly changing sites. INSTANT WEB PUBLISHING Another approach, first introduced in FileMaker Pro 4, is to publish the database itself on the Web using Instant Web Publishing.This shows users a dynamic view of the data as it exists at the moment they load the page. Users can rest assured that any page they see has the most current and up-to-date data, even if records are being added to or edited in the database at the same time they're browsing and searching it. From their web browsers, users can even see and interact with the same layouts they'd use if they were connected with a FileMaker Pro client, making sorting, searching, and editing records in the database very easy. And all of this can be accomplished without having to write any programs, scripts, or style sheets. One of the biggest advantages of Instant Web Publishing is that it does an excellent job of simulating the look and feel of a FileMaker Pro layout. Figure 2 shows the same record displayed in Internet Explorer through Instant Web Publishing in the front window and in the actual FileMaker

OTHER WEB SOLUTIONS


XML is not the only way to combine FileMaker Pro databases with web sites, but it is one of the best. To more clearly see XML's advantages, let's first look at some of the other approaches that have been taken over the last few years and the problems they've had. EXPORT AS HTML The first and most obvious approach is to simply export the data to HTML. This can be done by exporting a database as an HTML table or, for more precise formatting, with calculation fields and a little AppleScript or Perl. (This approach works equally well for exporting data to an XML vocabulary other than one of the three FileMaker Pro natively supports.) This approach also allows you to serve data from any computer with a web server, including Unix and Linux systems that can't run FileMaker Pro. As already noted, you tend to lose a lot of the data's structure when moving to pure HTML. But the biggest problem with this approach is that the web site is not automatically updated when the database changes. Sometimes that's OK if you just want to present a static picture of the data to the user, but it doesn't work so well if the data changes on a frequent basis. For instance it wouldn't be adequate for

Figure 2: A record in a FileMaker Pro database served via the FileMaker Web Companion

Pro database in the back window.The fidelity of the HTML page to the original FileMaker Pro layout is amazing. However, Instant Web Publishing offers limited customization. You can use layout themes to modify color schemes but you can't rearrange items on the page. To change the way

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

your web site behaves after a record has been added or deleted, you need to use additional technology like XML. And while FileMaker Pro's layout tools give you the ability to create beautiful user interfaces, most database experts aren't accomplished graphic designers and more graphic designers are comfortable working with HTML than with FileMaker Pro. CUSTOM WEB PUBLISHING WITH PROPRIETARY TAGS Still a third approach is to add CDML tags to your HTML files.This allows you to use a sort of server-side include to integrate your HTML pages with data from a FileMaker Pro database.You write an HTML file in which you include special tags like [FMP-FIELD: title] and [FMP-if] that tell the server what query to make against the database. When a browser requests a document, the server replaces the CDML tags with data from the database. The server then sends the browser pure HTML that it can display without any special software. The biggest problem here is speed. Parsing an HTML file to find out what queries to make, making the queries, and then building a new document by combining the old document with the results of those queries puts a lot of load on a database. XML can be a lot faster because it removes the need to parse the HTML just to find the queries. Furthermore, FileMaker Pro does less work on the back end because XML is a lot closer to the data's native format. It's a lot quicker for FileMaker to send the data out in pure XML and let the client convert that to HTML than to do all the work on the server side. Additionally CDML (and other middleware technologies) are proprietary. Since these aren't extensible, you're pretty much stuck with whatever features the vendor has provided tags for. With XML you can use JavaScript or VBScript to build robust, custom applications and behaviors. Furthermore, proprietary tag sets prevent you from easily migrating your data and web site to Oracle or IBM's DB2. XML is non-proprietary and supported by more database vendors every day like FileMaker, Inc., IBM, and Oracle. With strong XML, JDBC, and ODBC support across the FileMaker 5 family, FileMaker Inc. is moving towards more open standards. New applications should move to XML so they can take advantage of future developments. OTHER WEB APIS Another possibility is to use database middleware like ODBC or JDBC to connect to the FileMaker Pro database and load data into the HTML pages. JDBC is especially convenient if your web server supports servlets or Java Server Pages (JSP). The Java code includes standard SQL queries

that the FileMaker JDBC driver forwards to the FileMaker Web Companion. The Web Companion returns the results, and the servlet or JSP wraps them in HTML before passing them on to the client. Other non-Java Web development tools like Allaire's Cold Fusion and Adobe's GoLive 4.01 can build pages in this fashion by using the FileMaker ODBC driver. However both ODBC and JDBC process data on the server side, either on the database server or the web server which has to do a lot of expensive, time-consuming formatting that could be done more cheaply and quickly on the client.The more successful your web site is and the more hits it gets, the more problematic this becomes.You can always buy bigger and faster hardware, but it's a lot cheaper to move to an XML-based, client-side approach. Furthermore, with ODBC or JDBC, the client still only gets unstructured HTML with all of its attendant disadvantages. This may be sufficient if you want to hide your data's structure or you only want to present a static picture of the data to browsers, but it's not suitable for dynamic sites that let the user rearrange the data to meet their needs. THE XML ADVANTAGE XML has a number of advantages compared to all these approaches. 1. Most importantly XML is faster because it moves a lot of the work to the client.The server receives a query and sends a response that's very close to the raw data. It doesn't have to spend a lot of CPU power or processing time massaging the data into HTML that's suitable for client display. Formatting a single HTML document isnt a significant resource issue. Formatting thousands of them is. It's faster for each of thousands of clients to do its own small piece of the work in parallel, than for one server, even a very fast one, to do all the work itself. 2. Secondly, XML is a standard. XML is well-documented, well-understood technology with lots of third party support in the form of software, books, specifications and more.This broad support makes it much easier to learn and use XML. It also makes it much easier to exchange data with other individuals, companies, vendors, customers, contractors, and with their databases since you're all using the same technology. XML is platform, database, and programming language agnostic. It's just as happy to work with FileMaker Pro and WebStar on a Macintosh as Oracle and Apache on Solaris.

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

3. Another important benefit of XML in today's increasingly heterogeneous Internet is that XML documents are at least partially self-documenting. When you see an item l i ke < p e r s o n > < l a s t > E l i a s < / l a s t > < f i r s t > J a s o n </first></person>, you can easily tell that Elias is the last name of a person and that Jason is the first name. With a DTD or schema and appropriate comments, the identification becomes even clearer.That isn't true of less flexible formats like HTML or tab delimited text.

level syntax differs, the basic approach of these solutions is the same.The client, generally a browser, makes a particular request to the web server, probably by filling out and submitting a form. The page the user requests contains markup in the proprietary language telling the web server how to fill it out with data from the database. For instance, here's a page that uses CDML markup to provide a current list of titles in stock.The proprietary tags are in bold. Figure 4 shows the resulting HTML page displayed in Netscape Navigator.
<html>
<head><title>Available Titles at FunnyNovels.com</title></head>

HOW DOES FILEMAKER PRO SUPPORT XML?


FileMaker Pro serves XML via the FileMaker Web Companion. A client system, generally a browser, makes a request to the server using an HTML link or form. This form or link is set up to pass both a query to the server and details about how the information is to be encoded in XML. The server formats the data as XML, then passes that XML back to the client. If the XML is intended to be displayed to a person, the server will include information with the document telling where a style sheet for the document can be found. The browser then requests the style sheet. Once it has retrieved this style sheet, it formats the XML according to the instructions in the style sheet, and shows it to the user. Figure 3 summarizes this process:
<body> <h1>Funny Novels in stock on [FMP-CurrentDate]</h1> <UL> [FMP-Record] <LI>[FMP-Field: title], <i>[FMP-Field: author]</i> [/FMP-Record] </UL> <HR> Copyright 1999 Funny Novels<BR> <A HREF="mailto:webmaster@funnynovels.com">webmaster@funnynovels.com</A> </body></html>

Figure 4: A Web Page generated by FileMaker Pro in response to CDML markup

Figure 3: Querying FileMaker Pro for XML

Again, there are many other approaches for a web browser to get data out of a database.Adding CDML to pages is one approach historically used by FileMaker Pro backed sites. Another is to use Java Server Pages, servlets, CGIs, or an application server to talk to the database. Although the low

FileMaker Web Companion must replace the bold tags with standard HTML before sending this file to a browser. Thus, the FileMaker Web Companion web server retrieves the requested data from the database server and replaces the proprietary markup with the data.The result is a page of pure HTML. FileMaker Web Companion then sends this HTML page to the client, which displays it to the user. Figure 5 summarizes this process. This looks simpler than the XML process in Figure 3, and in some ways it is. But that's because the FileMaker Web Companion is doing a lot more of the work and the browser

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

database over the Web in much the same way it can be retrieved in HTML format, by opening FileMaker Pro (and hence the FileMaker Web Companion) on the server and using CGI commands from the client to make queries. However since, unlike HTML, XML doesn't carry any formatting information, there's an extra step.You'll also need to provide a CSS or XSL style sheet or use JavaScript to tell the browser how to display the XML data. To get data out of a FileMaker Pro database as XML, the machine running FileMaker Pro must be connected to the Internet using TCP/IP and the FileMaker Web Companion must be turned on. To activate this, pull down the Edit menu and open the Preferences/Application dialog box. Choose the Plug-In tab and check the Web companion check box. Next select Web Companion and click the Configure button. If you're running another web server on the same system, you'll need to pick some port other than 80. FileMaker has registered port 591 with the IANA for this purpose. Click OK twice to get out of the dialog and save your changes. Then, open each database you want to share, go to the File Menu and select Sharing. In the resulting dialog box, enable the Web Companion checkbox. Once the Web Companion is enabled, it's simply a matter of connecting to the server with a Web browser using a URL with the appropriate query string. For example, suppose you want to get an XML formatted list of the records in the novels.fp5 database from a FileMaker Pro database running on the host funnynovels.com on port 591.Then you would type this URL into your Web browser's location bar or Open page dialog:
http://funnynovels.com:591/FMPro?-db=novels.fp5&format=-fmp_xml&-max=all&-find

Figure 5: Querying a server for HTML with CDML

is doing a lot less. As long as there are many clients per server, it makes sense to push as much of the work as possible onto the clients to relieve the burden on the server. With XML, clients are closer to the real data. If they need to further process the data, for instance by sorting or summing it, they can. If they want to import the data into their own databases, they can. This doesn't just have to happen once. By using JavaScript the client can re-sort and organize the data multiple times according to a variety of criteria. By contrast, in the second approach a client only gets HTML, which is good for presentation but not much else. If it wants to see a slightly different view of the data, it has to go back to the server and ask for the exact same data, just formatted and organized a little differently. On mediumto-high volume web sites, this is an inefficient use of a server's limited resources. On the other hand, any server-based solution currently has much broader browser support. It can send viewable data to pretty much any browser since Netscape 1.0.The pure XML based solution more or less requires a fifth generation browser (for example, Internet Explorer 5 or the upcoming browser from Netscape), which limits your ability to deploy a solution like this. Of course as users upgrade their browsers, this will become less of a concern. (The Gartner Group estimates that by "year-end 2001, 80% of all Web-based technology will use XML-defined data interchange.") In the meantime, a lot of sites have chosen to go with a hybrid solution in which the database generates XML. However, the XML, rather than being sent directly to the client, is transformed to HTML on the server side, typically using an XSLT style sheet and Microsofts Active Server Pages (ASP) or Suns Java Server Pages (JSP).This allows you to support all web browsers while sticking with standard markup languages and still achieve substantial speed-ups.

This URL can be divided into five parts: the scheme: http
This specifies which protocol is used to communicate with the server.When talking to FileMaker Pro over the Web, this will always be http, the hypertext transfer protocol.

the host: funnynovels.com


This specifies the name or IP address of the server FileMaker Pro is running on.

the port: 591


Normally HTTP servers run on port 80. However if FileMaker Pro is sharing a machine with another web server like Apache or WebStar, then you'll need to choose a different port.

REQUESTING XML DATA FROM FILEMAKER PRO


Data can be retrieved in XML format from a FileMaker Pro

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

the file path: /FMPro


This tells the server which file to serve.When using the FileMaker Web Companion as your server to serve XML, this is always /FMPro.

This form uses hidden INPUT elements so that the query string will be set up exactly. Another approach is to make the complete query string part of the value of the href attribute of a link, like this:
<a href="http://funnynovels.com:591/FMPro?-db=novels. fp5&-format=fmp_xml&-max=all&-find"> List Books </a>

the query string: -db=novels.fp5&-format=-fmp_xml&max=all&-find


This provides input for the web server program that decides what data to send back.The information is provided in name=value pairs separated by & signs.This query string has four variables: -database, which specifies the database name (in this case, the value "novels.fp5", -format, which specifies which FileMaker XML grammar to use (in this example, "-fmp_xml", -max, which specifies the number of records to retrieve (in this case, all), and -find, which is the request for data.

On the other hand, one of the advantages of a FileMaker Pro backed web site is that users can search, sort, and perform other operations in the database directly from their browsers. In this case you'd give the user non-hidden INPUT elements that let them type in what they wanted to search for or sort by. For instance, this form lets the user search by author:
<FORM METHOD="GET" ACTION="http://funnynovels.com/FMPro">

Figure 6 shows Internet Explorer 5 connecting to this database using this URL. Since we haven't yet attached a style sheet to the document,IE uses its default,tree structured XML presentation that allows you to collapse and expand headings.

<INPUT <INPUT <INPUT <INPUT </FORM>

NAME="-db" VALUE="novels.fp5" TYPE="hidden"> NAME="-format" VALUE="-fmp_xml" TYPE="hidden"> NAME="Author"><br> NAME="-find" VALUE="List Books" TYPE="submit">

The form is shown in Figure 7:

Figure 7: A simple author search form

The query string it builds up looks like this:


-db=novels.fp5&-format=-fmp_xml&Author=Jerome&find=List+Books

Figure 6: Internet Explorer 5 showing raw XML from a FileMaker Pro database served over the Web

Of course, most of the time you won't be blindly typing query strings into the location bar. Instead you'll set up online forms so surfers can just press a button to access the database. For example, this HTML form would let users access the complete book list:
<FORM METHOD="GET" ACTION="http://funnynovels.com:591/FMPro"> <INPUT NAME="-db" VALUE="novels.fp5" TYPE="hidden"> <INPUT NAME="-format" VALUE="-fmp_xml" TYPE="hidden"> <INPUT NAME="-max" VALUE="all" TYPE="hidden"> <INPUT NAME="-find" VALUE="List Books" TYPE="submit"> </FORM>

The query string variables that begin with a hyphen like -db, -format, and -find are all instructions to FileMaker Pro.The query string variables that dont begin with a hyphen, Author in this example, are names of fields in the database. By using INPUT elements with different names you can search by different fields in the database. FileMaker Pro supports over two dozen different variables in its query strings that allow web surfers to create new records, edit existing records, search databases, sort databases, and run scripts in databases. All of these operations are performed by changing the values of query string variables or indirectly by setting up forms to use different query string variables. A complete list of the query string

10

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

variables you can use to request XML from a FileMaker Pro database, as well as the exact syntax for the values of these variables, can be found in Appendix B of the FileMaker Developer's Guide, or at the FileMaker XML central web site: www.filemaker.com/xml.

<?xml version="1.0" encoding="UTF-8" ?>


<FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">

CHOOSING A FILEMAKER PRO XML GRAMMAR


XML is a very general syntax for documents. XML itself says very little about what tags you may and may not use where in your documents. Most applications of XML restrict themselves to a well-specified subset of XML. FileMaker Pro can serve data encoded in any of three different XML vocabularies.These are: The FMPDSORESULT grammar (database dependent) The FMPXMLRESULT grammar (database independent) The FMPXMLLAYOUT grammar FMPDSORESULT and FMPXMLRESULT are alternative XML vocabularies for describing the records and fields in a FileMaker Pro 5 database.Which one you choose depends on whether you want to use the same XML vocabulary for all your databases or different, more specific vocabularies for different databases. The FMPDSORESULT grammar uses elements whose names match the names of the fields in the database. This means you can apply different CSS style rules to different fields. However, you do have to write a new style sheet for every different database you want to work with. The FMPXMLRESULT grammar uses a vocabulary with elements that represent database records, fields, result sets, and so forth.These are enough to describe any database, but they're a little generic. For instance, a book title would be described with the same generic DATA tags that are used for author names, ISBN numbers, prices, and other fields. This makes it difficult to use CSS to apply different styles to different fields. XSL style sheets are more flexible and can better deal with a database table-independent grammar like this using other non-name cues like element position. Finally, the FMPXMLLAYOUT grammar is used to describe not the data in a table but rather the semantic organization of the table such as the values allowed in a value list. FMPDSORESULT, a database dependent grammar The FMPDSORESULT grammar uses field names as element names. A small result set in the FMPDSORESULT grammar looks like this:

<ERRORCODE>0</ERRORCODE> <DATABASE>novels.fp5</DATABASE> <LAYOUT></LAYOUT> <ROW MODID="2" RECORDID="1"> <Title>Three Men in a Boat: To Say Nothing of the Dog!</Title> <ISBN>0140012133</ISBN> <Author>Jerome K. Jerome</Author> <Cover>FMPro?-DB=novels.fp5&-RecID=1&Cover=&Img</Cover> <Price>$6.95</Price> </ROW> </FMPDSORESULT>

One consequence of using field names as element names (rather than as element content or attribute values) is that the field names must be included in the DTD. Every database with a different schema will need a different DTD. Similarly, you can't write a very good generic style sheet for displaying this data. Any style sheet that provides an attractive format for this data will have to know that ISBN numbers are included in ISBN elements, and so forth. Of course, if you work mostly with one database at a time, then having the field names encoded as element names makes it a lot easier to apply style rules to particular elements.This is especially true in CSS because most current CSS implementations can't select based on attributes or element content. However even with XSLwhich can select based on attributes and element contentit's easier to select element names. Furthermore, this is a lot easier for human beings to read than the next two formats we'll look at. Computers, of course, don't much care about that. FMPXMLRESULT, a database independent grammar The FMPXMLRESULT grammar can encode an arbitrary table in XML.This is because, unlike FMPDSORESULT, it uses a fixed set of elements.The database schema is described by a METADATA element that contains one FIELD element giving the name and type of each field.The benefit of using "generic" tags is that the same style sheet can be easily reused with other FileMaker Pro databases.The same result set encoded in FMPXMLRESULT looks like this:
<?xml version="1.0" encoding="UTF-8" ?> <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult"> <ERRORCODE>0</ERRORCODE> <PRODUCT BUILD="9/8/1999" NAME="FileMaker Pro Web Companion" VERSION="5.0v2" /> <DATABASE DATEFORMAT="M/d/yyyy" LAYOUT=""NAME="novels.fp5" RECORDS="4" TIMEFORMAT="h:mm:ss a" /> <METADATA> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Title"TYPE="TEXT" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ISBN" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Author" TYPE="TEXT" />
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Cover" TYPE="CONTAINER" /> <FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Price" TYPE="NUMBER" />

11

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

</METADATA> <RESULTSET FOUND="1"> <ROW MODID="3" RECORDID="1"> <COL>


<DATA>Three Men in a Boat: To Say Nothing of the Dog!</DATA>

</COL> <COL> <DATA>0140012133</DATA> </COL> <COL> <DATA>Jerome K. Jerome</DATA> </COL> <COL> <DATA>FMPro?-DB=novels.fp5&-RecID=1&Cover=&-Img</DATA> </COL> <COL> <DATA>$6.95</DATA> </COL> </ROW> </RESULTSET> </FMPXMLRESULT>

Since all FMPXMLRESULT documents use the same fixed set of tags and attributes--DATABASE, RESULTSET, ROW, COL, DATA, etc.--it's easy to provide a DTD that can validate any FMPXMLRESULT document. Furthermore, the document itself includes a pretty decent schema for the database (not the same thing as an XML schema!) in the METADATA element. However, since the actual data is all stored in DATA elements, it's pretty much impossible to use CSS to attach different styles to different fields. For instance, you can't say that the title is bold but the author is plain text. XSL's more powerful selection facilities do allow you to make statements like that, though. Furthermore, the very regular, predictable structure of an FMPXMLRESULT is easier to handle through JavaScript and the Document Object Model (DOM) than the looser FMPDSORESULT grammar. If you're able to use XSL or fifth generation browsers, you should probably choose FMPXMLRESULT in preference to FMPDSORESULT. FMPXMLLAYOUT, A
GRAMMAR FOR LAYOUTS

<?xml version="1.0" encoding="UTF-8" ?> <FMPXMLLAYOUT xmlns="http://www.filemaker.com/fmpxmllayout"> <ERRORCODE>0</ERRORCODE> <PRODUCT BUILD="9/8/1999" NAME="FileMaker Pro Web Companion" VERSION="5.0v2" /> <LAYOUT DATABASE="novels.fp5" NAME="allfields"> <FIELD NAME="Title"> <STYLE TYPE="EDITTEXT" VALUELIST="" /> </FIELD> <FIELD NAME="ISBN"> <STYLE TYPE="EDITTEXT" VALUELIST="" /> </FIELD> <FIELD NAME="Author"> <STYLE TYPE="EDITTEXT" VALUELIST="" /> </FIELD> <FIELD NAME="Cover"> <STYLE TYPE="EDITTEXT" VALUELIST="" /> </FIELD> <FIELD NAME="Price"> <STYLE TYPE="EDITTEXT" VALUELIST="" /> </FIELD> <FIELD NAME="Binding"> <STYLE TYPE="RADIOBUTTONS" VALUELIST="Bindings" /> </FIELD> <VALUELISTS> <VALUELIST NAME="Bindings"> <VALUE>hardcover</VALUE> <VALUE>softcover</VALUE> </VALUELIST> </VALUELISTS> </LAYOUT> </FMPXMLLAYOUT>

The other grammars tell you what the data is and what the type of the data is.The FMPXMLLAYOUT grammar, by contrast, describes the structure and layout of a record. For example it provides field names, the types of the fields (whether they're formatted as editable text boxes, radio buttons, checkboxes, pop-up lists, or pop-menus and so forth). If the value of the field is taken from a value list, either dynamic or included in the layout, then the list of possible values is included as well.You can use all this information to build HTML forms that use the same value lists, the same default values, and the same user interface components. What an FMPXMLLAYOUT document doesnt tell you is any data that belongs to any particular record, as opposed to the general structure of all records in the table.

FMPXMLLAYOUT is the third and final XML grammar that FileMaker Pro supports. It's a little different than the other two because it provides different information than the other two.Whereas both FMPDSORESULT and FMPXMLRESULT focus on the data in the database, FMPXMLLAYOUT describes the layout of the fields. Here's the FMPXMLLAYOUT description of the same database that the previous two result sets came from. However, what's described here is not a result set, but rather one particular layout from the database the previous result sets came from.

FORMATTING XML DOCUMENTS


The almost source code like view of the XML in Figure 4 is not ideal. In practice, you need a much more attractive web page. However, XML says nothing about how the data is presented. Instead it relies on a style sheet or script to specify how each individual element is to be presented. There are several choices for formatting languages. Cascading Style Sheets (CSS) is the most broadly supported style sheet language and one of the simplest. However, it's quite limited in what it can accomplish.The Extensible Style

12

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

Language (XSL) is more powerful but more complex, and does not yet have broad browser support. It does, however, have substantial third party support.Another extremely powerful option, albeit one that comes with a price in increased complexity, is using the Document Object Model and a scripting language like JavaScript or VBScript to format and manipulate the native XML data and/or reformat it into HTML. Table 1 summarizes the various options and their advantages and disadvantages:

/* Put author, ISBN, and Price on separate lines */ Author {display: block; font-style: italic} ISBN, Price {display: block}

Here we're using the FMDSORESULT grammar because CSS is quite limited in what it can apply styles to. It can say that the Title element should be bold. However, saying that the first COL element in a RESULTSET should be bold exceeds CSS's limited selection capabilities (although CSS2 may do this). Well demonstrate using XSL, below. Figure 8 shows what the result looks like after the above style sheet has been applied. It's a lot more attractive than Figure 5.

Connecting a style sheet or script to the actual data returned from the database is easy, even if the style sheet is delivered from a different web server. All of these options share the advantage that the actual formatting information can be stored in a separate file from the data itself, allowing designers and programmers to use familiar tools like BBEdit or HomeSite to write their style sheets and scripts.With just a little forethought when first designing the style sheets or scripts, many different queries can all use the same few standard style sheets or scripts. FORMATTING XML USING CSS The simplest, most widely supported style sheet language for XML is Cascading Style Sheets Level 1 (CSS1).This is a very straight-forward language that simply lists properties for particular elements. Figure 9 shows the books database served in XML and formatted with this CSS1 style sheet (comments are enclosed in "/*" and "*/"):
/* These are the defaults for the entire page */ FMPDSORESULT {display: block; font-family: New York, Times New Roman, serif}
/* These are the elements we want to hide from the user */ ERRORCODE, DATABASE, LAYOUT, Cover {display: none}

Figure 8: A find request with a CSS style sheet applied

Elements generally inherit properties from their parents, but can override them if they choose. For example, in the above style sheet the Author and Price are in a serif font (preferably New York) but Title is in a sans serif font inherited from their parent FMPDSORESULT element because it has a more specific rule setting its font face. Unfortunately, CSS Level 1 alone is too simple to handle many common needs. For instance, it doesn't allow you to organize information as tables instead of paragraphs or embed images in a document. It relies on features of HTML to accomplish tasks like this. However, XML has no such underlying formatting model. Unlike HTML it makes no assumptions about how data is to be arranged on the page. CSS Level 2 does add a lot of features that are necessary for the more complex task of styling XML, such as table structures and text that doesn't flow from left to right and top to bottom (like Arabic or traditional Chinese). However, CSS2 isn't very well supported by common browsers yet. Finally, since CSS1 and CSS2 are static markup languages, they are limited to applying styles to what text is present in the document. They can't reorder that text, or merge text with boilerplate information. To do this with CSS, you must use CSS properties via the DOM from scripting languages like JavaScript.

/* Make the title look like an H1 header, big and bold */ Title {font-weight: bold; font-family: Helvetica, Arial, sans-serif; font-size: large}

13

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

Connecting a style sheet to the actual data returned from the database is easy. You just need to add -styletype and -stylehref variables to the query string that specify the MIME type and URL respectively of the style sheet you want to use. The styletype tag specifies the type of stylesheet to use and the stylehref tag specifies the file location).Then, before serving the document, FileMaker Pro will insert the necessary <?xml-stylesheet?> processing instruction to connect the document it sends to the style sheet you've prepared. For example, suppose your style sheet is at the absolute URL http://www.funnynovels.com/ styles/books.css.All you have to do is add these two hidden fields to the form that makes the query:
<INPUT NAME="-styletype" VALUE="text/css" TYPE="hidden"> <INPUTNAME="-stylehref" VALUE="http://www.funnynovels.com/styles/books.css" TYPE="hidden">

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

xmlns:fm="http://www.filemaker.com/fmpdsoresult"> <xsl:template match="fm:FMPDSORESULT"> <HTML> <HEAD><TITLE>Books in Inventory</TITLE></HEAD> <BODY> <H1>Funny Novels Inventory</H1> <xsl:apply-templates select="fm:ROW"/> <HR></HR> Copyright 1999 Funny Novels<BR /> <A HREF="mailto:webmaster@funnynovels.com"> webmaster@funnynovels.com </A> </BODY> </HTML> </xsl:template> <xsl:template match="fm:ROW"> <h2> <xsl:value-of select="fm:Title"/> by <i><xsl:value-of select="fm:Author"/></i> </h2> <ul> <li>ISBN: <xsl:value-of select="fm:ISBN"/></li> <li>Price: <xsl:value-of select="fm:Price"/></li> </ul> </xsl:template> </xsl:stylesheet>

This will add these two variables to the query string:


-styletype=text/css&-stylehref=http://www.funnynovels. com/styles/books.css

XSL style sheets are attached in much the same way. The only difference is that the -styletype query string variable would have the value "text/xsl" instead of "text/css". FORMATTING XML USING XSL XSL is a much more complete style sheet language than CSS. Furthermore, XSL is much better suited to the specific needs of XML, as opposed to CSS, which is really designed for HTML with XML support tacked on as an afterthought. However, while XSL is much more powerful than CSS, it's also quite a bit more complex. XSL is divided into two parts: XSL Transformations (XSLT) and XSL Formatting Objects. (XSL-FO). The transformations half defines an XML vocabulary for describing how one XML document is transformed into another XML document. The formatting objects half defines an XML vocabulary for describing the layout, styles, and contents of boxes on pages. It's almost PostScript like in its power and flexibility. These two parts are useful independently of each other, and indeed XSLT is much further along in both specification and shipping software than XSL-FO. The most common way to use XSL with FileMaker Pro is to write an XSLT style sheet that transforms the XML FileMaker Pro emits into HTML that the browser knows how to display. Since HTML can use CSS formatting properties, this means that XSLT can do anything CSS can do, and then quite a bit more. An XSLT style sheet for the books example using the FMPDSORESULT grammar would look something like this:

This transforms the XML FileMaker Pro sends into very nicely formatted HTML as Figure 9 shows. Since the style sheet can contain literal result elements like "<TITLE>" and text strings like "Copyright 1999 Funny Novels" as well as XSL instructions like xsl:template, it's straight-forward to mix the actual data from the database with boilerplate text like this.

Figure 9: A find request with an XSL style sheet applied

This style sheet matches one template to the root element FMPDSORESULT that wraps the entire page in a standard

14

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

HTML envelope like a HEAD element and a signature block with a copyright notice. Inside the template for the root element, xsl:apply-templates processes each ROW child element. For every ROW child, it fills in and outputs the template for the ROW element. The ROW template pulls each piece of datathe author, the title, etcand puts it together along with some standard HTML formatting tags like <H2> and <i>. XSLT also works for the FMPXMLRESULT grammar. In this case you can't select individual fields like Author using the element names since all the element names are the same. Instead you have to choose fields by their positions relative to their siblings in their parent ROW element.
<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fm="http://www.filemaker.com/fmpxmlresult">

However, ultimately XSL is a declarative language that focuses on the structure of the input document. If you really need to manipulate XML on the client side in a truly arbitrary fashion, then you need to use a scripting language like VBScript or JavaScript. Scripting can accomplish anything XSLT can, as well as performing a lot of things XSLT can't like making network connections to load document parts that are only referenced by URL in the input document or dynamically updating the view of the data based on what the user does with the mouse. For instance, in Internet Explorer 5's default, tree-structured XML view, scripting is responsible for showing and hiding the individual parts of the document as the user clicks on the + and - signs in the left hand column. The trade off of using a scripting language to access the document is that it's considerably more complex than the alternatives of CSS and XSLT. Scripting is programming, and while programming in JavaScript may be easier than programming in traditional languages like C or Java, it still requires a reasonable facility with programming fundamentals. And, depending on your task, you may find that 90% of your code does something that could be more easily and cleanly done in XSLT, while less than ten percent of your program is devoted to the dynamic features that really demand scripting. The first step in using JavaScript to format XML data is to get the XML into the HTML document that holds the script. Internet Explorer 5 provides several approaches including XML data islands and an XMLDSO applet. However, here we'll focus on a method supported in Internet Explorer 4 for Windows and later. This is an ActiveX control that connects to the MSXML parser.This ActiveX control can load an XML document from a URL on the network. It then exposes the XML document to the script as an object. The child elements of the document become properties of the object. By reading the values of the properties of the object (and the values of the properties of the properties and so forth) you can access any node in the XML document. Naturally, we'll set the ActiveX control to a URL that points into a FileMaker Pro database.This demonstrates the power of XML: Microsoft never considered the needs of FileMaker Pro when it wrote Internet Explorer; yet because FileMaker Pro supports XML, we can easily make FileMaker Pro records and result sets into objects that Internet Explorer natively handles. The MSXML parser exposes the contents of the XML document using Internet Explorer's Document Object Model, or DOM. (Netscape has a different DOM which supports none

<xsl:template match="fm:FMPXMLRESULT"> <HTML> <HEAD><TITLE>Books in Inventory</TITLE></HEAD> <BODY> <H1>Funny Novels Inventory</H1> <xsl:apply-templates select="fm:RESULTSET"/> <HR></HR> Copyright 1999 Funny Novels<BR /> <A HREF="mailto:webmaster@funnynovels.com"> webmaster@funnynovels.com </A> </BODY> </HTML> </xsl:template> <xsl:template match="fm:ROW"> <h2> <xsl:value-of select="fm:COL[position()=1]"/> by
<i><xsl:value-of select="fm:COL[position()=3]"/></i>

</h2> <ul>
<li>ISBN: <xsl:value-of select="fm:COL[position()=2]"/></li> <li>Price: <xsl:value-of select="fm:COL[position()=5]"/></li>

</ul> </xsl:template> </xsl:stylesheet>

Since XSLT can produce essentially arbitrary HTML output, (possibly including some CSS as well) you're only limited by the capabilities of HTML. Anything you can do in HTML, you can do in XML + XSLT transformed to HTML. The same can't be said for XML + CSS which is missing some of the power of HTML. SCRIPTING AND THE DOCUMENT OBJECT MODEL (JAVASCRIPT, VBSCRIPT) XSLT is extremely powerful, and can accomplish a lot. Beyond the simple style sheets we've seen here, it can sort and reorder elements, select elements based on attribute values, perform simple arithmetic, format elements with the same name but different content differently, and more.

15

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

of this to date. The W3C is making efforts to standardize DOMs between browsers. It has released an official specification for DOM Level 1, of which Internet Explorer 5 has partial support. However, true cross-browser scripting and DOM support is still some time in the future.) The IE DOM allows you to access the XML document at a remote URL by invoking the MSXML XML parser as an ActiveX Control. This returns an XML Document object whose child elements you can inspect. Below you see an HTML page designed to handle this. It loads an external script file called loadbooks.js that will connect to the database, download the XML, and format it as HTML for insertion in the page.
<HTML> <HEAD><TITLE>Books in Inventory</TITLE></HEAD> <BODY> <H1>Funny Novels Inventory</H1> <SCRIPT LANGUAGE="JavaScript" SRC="loadbooks.js"> </SCRIPT> <HR></HR> Copyright 1999 Funny Novels<BR /> <A HREF="mailto:webmaster@funnynovels.com"> webmaster@funnynovels.com </A> </BODY> </HTML>

// complete text of each column since our database doesn't // have any repeating fields. var title = columns.item(0).text; var isbn = columns.item(1).text; var author = columns.item(2).text; var price = columns.item(4).text;
// Now that the title, author, price, and ISBN are stored in // convenient variables, we simply wrap them in a little // literal HTML and write the data into the web page. document.write("<h2>" + title + " by <i>" + author + "</i></h2> "); document.write("<ul>"); document.write("<li>ISBN: " + isbn); document.write("<li>Price: " + price); document.write("</ul>"); }

The resulting web page, shown in Figure 10, is almost identical to the page produced earlier by XSLT. Probably more than 90% of the time both JavaScript and XSLT are completely capable of doing anything you need and your choice between them is mostly a matter of personal preference and software support.The exceptions would be cases where you wanted to respond to the user dynamically in real time or you needed to merge data from multiple XML documents. In these cases you really need a scripting language.

Here's the loadbooks.js script.


// Load the parser var xml = new ActiveXObject("msxml"); // Tell the parser which document will be parsed xml.URL = "http://localhost/fmpro?-db=novels.fp5&format=-fmp_xml&-find"; // Get the root element of the document var docroot = xml.root; // Look for the // We know that // there should var resultset = RESULTSET child of the root. in the FMPXMLRESULT grammar be exactly one of these: docroot.children.item("RESULTSET");

Figure 10: A find request that uses JavaScript formatting

// We know that in the FMPXMLRESULT grammar // RESULTSET has zero or more ROW children // and no children of any other type var rows = resultset.children; // Each row in this database represents a book for (row=0; row < rows.length; row++) { // The fields are in COL elements which are the // only children of the ROW elements. var columns = rows.item(row).children; // The title, ISBN, author, and price are always // in the same columns. We could get the DATA children // here as well, but it's simpler just to take the

This script is extremely short on error checking and makes a lot of assumptions that particular fields like Title and Author will be in particular places in the document. These positions shouldn't change capriciously from run to run. However, they might change if someone deleted a field from the database, or changed which fields appear on the layout. Ideally, you'd want to compare the expected positions for fields with the position of the corresponding FIELD child of the METADATA element. The XSLT style sheet shared this issue. However, in that case the solution would be a lot more complex to implement than here.The

16

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

CSS style sheet did not share this problem because it used the FMPDSORESULT grammar that identifies the different fields by their names rather than by their positions. An alternative solution would be to simply use that grammar instead of FMPXMLRESULT. This is far from the only way to format a page using JavaScript.There are at least half a dozen other ways to do it that would produce identical results. For instance, you could use an XML element as a data island tied to DIV elements, or you could load the XML when the document first loaded and insert it into an element rather than simply writing it into the middle of the document. Of course all these examples really only reproduce what we already accomplished more simply with XSLT. The real advantage to JavaScript is dynamically manipulating the XML in response to user action. Once you've loaded the XML document into memory from the FileMaker Web Companion and possibly converted it to some convenient format, it's a simple matter of programming to sort it, collapse it, rearrange it or reformat it on the fly. Since JavaScript is a full programming language, it lends itself to multiple solutions. The same technique works with virtually any embedded scripting language, provided it has some way to translate a remote XML document into an object to be accessed by the script. For example, here's a version of the same script that uses VBScript instead of JavaScript. Since VBScripts can't be included in external files, it's embedded directly in the HTML source:
<HTML> <HEAD><TITLE>Books in Inventory</TITLE></HEAD> <BODY> <H1>Funny Novels Inventory</H1> <SCRIPT LANGUAGE="VBScript"> Dim rows, columns Dim xmldoc Set xmldoc = CreateObject("Microsoft.XMLDOM") REM wait for the document to finish loading before continuing xmldoc.async = false REM validation isn't required; well-formedness is enough xmldoc.validateOnParse = false REM Load the XMl data from the database. Notice we use the REM FMPXMLRESULT grammar xmldoc.load("http://localhost/fmpro?-db=novels.fp5&format=-fmp_xml&-find") REM Here we go straight to the ROW elements; there's one row per record Set rows = xmlDoc.getElementsByTagName("ROW")

REM Format each record For i=0 To (rows.length -1) REM Put the fields of the record into the columns variable Set columns = rows.item(i).getElementsByTagName("DATA") REM Get each field from its known position title = columns.item(0).text isbn = columns.item(1).text author = columns.item(2).text price = columns.item(4).text REM Wrap the data in HTMl and write it into the document document.write("<h2>" + title + " by <i>" + author + "</i></h2> ") document.write("<ul>") document.write("<li>ISBN: " + isbn) document.write("<li>Price: " + price) document.write("</ul>") Next </SCRIPT> <HR></HR> Copyright 2000 Funny Novels<BR /> <A HREF="mailto:webmaster@funnynovels.com"> webmaster@funnynovels.com </A> </BODY> </HTML>

Aside from the syntactic differences between Visual Basic and JavaScript, this script is really quite similar to the JavaScript version and produces the same end result. Some lines look almost identical. The reason is that both JavaScript and VBScript are accessing the same objects using the same object model. For instance, the document object is the same thing in VBScript as it is in JavaScript, a representation of the HTML page. However, because this script was written using Microsofts Document Object Model, it only runs on Internet Explorer. if you add support in this script for W3C DOM, the script would work across platforms on W3C-DOM compliant browsers. TOOLS TO HELP FORMAT XML DOCUMENTS The basic tool for editing CSS is a text editor like UltraEdit, emacs, or BBEdit and a CSS compliant web browser like Mozilla 5 or Internet Explorer 5.Various text editors like HotMetal, HomeSite, FrontPage, and BBEdit provide varying levels of support for CSS, but for the most part any software you can edit HTML+CSS in will do the trick for XML+CSS as well. If you prefer to design your documents visually rather than by typing style rules in a text editorand most people dothen there are a number of free and cheap tools to help you do so by editing style sheets. Not all of these can work with data loaded directly from a FileMaker Pro query over the Web.You may need to load an example page into your browser first, then save

17

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

it to a local file from the browser. Then you can work on this local file instead. However, once you've done that, it's quite easy to create the style sheet. Attaching the finished style sheet to future queries simply requires moving it into the FileMaker Pro Web folder and adding -stylehref and -styletype variables to your query strings that point to your style sheet. XSLT style sheets are trickier.You'll still need a text editor like emacs or BBEdit and a web browser to view the finished product. However, if you're relying on transforming XML to HTML on the server side rather than letting the browser do it for you, you're probably better off with a command line processor like xt or Xalan since they're more up to date with the final W3C XSLT Recommendation. XSLT processors that are open source and written in Java include: James Clark's xt: http://www.jclark.com/xml/xt.html The Apache XML Project's Xalan: http://xml.apache.org/xalan/index.html Michael Kay's Saxon: http://users.iclway.co.uk/mhkay/saxon/ There are numerous others, including ones written in C, C++, Python, and many other languages. However these three appear to be frequently updated, an important characteristic on the bleeding edge that is XSL. There are fewer tools for editing XSL style sheets than CSS style sheets, and they aren't nearly as visual.To a large extent, that's because XSL's formatting model doesn't easily lend itself to making text selections and pulling down a font or a style from a menu. However, there are a couple of packages worth checking out. IBM's alphaWorks' XSL Editor is a pure Java program for editing and debugging XSLT style sheets. It lets you trace the path the templates follow through a document, and helps you write, select and match expressions by automatically generating the necessary XPath syntax from example input and output documents. See http://www.alphaworks.ibm.com/tech/xsleditor Object Design's eXcelon Stylus is an XML Integrated Development Environment (IDE) for Windows 95/98/NT that can be used to develop XSLT style sheets compliant with the W3C's specification or with Microsoft's version of XSL supported in Internet Explorer 5. See http://www.odi.com/excelon/Products/ProdMain.htm

DEPLOYING A FILEMAKER PRO XML

SOLUTION

On an intranet where you know that your users surf with Internet Explorer 5.0 or later, you can deploy XML on the client side with reasonable confidence that users will be able to handle what you send them. Unfortunately, well over half of web surfers today are still using 4.x generation or earlier browsers that only support HTML. These browsers have limited ability to handle particular XML documents in special circumstances. In particular, Internet Explorer 4 for Windows can do a passable job of handling XML via JavaScript and the DOM. However, for most practical purposes both Internet Explorer 4.5 and earlier and Netscape Navigator 4.7 and earlier only support HTML. Netscape 5.x and later, Mozilla 5.x and later, and Internet Explorer 5.x and later provide varying levels of support for XML, XSL, and CSS. There are two basic ways to serve XML data to clients. The first is to send the raw XML along with a style sheet that tells the browser how to render the document. This requires that the client application know both XML and the specific style sheet language (and indeed the particular version of the specific style sheet language) you're sending it. The second approach is to have the server apply the style sheet to the XML data to convert into lowest-common-denominator HTML that all browsers understand. Most of the time, CSS is more reliable when you want to send the XML documents themselves to fifth generation browsers because Mozilla, Netscape, and Internet Explorer all support CSS to some degree. However, XSLT is more convenient for server side transformations to HTML because of the much broader availability of tools to handle this. Table 2 below summarizes the level of support for different combinations of XML and style sheets and scripting languages in the common browsers:

Table 2: Browser support for style sheet and scripting languages

18

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

One thing this table indicates is that if your client environment is at all heterogeneous, then the only really plausible solution is to convert to HTML on the server side. Even among fifth generation browsers, Internet Explorer's CSS support is incomplete and Mozilla/Navigator's XSL support is non-existent. In an Intranet situation with homogeneous clients, you may have a few more choices. There are two basic approaches to server side conversion of XML data.The first approach is to put pure XML files on the web server (or in this case, serve them out of a FileMaker Pro database) and have the web server convert those XML documents to HTML before delivering them to browsers. This is most commonly accomplished with Java servlets or ASP.The second approach is to embed a reference to the XML data in HTML files (or an XSL style sheet), along with some instructions to the server about how to replace the data and instructions with HTML before serving it to the client.This is commonly accomplished with ASP,JSP,or PHP.The advantage of this approach is that designers can write all the presentational aspects of the page in normal, familiar HTML.They don't have to learn a new style sheet language just to place a few tables on a page. Figure 11 shows this process using Java Server Pages. The key element in this process is the servlet that knows how to transform the XML FileMaker Pro sends into the HTML the browser reads.This servlet can either operate directly on the XML using a parser, much like the JavaScript and VBScript examples we saw earlier; or it can be a more generic servlet that applies an XSLT style sheet to FileMaker Pro's XML.There are many good, free servlets available to do exactly that including IBM alphaWorks' XML Enabler (http://www.alphaworks.ibm.com/tech/xmlenabler) and James Clark's XSLServlet (http://www.jclark.com/xml/xt.html).

FURTHER READING
For more detailed information and examples of how to serve a FileMaker Pro database as XML, consult the FileMaker Pro Developer's Guide, included with FileMaker Developer 5. An appendix to the Developer's Guide contains a complete list of the query string variables you can use to request XML from a FileMaker Pro database, as well as the exact syntax for the values of these variables. For more information about working with the FileMaker Web Companion, refer to the FileMaker Pro 5 User's Guide, included with FileMaker Pro 5 Unlimited, FileMaker Pro 5 and FileMaker Developer 5. For a detailed specification of the FMPDSORESULT, FMPXMLRESULT, and FMPXMLLAYOUT grammars, you should read the document type definitions for these vocabularies included on the FileMaker Developer 5 CD. This CD also includes a complete XML example that shows an inventory database designed to be run in conjunction with Internet Explorer 5 for Windows.You'll find the necessary files in the FileMaker Pro/Web folder/XML Example folder on your CD.This example is also described in the FileMaker Developer's Guide. There are many web sites on the Internet dedicated to XML.The World Wide Web Consortium (W3C) has taken the lead in standardizing XML and many related technologies like XSL and CSS.You'll find the official specifications for these on their web site at http://www.w3.org/TR/. Some of the most important include:
XML 1.0 Nameplaces in XML XSL Transformations XPath Document Object Model (DOM) Level 1 Cascading Style Sheets Level 2 (one of the most readable specifications) http://www.w3.org/TR/REC-xml
http://www.w3.org/TR/REC-xml-names

htt:p://www.w3.org/TR/xslt http://www.w3.org/TR/xpath http://www.w3.org/TR/REC-DOM-Level-1 http://www.w3.org/TR/REC-CSS2/

Other sites of interest include: xml.com, http://www.xml.com


Ongoing news coverage of developments in XML. Particularly useful here is Tim Bray's Annotated XML Specification that explains both what the somewhat turgid XML specification really means and why it means it.
Figure 11: Java Server pages used to perform server side transformations of XML

19

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

Microsoft XML Developer Center, http://msdn.microsoft.com/xml/default.asp


This site on the Microsoft Developer Network provides detailed information about how XML can be used in Internet Explorer 4 and 5, particularly through XML Data Islands and the DOM. Be warned, however, that this doesn't always clearly distinguish between Microsoft and Internet Explorer specific extensions and standard XML.

GLOSSARY
CDML FileMaker, Inc. proprietary tags for publishing FileMaker Pro data to the Web using custom web publishing. You can now choose to use XML or other APIs such as JDBC or ODBC instead. CSS The simplest and least powerful way to apply style formatting to XML data, for example for display in a browser. See the Technology Previews section on Formatting XML documents for the uses, pros, and cons of this and other formatting methods. DOM -Document Object Model A DOM is the way a browser makes elements in XML documents available to scripting and programming languages, for example for the creation of dynamic web pages. Currently, each browser has its own version of a DOM, but the the World Wide Web Consortium is developing a standard that will make it possible to write programs and scripts that work with any browser on any platform. DTD- document type definition A document containing rules to which all documents and programs involved in a particular project or application of XML must adhere in order to ensure compatibility and consistency. Field names, for example, would be specified in a DTD. An XML document must declare any DTD that it must be validated by. Validation is done by a validating parser (see). FileMaker Pro optionally generates a DTD describing the rules governing each of the three grammars it can publish. meta data Data that describes data; for example, a field name. parser An application (or part of an application) that interprets an XML document so that it can be manipulated or used, for example to display data in a browser. schema The structure of a database, as determined by the database files and fields. The schema is the basis for rules that can be described in a DTD (see). structured data Data that knows what it is and how it is related to other elements around it. Data stored in a table (i.e., a FileMaker Pro file) is structured data. XML data is structured data. In XML data from FileMaker Pro, each piece of data is identified by its field name and is a subset of the data in a particular record. Structured data has the potential to be manipulated and used much more precisely than unstructured data. For example, formatting can be applied to data based on its category.

Cafe con Leche, http://metalab.unc.edu/xml/


Daily news updates about XML software, applications, and specifications as well as links to XML mailing lists, conferences, books, and more.

XMLInfo, http://www.xmlinfo.com/
James Tauber's XMLInfo is a well organized collection of links to XML resources including schemas, style sheets, examples, specifications, software, articles, and more.

The SGML/XML Web Page, http://www.oasisopen.org/cover/xml.html


Robin Cover maintains a huge database of almost every thing anyone or anybody has ever said, done, written, or posted about XML.This massive site includes summaries of and links to W3C XML Working Groups, specifications, schemas, FAQ lists, other web sites about XML, XML applications, articles and books about XML, press releases, mailing lists newsgroups, and more.

OASIS, http://www.oasis-open.org/
OASIS, the Organization for the Advancement of Structured Information Standards, is a nonprofit, international consortium dedicated to standards based, product-independent formats for structured information including XML. Membership in OASIS is open to interested individuals for a reasonable price.

xml-dev, http://www.lists.ic.ac.uk/hypermail/xml-dev/
The xml-dev mailing list is for high-level discussion among people writing software and specifications for XML processing. It's intensely technical.To subscribe, send email to majordomo@ic.ac.uk with the words "subscribe xml-dev you@host.domain" in the body of the message.

XML-L, xml-l@listserv.hea.ie
The XML-L mailing list is a user oriented list for people trying to use existing tools to work with XML documents.To subscribe, send email to listserv@listserv.hea.ie with the words "SUBSCRIBE XML-L your name here" in the message body.

20

TECHNOLOGY OVERVIEW FILEMAKER PRO AND XML

Style sheet A style sheet determines the appearance and formatting of elements in the set of documents that references it. Because XML data contains no information about how information is to be displayed, an XML document can specify a style sheet in order to display its data in a browser. Style sheets can be written using CSS or XSL. See the Technology Previews section on Formatting XML documents for details. valid An XML document is valid according to the rules specified in a DTD (see) if it follows those rules. Validity is determined by a validating parser (see). validating parser An application program (such as the one contained in Microsoft Internet Explorer 5) that evaluates an XML document to be sure it is valid (see). W3C The World Wide Web Consortium, the organization dedicated to standardizing WWW technologies. XSL A language used to write style sheets to format or transform data in XML documents.The most commonly used of its two parts, XSLT, can be used to transform the XML from FileMaker Pro into HTML for display in a browser, or into an agreedupon standard for data exchange. See the Technology Previews section on Formatting XML documents for the uses, pros, and cons of this and other formatting methods. XSLT Part of the XSL formatting language. Use an XSLT style sheet, for example, to transform the XML that FileMaker Pro generates into HTML for display in a browser.

For more information visit the FileMaker XML web site at: http://www.filemaker.com/xml/ which provides additional technical papers, examples, documentation, and links to 3rd party resources. For more information on the FileMaker product family, or to order software, visit www.filemaker.com FileMaker, Inc. 5201 Patrick Henry Drive Santa Clara, CA 95054 http://www.filemaker.com FileMaker Product Family
FileMaker Pro 5
Enables a single user to create, manage and share information and projects in workgroups of up to 10 guests.

FileMaker Server 5
Increase network performance and centralize administration of FileMaker Pro les with up to 250 guests.

FileMaker

Pro 5

FileMaker
Server 5

FileMaker Pro 5 Unlimited


Unlimited sharing of FileMaker les over the Web with built-in support for leading Web servers.

FileMaker Developer 5
Author custom solutions for the Web, FileMaker Pro, or the runtime application (included).

FileMaker

Pro 5 Unlimited

Includes FileMaker Pro

FileMaker

Developer 5

Includes FileMaker Pro

If you use FileMaker Pro 5 with other FileMaker products, those other FileMaker Products must be version 5 or later. Each FileMaker Pro guest requires an additional licensed copy of FileMaker Pro.

ABOUT THE AUTHOR


Elliotte Rusty Harold is an internationally respected writer, programmer, and educator, both on the Internet and off. He lectures about Java and object oriented programming at Polytechnic University in Brooklyn. His Cafe au Lait web site at http://metalab.unc.edu/javafaq has become one of the most popular independent Java sites on the Internet, and his spin-off site Cafe con Leche at http://metalab.unc.edu/xml has become one of the most popular XML sites. He is the author of numerous books, most recently:The XML Bible from IDG and Java I/O from O'Reilly.

2000 FileMaker, Inc. All rights reserved. FileMaker is a trademark of FileMaker, Inc., registered in the U.S. and other countries, and the file folder logo is a trademark of FileMaker, Inc. Portions of some screen shots are reprinted by permission from Microsoft Corporation. Portions of some screen shots are copyright 1996-2000 Netscape Communications Corp. All rights reserved.These screen shots may not be reprinted or copied without the express written permission of Netscape. All other trademarks are the property of their respective owners. Menton of third party products and companies is for informational purposes only and does not constitute an endorsement nor recommendation. Some persons and companies listed in the examples are purely fictitious, and any resemblance to existing persons and companies is purely coincidental. Product specifications and availability subject to change without notice."

21

Das könnte Ihnen auch gefallen