4 Replies Latest reply on Sep 6, 2009 8:44 PM by aaravind

    xml data in combobox

    aaravind Level 1

      What i want is ,,,,,,,i have an xml of this type,,,

      <?xml version="1.0" encoding="UTF-8"?>
      <userslist>
       
        <user>
          <name>aravind</name>
        </user>
      <user>
          <name>aravind1</name>
        </user>
        <user>
          <name>aravind2</name>
        </user>
        <user>
          <name>aravind3</name>
        </user>
      </userslist>

       

       

      I want tis to be listed in a combo box,,(drop down)..I was able to do it by this loop

      for(i=0;i<http.lastResult.userslist.user.length;i++)               
                          temp[i]=htp.lastResult.userslist.user[i].name;
                      comb.dataProvider=temp;

       

       

      But the problem is if i have only one entry in the xml iam not gettin it in the drop down,,,tat time the size is http.lastResult.userslist.user.length is undefined....if i have 2 or more entries in the xml the length shown is correct..

       

      PLS help

        • 1. Re: xml data in combobox
          leybniz Level 4

          wrong loop my friend, use this one:

           

          var xml:XML = http.lastResult as XML;

          for each (var userNode:XML in xml..user) {

               temp[i] = userNode.name;

          }

          • 2. Re: xml data in combobox
            sergei_developer Level 1

            I think it will be good way for you:

            <mx:ComboBox id="comboBox"
                        prompt="Please select a State..."
                        dataProvider="{myXML}"
                        labelField="user.name" />


            var myXML:XMl = <?xml version="1.0" encoding="UTF-8"?>
            <userslist>
             
              <user>
                <name>aravind</name>
              </user>
            <user>
                <name>aravind1</name>
              </user>
              <user>
                <name>aravind2</name>
              </user>
              <user>
                <name>aravind3</name>
              </user>
            </userslist>

            and I think correct xml will be like this
            <user name ="aravind"/>
            <user name ="aravind1"/>
            <user name ="aravind2"/>
            <user name ="aravind3"/>

            then :
            <mx:ComboBox id="comboBox"
                        prompt="Please select a State..."
                        dataProvider="{myXML}"
                        labelField="@name" />






            • 3. Re: xml data in combobox
              Gregory Lafrance Level 6

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

               

              You should use HTTPService:

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                creationComplete="dataRequest.send();">
                <mx:Script>
                  <![CDATA[
                    import mx.rpc.events.ResultEvent;
                    import mx.collections.XMLListCollection;
                   
                    [Bindable] private var dataXLC:XMLListCollection;
                   
                    private function dataHandler(evt:ResultEvent):void{
                      dataXLC = new XMLListCollection(evt.result..user.name as XMLList);
                    }
                  ]]>
                </mx:Script>
                <mx:HTTPService id="dataRequest" result="dataHandler(event)"
                  resultFormat="e4x" url="data.xml"/>
                <mx:ComboBox dataProvider="{dataXLC}"/>
              </mx:Application>

              • 4. Re: xml data in combobox
                aaravind Level 1

                I got the solution.....but by a different way,,,I used the same loop as mentioned in the first post..

                The problem was lastresult.length wont take 1 as a value if only one entry is ter in the xml(it shows undefined)...so i just wrote a code snippet to read the single content if the length!=2 or >2

                 

                Thanks 4 all the help....,,,,