1 Reply Latest reply on Jul 23, 2010 2:03 AM by webqaflash

    Getting value from xml

    mrgoodguy_in

      Need help in getting value from xml
      I am able to get the node values from the xml into my flash.

       

      sample xml file:

       


      <quiz>
          <questions>
              <question>Q1 text?</question>
              <option1>option 1 text</option1>
              <option2>option 2 text</option2>
              <option3>option 3 text</option3>
              <option4>option 4 text</option4>
              <correct>3</correct>
          </questions>
          <questions>
              <question>Q2 text?</question>
              <option1>option 1 text</option1>
              <option2>option 2 text</option2>
              <option3>option 3 text</option3>
              <option4>option 4 text</option4>
              <correct>2</correct>
          </questions>
      </quiz>

       


      I am able to assign the questions to text fields in flash using the code:
          q1 = xmlobj.childNodes[0].childNodes[0].childNodes[0];

       

      but not able to assign the value of the tag <correct></correct> to a variable

       

      thanks in advance

        • 1. Re: Getting value from xml
          webqaflash Level 3

          var datas:XML = new XML();
          datas.load("test.xml");
          datas.ignoreWhite = true;

           

          datas.onLoad = function(success:Boolean) {
              trace(success);

           

              if (success) {

           

                  var datasToXMLString:String = new String();
                  datasToXMLString = datas.toString();

           

                  var datasXML:XML = new XML(datasToXMLString);
                  datasXML.parseXML(datasToXMLString);
                  trace(datasXML);
                  var datasNodes:Object = datasXML.firstChild;
                  var datasNodesChildren:Object = datasNodes.childNodes;
                  trace("-----------------------");
                  trace(datasNodes.childNodes[0].childNodes[5].firstChild);//3
              }
          };