dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Data extraction problem

  1. #1
    Junior Member
    Join Date
    Jun 2005
    Posts
    8

    Data extraction problem

    Hi board,

    I am trying to extract data from an xml with flash mx 2004. Here is the last event entry.
    Why is it only outputting the id 90? It seems not to care about the second for statement.

    PHP Code:
    <events>
    </
    event>
    ...
    </
    event>
    ...
    <
    event>
    <
    title  id="90">blah</title>
    <
    city>Düsseldorf</city>
    <
    start>2005-11-25</start>
    <
    end>2005-11-26</end>
    <
    referent>DrHans Wurst</referent>
    </
    event>
    </
    events
    Code:
    stop();
    var events:Array = new Array();
    var xmlEvents:XML;
    loadEvents();
    
    function loadEvents():Void {
            xmlEvents = new XML();
            xmlEvents.ignoreWhite = true;
            xmlEvents.onLoad = function(bSuccess:Boolean) {
                    if(bSuccess) {
                            var xnEvents:XMLNode = this.firstChild;
                            for (var i:Number = 0; i < xnEvents.childNodes.length; i++) {
                                    events[i]['id'] =    this.firstChild.childNodes[i].firstChild.attributes.id;
                                    events[i]['title'] = this.firstChild.childNodes[i].firstChild.firstChild.nodeValue;
                                    events[i]['city'] =  this.firstChild.childNodes[i].nextSibling.firstChild.nodeValue;
                                    events[i]['start'] = this.firstChild.childNodes[i].nextSibling.firstChild.nodeValue;
                                    events[i]['end'] =   this.firstChild.xnEvents.childNodes[i].nextSibling.firstChild.nodeValue;
                                    events[i]['referent'] = this.firstChild.childNodes[i].nextSibling.firstChild.nodeValue;
                                    events[i]['moreInfo'] = this.firstChild.childNodes[i].nextSibling.firstChild.nodeValue;
                                    _root.main.mc_events.txt_events.htmlText = this.firstChild.childNodes[i].firstChild.attributes.id;
                            }
                            
                            for (var i:Number = 0; i < events.length; i++) {
                                    _root.main.mc_events.txt_events.htmlText =  "Datum: " + events[i]['start'] + " - " + events[i]['end'] + "<br>" + events[i]['title'] + "<br>" + events[i]['city'] + "<br>";
                            }
                    } else {
                            _root.main.mc_events.txt_events.htmlText = "Das gibt es ein Problem.";
                    } // end of else
            }; //end .onload
            xmlEvents.load("/de/aktuelles/php/courses.php");
    }// end of function

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try this...

    Just inside the first FOR loop, add:
    Code:
    events[i]= new Array();

  3. #3
    Junior Member
    Join Date
    Jun 2005
    Posts
    8
    Still no luck: It is outputitng "undefined" for those variables. I have been working on this for 2 straingt day. Please could anbody with Flash/XML experience look into this?

    Code:
    stop();
    var events:Array = new Array();
    var xmlEvents:XML;
    loadEvents();
    
    function loadEvents():Void {
        xmlEvents = new XML();
        xmlEvents.ignoreWhite = true;
    	xmlEvents.onLoad = function(bSuccess:Boolean) {
    		if(bSuccess) {
                var xnEvents:XMLNode = xmlEvents.firstChild;
    			_root.main.mc_events.txt_events.text = xnEvents.childNodes.length;
    			for (var i:Number = 0; i < xnEvents.childNodes.length; i++) {
    				events[i] = new Array();
    				events[i]["id"] =  xnEvents.firstChild.childNodes[i].firstChild.attributes.id;
    				events[i]["eventtitle"] = xnEvents.firstChild.childNodes[i].firstChild.firstChild.nodeValue;
    				events[i]["city"] =  xnEvents.firstChild.childNodes[i].nextSibling.firstChild.nodeValue;
    				events[i]["startdate"] = xnEvents.firstChild.childNodes[i].nextSibling.firstChild.nodeValue;
    				events[i]["enddate"] =   xnEvents.firstChild.childNodes[i].nextSibling.firstChild.nodeValue;
    				events[i]["referent"] = xnEvents.firstChild.childNodes[i].nextSibling.firstChild.nodeValue;
    	            events[i]["moreInfo"] = xnEvents.firstChild.childNodes[i].nextSibling.firstChild.nodeValue;
    			}
    
    			for (var i:Number = 0; i < events.length; i++) {
    				_root.main.mc_events.txt_events.htmlText =  events[i]["id"] + "Datum: " + events[i]["startdate"] + " - " + events[i]["enddate"] + "<br>" + events[i]["eventtitle"] + "<br>" + events[i]["city"] + "<br>";
    			}
        	} else {
    			_root.main.mc_events.txt_events.htmlText = "Da gibt es ein Problem.";
    		} // end of else
    	}; //end .onload
    	xmlEvents.load("/de/aktuelles/php/courses.xml");
    }// end of function
    PHP Code:
    events>
    <
    event>
    <
    city>Dresden</city>
    <
    start>2005-07-15</start>
    <
    end>2005-07-16</end>
    <
    referent>DrS K</referent>
    </
    event>

    <
    event>
    <
    city>Dresden</city>
    <
    start>2005-07-15</start>
    <
    end>2005-07-16</end>
    <
    referent>DrS K</referent>
    </
    event>

    <
    event>
    <
    city>Erfurt</city>
    <
    start>2005-08-19</start>
    <
    end>2005-08-20</end>
    <
    referent>DrS K</referent>
    </
    event>
    </
    events

  4. #4
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe try this...

    Code:
    stop();
    var events:Array = new Array();
    xmlEvents = new XML();
    xmlEvents.ignoreWhite = true;
    xmlEvents.load("samp.xml");
    xmlEvents.onLoad = function(bSuccess:Boolean) {
    	if (bSuccess) {
    		var xnEvents:XMLNode = this.firstChild;
    		var tmp:XMLNode;
    		for (var i = 0; i < xnEvents.childNodes.length; i++) {
    			events[i] = new Array();
    			tmp = xnEvents.childNodes[i].firstChild;
    			events[i]['id'] = tmp.attributes.id;
    			events[i]['title'] = tmp.firstChild.nodeValue;
    			tmp = tmp.nextSibling;
    			events[i]['city'] = tmp.firstChild.nodeValue;
    			tmp = tmp.nextSibling;
    			events[i]['start'] = tmp.firstChild.nodeValue;
    			tmp = tmp.nextSibling;
    			events[i]['end'] = tmp.firstChild.nodeValue;
    			tmp = tmp.nextSibling;
    			events[i]['referent'] = tmp.firstChild.nodeValue;
    			tmp = tmp.nextSibling;
    			events[i]['moreInfo'] = tmp.firstChild.nodeValue;
    			_root.main.mc_events.txt_events.htmlText = events[i]['id'];
    			trace(events[i]['id']);
    		}
    		for (var i = 0; i < events.length; i++) {
    			_root.main.mc_events.txt_events.htmlText = "Datum: "+events[i]['start']+" - "+events[i]['end']+" "+events[i]['title']+" "+events[i]['city']+" ";
    			trace("Datum: "+events[i]['start']+" - "+events[i]['end']+" "+events[i]['title']+" "+events[i]['city']+" ");
    		}
    	} else {
    		_root.main.mc_events.txt_events.htmlText = "Das gibt es ein Problem.";
    	}
    	// end of else
    };
    // end of function
    I made an XML file using this and called it 'samp.xml'.
    PHP Code:
    <events>
    <
    event>
    <
    title id="90">Title 1</title>
    <
    city>Dresden</city
    <
    start>2005-07-15</start
    <
    end>2005-07-16</end
    <
    referent>DrS K</referent
    </
    event
    <
    event>
    <
    title id="91">Title 2</title>
    <
    city>Dresden</city
    <
    start>2005-07-15</start
    <
    end>2005-07-16</end
    <
    referent>DrS K</referent
    </
    event
    <
    event>
    <
    title id="92">Title 3</title>
    <
    city>Erfurt</city
    <
    start>2005-08-19</start
    <
    end>2005-08-20</end
    <
    referent>DrS K</referent
    </
    event
    </
    events

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