• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to import XML data?

Explorer ,
Mar 11, 2010 Mar 11, 2010

Copy link to clipboard

Copied

Please explain with examples

regards

spvr

TOPICS
ActionScript

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Mar 11, 2010 Mar 11, 2010

For example you have an XML file of name "myxml.xml" inside the same directory of your fla with the following contents:

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

<myrootnode>

   <mychildnode id="1">Something111</mychildnode>

   <mychildnode id="2">Something222</mychildnode>

</myrootnode>

//
//You can load it through the URLLoader class:

var cXmlLoader:URLLoader = new URLLoader();

var cUrlReq:URLRequest = new URLRequest("myxml.xml");

cXmlLoader.addEventListener(Event.COMPLETE, onXmlLoad);

cXmlLoader.load(cUr

...

Votes

Translate

Translate
Advocate ,
Mar 11, 2010 Mar 11, 2010

Copy link to clipboard

Copied

For example you have an XML file of name "myxml.xml" inside the same directory of your fla with the following contents:

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

<myrootnode>

   <mychildnode id="1">Something111</mychildnode>

   <mychildnode id="2">Something222</mychildnode>

</myrootnode>

//
//You can load it through the URLLoader class:

var cXmlLoader:URLLoader = new URLLoader();

var cUrlReq:URLRequest = new URLRequest("myxml.xml");

cXmlLoader.addEventListener(Event.COMPLETE, onXmlLoad);

cXmlLoader.load(cUrlReq);

function onXmlLoad(oEvent:Object):void

{

   XML.ignoreWhitespace = true;

   var cXmlData:XML = new XML(oEvent.target.data);

   trace(cXmlData.mychildnode[0]);

   trace(cXmlData.mychildnode[1]);

}

If you had more child nodes under each of the child nodes then you could access them by simple dot notation using their node names.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 12, 2010 Mar 12, 2010

Copy link to clipboard

Copied

Adobe Forum (but i think YOU) wrote:

thanks harry.
i have a another problem with xml data load if i use class.
please check following code

package {
    import flash.xml.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.errors.IOError;
    import flash.events.IOErrorEvent;
    import flash.display.MovieClip;
   
    public class xmldata {

        public var loader:URLLoader = new URLLoader();
   
        public function xmldata() {
            loader_fun();

        }
       
        private function loader_fun(){
        loader.addEventListener(Event.COMPLETE, onLoadXML);
            loader.load(new URLRequest("carData.xml"));
        }
           
            public function onLoadXML(ev:Event) {
            try {
               
                var myXML:XML = new XML(ev.target.data);
                trace(myXML);
            } catch (e:TypeError) {
               
                trace("Could not parse the XML");
                trace(e.message);
            }
        }
    }
}

Hey, something weird just happened. I received your reply but instead of your display name, it was "Adobe Forums <forums@adobe.com>", that's weird. Anyway. I don't see any problem with your code. It works fine in my setup. Just make sure your file has the same name as the class name "dataxml" and it is in the same directory as your fla and use this code in the fla:
import xmldata;
var cXmlData:xmldata = new xmldata();
I receive the trace of the xml content. Are there any errors you received?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 30, 2011 Mar 30, 2011

Copy link to clipboard

Copied

LATEST

you can try this example.it uses URLLoader in flex to extract XML data

http://flexparsexml.blogspot.com/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines