3 Replies Latest reply on Aug 16, 2009 4:55 AM by Gregory Lafrance

    How to use a variable to navigate through XML data

    ice1000 Level 1

      My chart has xml data that looks like this:

       

      <getViewResponse>

         <getViewResult>

            <DocumentElement>

               <ColumnChart>

                  <Month>

                     "Dec"

                  <NetIncome>

                     1000

               <ColumnChart>

      etc.

      etc.

       

      the following lines in actionscript work perfectly to feed the chart:

       

      resultxml = event.result.getViewResult.DocumentElement.ColumnChart as XMLList

      //chart data provider

      _chartDP = new XMLListCollection(resultxml);

       

      The last Colum Chart argument in DocumentElement.ColumnChart is going to change. I want to make this a variable instead.

       

      I tried DocumentElement+'.'+this.[ColumnChart] but I get an error telling me the property does not exist.

       

      The following almost works:

      event.result.getViewWithTitlesResult.DocumentElement.*

       

      but my chart has an empty extra data series.

       

      How can I set that last element to a variable?

        • 1. Re: How to use a variable to navigate through XML data
          Gregory Lafrance Level 6

          How about this:

           

          var myVar:XML = _chartDP.getItemAt(_chartDP.length-1);

           

          If this post answers your question or helps, please mark it as such.

          • 2. Re: How to use a variable to navigate through XML data
            ice1000 Level 1

            I couldn't get your code to work. I got an error about implicit coercion not working.

             

            I have more info on my problem though. I browsed through the xml and it actually looks something like this:

             

            <ColumnChart>
               <Month>2006</Month>
               <NetIncome>-7393046.28695399</NetIncome>
            <ColumnChart>
            <ColumnChart>
               <Month>2007</Month>
               <NetIncome>77801003.0915078</NetIncome>
            <ColumnChart>

            <Info>
               <Table>Finance</Table>
               <View>ColumnChart</View>
            </Info>

             

            The chart is actually graphing the correct data set. I just happen to have an extra node in my XMLList. I researched and founf a function to remove a node from an XMLList.

             

            private function removeNode(node:XML):void {
              var cn:XMLList = XMLList(node.parent()).children();
              for (var i:Number=0;i<cn.length();i++) {
                if (cn[i]==node) {
                  delete node[i];
                }    
              }
            }

             

            I think this will work but in my original code my xml is an XMLList type. The above funtion is expecting a XML datatype.

             

            How do I extract the Info node as XML from an XMLList so I can pass it to the function?

             

            Thanks!

            • 3. Re: How to use a variable to navigate through XML data
              Gregory Lafrance Level 6

              If the data you currently say is XMLList has just one item, just cast to XML with XML(myXMLLIST) or "myXMLLIST as Xml".

               

              If this post answers your question or helps, please mark it as such.