More on FileMaker Pro, XML, and XPath

| | Comments (1)

In my initial zeal to export XML from FileMaker Pro, I found that the first choice of XML grammar types, FMPXMLRESULT, is not the best choice. What it does is to make a generic formatting of the field names so that all the data comes from a ROW/COL/DATA path. This is not real helpful if you're going to be using XPath. You would still end up using a lot of firstChild.nextSibling iterations in addressing your info.

What you need to do when exporting from FileMaker Pro is to choose XML from the pulldown menu, then for the Grammar type, choose FMPDSORESULT. When you go to save it, make sure that you check "Apply current layout's data formatting to exported data" at the bottom of the window. This way, instead of getting generic ROW/COL/DATA structure, the data will be enclosed by the names of the respective fields. I'll explain more in a moment.

Once the XML file is exported from FileMaker, it can be opened in a text editor (I use BBEdit). What is not good, however, is that the XML file is not indented neatly, but just kind of jumbled all together. Not sure if there is a better way to correct this, but I downloaded a demo copy of Oxygen, which is an XML editor for the Mac. After dragging my XML file to the main window, I clicked the "Format and Indent" button and magically my jumble of text became a neatly organized and indented XML file like I'm used to seeing. GREAT! I think Oxygen costs about $48 educational, so I may get our department to spring for this after the 30 day trial is up.

Moving on to Flash, I'm now going to redo what I blogged about last time. This time you'll see the beauty of how XPath can get you to your data without anyone getting hurt.

// Starting the same as last time...

import mx.xpath.XPathAPI;
var my_xml:XML = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success:Boolean) {
trace("onload...");
if (success) {
trace("success...");

// Now instead of setting the path to this like I did previously...
// path = "/FMPXMLRESULT/RESULTSET/ROW/COL/DATA";

// I can set it directly to this to find all the backgrounds in each record
path = "/FMPDSORESULT/ROW/BACKGROUND"
arrayBackgrounds = mx.xpath.XPathAPI.selectNodeList(this.firstChild, path);

// and set my first background to the first one it finds...
background_img = arrayBackgrounds[0].firstChild;
// so in my second FMP record the background_img would be "arrayBackgrounds[1].firstchild"

// I can then make a new path and point it to the fields called "DESCRIPTION"...
path2 = "/FMPDSORESULT/ROW/DESCRIPTION";
arrayDescriptions = mx.xpath.XPathAPI.selectNodeList(this.firstChild, path2);

// and set my first description variable to the first record it finds...
description = arrayDescriptions[0].firstChild;

} else {
trace("error loading XML");
}
};
my_xml.load("simulation.xml");

stop();

Okay, so each "ROW" in my XML file represents an individual record in FileMaker Pro. Each record in my simulation database will include such info as the background image, the scene title, scene description, the question to be asked, and each of the four choices you might get on that scene. There would also be a destination for each choice that would make you go to that scene should you choose that particular choice. We could also include points for each choice and feedback among other things.

BTW, I actually got the crude demo Flash file from Hershey and am pretty excited to start this project. It became apparent right away that I will need a good flow diagram of the scenes to know what to create and where things will go. Still, it looks very doable, especially since I have a leg up on the data end of things.

1 Comments

Cole said:

Would you be interested in sharing any Hershey details at the all staff meeting tomorrow? Might be good for others to see what you are up to with them!

Leave a comment

About this Entry

This page contains a single entry by PATRICK JOSEPH BESONG published on May 21, 2007 9:35 PM.

XPath - A very cool way to do XML data in Flash was the previous entry in this blog.

Baby steps and planning is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.24-en