9 Replies Latest reply on Aug 19, 2013 7:06 PM by Anne0829

    Error1009 when convert XMLList to XMLListCollection

    Anne0829

      I want to convert a XML to ArrayCollection. So I convert the XML to XMLList, then XMLList to XMLListCollection, then XMLListCollection to Array, and finally Array to ArrayCollection. Please see my code below:

       

      var nodexml:XML;

                                              var searchData:XMLList;

                                              var countriesXML: XMLListCollection;

                                              var countriesArray:Array;

      var sourceModel:ArrayCollection;

                                              nodexml= new XML(xmlLoader.data);

                                              searchData = new XMLList(nodexml.elements("node"));

                                              countriesXML= new XMLListCollection(searchData);

                                              countriesArray = new Array(countriesXML.toArray());

                                              sourceModel= new ArrayCollection(countriesArray);

       

      my sample XML is as below:

      <root>

      <node>Afghanistan</node>

      <node>Algeria</node>

      <node>Bahamas</node>

      <node>Cambodia</node>

      <node>Democratic</node>

      </root>

       

      Error 1009 occurs in this statement:  countriesXML= new XMLListCollection(searchData);

       

      I tried many times and I don't know how to solve this issue. I insert watch expressions and found no data is read in this statement. the previous two statements run successfully.

       

      Could anyone help me out for this? Thanks a million in advance!

        • 1. Re: Error1009 when convert XMLList to XMLListCollection
          Flex harUI Adobe Employee

          Try:

           

           

                                                  searchData = nodexml.elements("node");

           

          Accessing XML generally returns an XMLList.

           

          If that doesn't work, post the full text of the error including stack trace.

           

          -Alex

          • 2. Re: Error1009 when convert XMLList to XMLListCollection
            Anne0829 Level 1

            Thank you very much! The error is gone during my debugging, but there is still no content for countriesXML after countriesXML= new XMLListCollection(searchData); Please see my expressions values as below when I'm debugging it:

             

            nodexml=:

            <root>

              <node>

                Afghanistan

              </node>

              <node>

                Algeria

              </node>

              <node>

                Bahamas

              </node>

              <node>

                Cambodia

              </node>

              <node>

                Democratic

              </node>

            </root>

             

            searchData=:

            <node>

              Afghanistan

            </node>

            <node>

              Algeria

            </node>

            <node>

              Bahamas

            </node>

            <node>

              Cambodia

            </node>

            <node>

              Democratic

            </node>

             

            countriesXML=:

            mx.collections.XMLListCollection (@12d1ae09)

             

            countriesArray=:

            [ ] (@12cafdd1)

             

            sourceModel=:

            mx.collections.ArrayCollection (@12d1afc9)


            • 3. Re: Error1009 when convert XMLList to XMLListCollection
              Anne0829 Level 1

              I also try to modify countriesXML= new XMLListCollection(searchData) to countriesXML.source= searchData then the 1009 error pop up again

               

              at flash.events::EventDispatcher/dispatchEventFunction()

                        at flash.events::EventDispatcher/dispatchEvent()

                        at flash.net::URLLoader/onComplete()

              • 4. Re: Error1009 when convert XMLList to XMLListCollection
                Flex harUI Adobe Employee

                What is countries.length?  Is it 0 or the right number?

                 

                Your XML has text elements in the node elements, and Flex DataGrids and maybe other components won't handle that very well.

                 

                -Alex

                • 5. Re: Error1009 when convert XMLList to XMLListCollection
                  Anne0829 Level 1

                  Thanks a lot! I've tested the length of countriesXML and countriesArray, they are both 5, not 0.

                   

                  yes, my XML has text elements and I'm trying  to convert them into a Array. I didn't use DataGrid before I convert the XML into an Array. But I truly did use DataGrid after it's converted successfully if possible. Could you explain to me what do you mean by "Flex DataGrids and maybe other components won't handle that very well"? Or, what do you suggest me to convert text XML into an Array?

                   

                  Thank you very much!

                  • 6. Re: Error1009 when convert XMLList to XMLListCollection
                    Flex harUI Adobe Employee

                    DataGrid expects the items to have name/value pairs.  There isn't a "name" for the text node.  You can probably  use a labelFunction to extract the text node.

                    • 7. Re: Error1009 when convert XMLList to XMLListCollection
                      Anne0829 Level 1

                      Thank you very much!

                       

                      I tried to use List instead of DataGrid in my code, and the text shows up. But when I'm trying to filter the list, the error 1009 pop up again even when there is text matching.

                       

                      My code is:

                      private function filter():void {

                                                              sourceModel.filterFunction = filterMyArrayCollection;

                                                              sourceModel.refresh();

                                                    }

                       

                                                    private function filterMyArrayCollection(item:Object):Boolean {

                                                              var searchString:String = searchTextInput.text.toLowerCase();

                                                              var itemName:String = (item as String).toLowerCase();

                                                              return searchString == itemName.substr( 0, searchString.length );

                                                    }

                       

                      <spark:SearchTextInput id="searchTextInput" width="250" prompt="Enter search text" change="filter()" />

                                          <sas:List id="list" dataProvider="{sourceModel}" editable="false"

                                                                          width="100%" height="80%">

                                          </sas:List>

                       

                      My ERROR detail is:

                      at index/filterMyArrayCollection()[C:\Adobe Flash Builder 4\SearchTextInput\src\index.mxml:71]

                                at mx.collections::ListCollectionView/internalRefresh()[/c/bb02na1a/vol/sas/day/vert-d4flxcm n42/Products/Commons.Flex/ThirdParty/FlexSDK/frameworks/projects/framework/src/mx/collecti ons/ListCollectionView.as:1533]

                                at mx.collections::ListCollectionView/refresh()[/c/bb02na1a/vol/sas/day/vert-d4flxcmn42/Prod ucts/Commons.Flex/ThirdParty/FlexSDK/frameworks/projects/framework/src/mx/collections/List CollectionView.as:477]

                                at index/filter()[C:\Adobe Flash Builder 4\SearchTextInput\src\index.mxml:66]

                                at index/__searchTextInput_change()[C:\Adobe Flash Builder 4\SearchTextInput\src\index.mxml:80]

                                at flash.events::EventDispatcher/dispatchEventFunction()

                                at flash.events::EventDispatcher/dispatchEvent()

                                at mx.core::UIComponent/dispatchEvent()[/c/bb02na1a/vol/sas/day/vert-d4flxcmn42/Products/Com mons.Flex/ThirdParty/FlexSDK/frameworks/projects/framework/src/mx/core/UIComponent.as:1317 5]

                                at spark.components.supportClasses::SkinnableTextBase/textDisplay_changeHandler()[/c/bb02na1 a/vol/sas/day/vert-d4flxcmn42/Products/Commons.Flex/ThirdParty/FlexSDK/frameworks/projects /spark/src/spark/components/supportClasses/SkinnableTextBase.as:2699]

                                at flash.events::EventDispatcher/dispatchEventFunction()

                                at flash.events::EventDispatcher/dispatchEvent()

                                at mx.core::UIComponent/dispatchEvent()[/c/bb02na1a/vol/sas/day/vert-d4flxcmn42/Products/Com mons.Flex/ThirdParty/FlexSDK/frameworks/projects/framework/src/mx/core/UIComponent.as:1317 5]

                                at spark.components::RichEditableText/textContainerManager_flowOperationCompleteHandler()[/c /bb02na1a/vol/sas/day/vert-d4flxcmn42/Products/Commons.Flex/ThirdParty/FlexSDK/frameworks/ projects/spark/src/spark/components/RichEditableText.as:4842]

                                at flash.events::EventDispatcher/dispatchEventFunction()

                                at flash.events::EventDispatcher/dispatchEvent()

                                at flashx.textLayout.container::TextContainerManager/dispatchEvent()[C:\Vellum\branches\v2\2 .0\dev\output\openSource\textLayout\src\flashx\textLayout\container\TextContainerManager.a s:1553]

                                at flash.events::EventDispatcher/dispatchEventFunction()

                                at flash.events::EventDispatcher/dispatchEvent()

                                at flashx.textLayout.elements::TextFlow/dispatchEvent()[C:\Vellum\branches\v2\2.0\dev\output \openSource\textLayout\src\flashx\textLayout\elements\TextFlow.as:859]

                                at flashx.textLayout.edit::EditManager/finalizeDo()[C:\Vellum\branches\v2\2.0\dev\output\ope nSource\textLayout\src\flashx\textLayout\edit\EditManager.as:669]

                                at flashx.textLayout.edit::EditManager/doOperation()[C:\Vellum\branches\v2\2.0\dev\output\op enSource\textLayout\src\flashx\textLayout\edit\EditManager.as:613]

                                at flashx.textLayout.edit::EditManager/flushPendingOperations()[C:\Vellum\branches\v2\2.0\de v\output\openSource\textLayout\src\flashx\textLayout\edit\EditManager.as:873]

                                at flashx.textLayout.edit::EditManager/insertText()[C:\Vellum\branches\v2\2.0\dev\output\ope nSource\textLayout\src\flashx\textLayout\edit\EditManager.as:1497]

                                at flashx.textLayout.edit::EditManager/textInputHandler()[C:\Vellum\branches\v2\2.0\dev\outp ut\openSource\textLayout\src\flashx\textLayout\edit\EditManager.as:489]

                                at flashx.textLayout.container::ContainerController/textInputHandler()[C:\Vellum\branches\v2 \2.0\dev\output\openSource\textLayout\src\flashx\textLayout\container\ContainerController. as:2502]

                                at flashx.textLayout.container::TextContainerManager/textInputHandler()[C:\Vellum\branches\v 2\2.0\dev\output\openSource\textLayout\src\flashx\textLayout\container\TextContainerManage r.as:1881]

                      • 8. Re: Error1009 when convert XMLList to XMLListCollection
                        Flex harUI Adobe Employee

                        When discussing errors, it is best to post the entire text of the error including stack traces.  That information is often helpful.

                         

                        My guess is that item is not a String so you can't use (item as String) and should use item.toString() instead.

                        • 9. Re: Error1009 when convert XMLList to XMLListCollection
                          Anne0829 Level 1

                          Thank you very much! You are correct! the problem is solved!