Groups | Blog | Home
all groups > flash data integration > may 2007 >

flash data integration : FileMaker XML data problems


Raymond Basque
5/17/2007 12:41:46 PM
The text inside the <DATA></DATA> node is inside an invisible text node. You
need to add one more .firstChild


On another note, you might want to take a look at the mx.xpath.XPathAPI
class.

http://download.macromedia.com/pub/documentation/en/flash/fl8/XpathAPI.pdf

It's a very XPath implementation, but will save you from having to use that
ugly firstChild.firstChild.nextSibling.nextSibling.etc... nonsense.

Raymond Basque
5/17/2007 12:44:25 PM
Meant to say "It's a very BASIC XPath implementation,..."

pbesong
5/17/2007 2:46:21 PM
I'm a bit of a newbie to getting data from XML into Flash, but I'm seeing that
this is going to be very important to future projects that I work on. I am
using FileMaker Pro (currently version 7, but upgrading to 8) to create a
database and exporting XML file from there to read into Flash. I cannot seem to
get the data from the XML to show up in the Flash movie. I have been following
a tutorial on Lynda.com on Flash/FileMaker integration, but the XML file
doesn't look quite the same. Here is the XML data I get when exporting from
FileMaker:

<FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">
<ERRORCODE>0</ERRORCODE>
<PRODUCT BUILD="05-06-2004" NAME="FileMaker Pro" VERSION="7.0v2"/>
<DATABASE DATEFORMAT="M/d/yyyy" LAYOUT="RecRev"
NAME="Penn.State.On.The.Air.fp7" RECORDS="1" TIMEFORMAT="h:mm:ss a"/>
<METADATA>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="PersonNam" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ProgramNam" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="PersonBio" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="ProgramDesc" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="AudioName" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="VideoNam" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="Notes" TYPE="TEXT"/>
<FIELD EMPTYOK="YES" MAXREPEAT="1" NAME="LastUpdate" TYPE="DATE"/>
</METADATA>
<RESULTSET FOUND="1">
<ROW MODID="1" RECORDID="1">
<COL><DATA>Fran Fisher</DATA></COL>
<COL><DATA>TV Quarterbacks (1965-1985)</DATA></COL>
<COL><DATA>One of the classic voices of Penn State Athletics, Fran Fisher has
called football and basketball on the radio, as well as hosted several Penn
State-related programs on both television and radio. Beginning in 1966, Fisher
hit the airwaves providing color commentary on football radiocasts. A year
later, he joined the crew of WPSX-TV???s TV Quarterbacks, to narrate game films
and was made a co-host in 1968???a post he retained until the show???s end in
1984. After three years of doing football color work on the radio, he was
shifted to play-by-play duties. In this role he became the voice of Penn State
Football and provided a steady presence in the booth through the 1982 National
Championship season.
</DATA></COL>
<COL>
<DATA>The first television program to focus on Penn State Football, TV
Quarterbacks was the brainchild of WPSX-TV general manager Marlowe Froke.
Debuting in 1965, and initially titled Wednesday Quarterbacks, the show was
hosted by Harris Lipez and Ken Holderman and included commentary from Coach Rip
Engle.
</DATA>
</COL>
<COL>
<DATA>
</DATA>
</COL>
<COL>
<DATA>
</DATA>
</COL>
<COL>
<DATA>
</DATA>
</COL>
<COL>
<DATA>3/23/2007</DATA>
</COL>
</ROW>
</RESULTSET>
</FMPXMLRESULT>


I've tried many iterations of the combination of firstChild and sibling, but I
either get NULL, UNDEFINED, or a blank text area where the PersonNam and
PersonBio data should go. Here is the Actionscript I'm using to load the data:

myXML = new XML();
xmlFile = "fmp.xml"
myXML.load(xmlFile);
function myOnLoad () {
PersonNam =
myXML.firstChild.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.firs
tChild.firstChild.firstChild.nodeValue;
PersonBio =
myXML.firstChild.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.firs
tChild.firstChild.nextSibling.firstChild.firstChild.nodeValue;
}
myXML.onLoad = myOnLoad;

I think I just don't understand XML well enough to get the right data path. It
confuses me that the data in the XML file looks different than what I saw on
the tutorial.
pbesong
5/17/2007 4:13:02 PM
Okay, I'm getting close...I changed the code to load the XML file and by doing
a trace:

trace
(this.firstChild.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.firs
tChild.firstChild.firstChild);

I am getting: " <DATA>Fran Fisher</DATA>"
but if I try to tack ".nodeValue" onto the trace I get NULL.

How do I adjust the call to get just "Fran Fisher" ?

pbesong
5/17/2007 5:19:28 PM
pbesong
5/20/2007 1:32:34 AM
I looked over that PDF and started messing around with XPath. Although it took
a bit of experimentation, I was able to get the info I wanted from my XML file
with the following code:

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...");

path = "/FMPXMLRESULT/RESULTSET/ROW/COL/DATA";
// Make an array of all the data
arNodes = mx.xpath.XPathAPI.selectNodeList(this.firstChild, path);

// Display first and second names on screen as a test
fname = arNodes[0].firstChild;
lname = arNodes[8].firstChild;

path2 = "/FMPXMLRESULT/RESULTSET/ROW";
// Make an array of just the people's names now
namNodes = mx.xpath.XPathAPI.selectNodeList(this.firstChild, path2);

trace(namNodes[0].firstChild.firstChild.firstChild);

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

I think I may go the XPath route for my kiosk project. This looks quite a bit
easier than dealing with the confusing and endless firstChild iterations.
Thanks again for suggesting this, Raymond!
AddThis Social Bookmark Button