PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
problems reading XML into Flash
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: problems reading XML into Flash

  1. #1
    Senior Member
    Join Date
    Aug 2000
    Location
    Central PA
    Posts
    120

    problems reading XML into Flash

    I have an XML doc that was exported from FileMaker Pro that I need to read into flash to get the variables from. The XML doc is laid out like this (shortened for brevity):

    <FMPXMLRESULT>
    <ERRORCODE>0</ERRORCODE>
    <PRODUCT BUILD="06-20-2006" NAME="FileMaker Pro"/>
    <DATABASE DATEFORMAT="M/d/yyyy"/>
    <METADATA/>
    <RESULTSET FOUND="20">
    <ROW MODID="11" RECORDID="1">
    <COL>
    <DATA>first_bkgd.jpg</DATA>
    </COL>
    <COL>
    <DATA>You are a tutor at the Writing Center.</DATA>
    </COL>
    <COL>
    <DATA>A. "Hi, are you looking for someone?"</DATA>
    </COL>
    <COL>
    <DATA>B. "Hi, sorry to keep you waiting."</DATA>
    </COL>
    <COL>
    <DATA>C. "Is this your first time here?"</DATA>
    </COL>
    </ROW>
    </RESULTSET>
    </FMPXMLRESULT>

    Here is my code to load the XML:

    Actionscript Code:
    var simXML:XML = new XML();
    simXML.ignoreWhitespace = true;
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE,init,false,0,true);
    xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,onIOError,false,0,true);
     
    xmlLoader.load(new URLRequest("sim.xml"));
     
     
    function init(evt:Event):void {
        simXML = XML(xmlLoader.data);
        try {
           for (var i:int=0; i<=5; i++) {
                backgroundArray.push(simXML.firstChild.firstChild.nextSibling.nextSibling.nextSibling.nextSibling.childNodes[i].nodeValue);
         }
        } catch (err:Error) {
            trace("Could not parse loaded content as XML:\n" + err.message);
          }
    }
     
    function onIOError(evt:IOErrorEvent):void {
    trace("An error occurred when attempting to load the XML file.\n"+ evt.text);
    }

    It keeps telling me a term is undefined and has no properties. This I've isolated to the backgroundArray.push statement. Just not sure how to fish the data out of that XML doc properly. What call would I use to iterate thru the different ROW tags to get to the DATA info?
    ?:-{>

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    var simXML:XML = new XML();
    simXML.ignoreWhitespace=true;
    var xmlLoader:URLLoader = new URLLoader();
    xmlLoader.addEventListener(Event.COMPLETE,init,false,0,true);
    xmlLoader.addEventListener(IOErrorEvent.IO_ERROR,onIOError,false,0,true);
    xmlLoader.load(new URLRequest("sim.xml"));
    var backgroundArray:Array = new Array();
    function init(evt:Event):void {
    	simXML=XML(xmlLoader.data);
    	try {
    		for (var i in simXML.RESULTSET.ROW.COL) {
    			trace(simXML.RESULTSET.ROW.COL[i].elements("DATA"));
    			backgroundArray.push(simXML.RESULTSET.ROW.COL[i].elements("DATA"));
    		}
    	} catch (err:Error) {
    		trace("Could not parse loaded content as XML:\n" + err.message);
    	}
    }
    function onIOError(evt:IOErrorEvent):void {
    	trace("An error occurred when attempting to load the XML file.\n"+ evt.text);
    }

  3. #3
    Senior Member
    Join Date
    Aug 2000
    Location
    Central PA
    Posts
    120
    Thanks, dawsonk. That works great. Funny thing was that it would not load when I tried to load the actual XML doc, but it would if I made an XML doc out of the sample XML code I had listed above. I tracked it down to the attribute on the <FMPXMLRESULT> tag, which actually looks like this on the real XML doc:

    <FMPXMLRESULT xmlns="http://www.filemaker.com/fmpxmlresult">

    For some reason the xmlns attribute would not allow it to load. So I just need to delete that I guess.

    Thanks again, dawsonk!
    ?:-{>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center