1 Reply Latest reply on May 19, 2011 2:29 AM by Peter Blazejewicz

    Convert XML String into Array Collection

    194642537

      Hi All,

       

         I have an xml string

       

         <tags>

             <tag>

                  <fn>fname1</fn>

                   </ln>lname1</ln>

              </tag>

                 <tag>

                  <fn>fname2</fn>

                   </ln>lname2</ln>

              </tag>

         </tags>

       

        I wanted to build a datagrid with the values from <tag>.

       

        Can anybody help me with this?

       

        Any help or suggestions is highly appreciated.

       

      Thanks

        • 1. Re: Convert XML String into Array Collection
          Peter Blazejewicz Level 4

          Hi,

           

          there could be many different ways to do that. The main point is that you can obtain reference to your XML by casting data into XML object or creating it directly, etc,

          Here is some basic example:

           

           

          <fx:Script>

               <![CDATA[

          import mx.collections.XMLListCollection;

          //

          [Bindable]

                    private var xmlListCollection:XMLListCollection = null;

                    //

                    private var tagsXML:XML = <tags>

                                                                      <tag>

                                                                             <fn>fname1</fn>

                                                                              <ln>lname1</ln>

                                                                        </tag>

                                                                           <tag>

                                                                             <fn>fname2</fn>

                                                                              <ln>lname2</ln>

                                                                        </tag>

                                                                      </tags>

                    //

                    protected function initApp():void

                    {

                         xmlListCollection = new XMLListCollection(this.tagsXML.tag);

                    }

                   

               ]]>

          </fx:Script>

          <s:DataGrid x="10" y="10" width="100%" dataProvider="{xmlListCollection}"

                         requestedRowCount="{xmlListCollection.length}">

               <s:columns>

                    <s:ArrayList>

                         <s:GridColumn dataField="fn" headerText="First Name"></s:GridColumn>

                         <s:GridColumn dataField="ln" headerText="Last Name"></s:GridColumn>

                    </s:ArrayList>

               </s:columns>

          </s:DataGrid>

           

           

           

          regards,

          Peter Blazejewicz