2 Replies Latest reply on Apr 9, 2009 3:12 PM by iSyndicate

    Populating ComboBox with XML data

    iSyndicate

      Hi there,

       

      Probably the most basic question, but I'm having a hard time with this...

       

      Trying to populate the ComboBox with XML data as a dataProvider.

       

      Here is the code snippet:

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
                      layout="vertical"
                      creationComplete="baseDataRequest.send()">
          <mx:Script>
              <![CDATA[
                  import mx.collections.XMLListCollection;
                  import mx.rpc.events.ResultEvent;
      
                  [Bindable]
                  private var baseDataXML:XML;
      
                  private function baseResultHandler(event:ResultEvent):void
                  {
                      baseDataXML = event.result.node.child as XML;
                  }
              ]]>
          </mx:Script>
      
          <mx:HTTPService id="baseDataRequest"
                          useProxy="false"
                          resultFormat="e4x"
                          result="baseResultHandler(event)"
                          url="XML_URL"/>
      
          <mx:ComboBox id="comboDemo"
                       width="390"
                       dataProvider="{baseDataXML}"
                       labelField="NodeName"/>
      </mx:Application>
      

       

      And that returns nothing, basically. I know the XML is being pulled, because if I do this:

      baseDataXML = event.result as XML;

       

      then I just see a single item in my ComboBox, with full XML content.

       

      How do I populate the ComboBox with XML contents?

       

      XML example:

       

      <root>
          <node>          <child>Child1</child>
                <child>Child2</child>
           </node>
      </root>
      

       

      Question: how do I populate the ComboBox with XML data nodes? I need <child> content to be the labelField of each combo box item...

       

      Thanks!

       

      K

        • 1. Re: Populating ComboBox with XML data
          Brent Lamborn Level 2
               <mx:Script>
                    <![CDATA[
                         var baseDataXML:XML = <root><node><child>Child1</child><child>Child2</child></node></root>;
                    ]]>
               </mx:Script>
               <mx:ComboBox id="comboDemo"
                           width="390"
                           dataProvider="{baseDataXML.node.child}"
                           labelField="NodeName"/>
          

           

          Don't do:

           

          baseDataXML = event.result.node.child as XML;
          
          

           

          Instead just do:

           

          baseDataXML = XML(event.result);
          
          

           

          And in your combo:

           

          dataProvider="{baseDataXML.node.child}"
          

          • 2. Re: Populating ComboBox with XML data
            iSyndicate Level 1

            Thanks for your reply!

             

            Apparently, the problem I was having was related to namespaces... I had a namespace declaration in the root node of my XML and it was breaking the whole thing. Once that is no longer there - problem is gone!