2 Replies Latest reply on Dec 22, 2010 9:06 AM by webchic2008

    XML not parsing correctly? Is this a bug?

    webchic2008

      I'm very new to both FLEX & FB 4, and have run into what seems to be an impasse. I would appreciate any help you have to offer.

       

      The application displays a list of departments in a pulldown menu that are being provided from an XML file. However, two of the departments have characters that are consistently not displaying.

       

      My source code is:

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
          xmlns:s="library://ns.adobe.com/flex/spark"
          xmlns:mx="library://ns.adobe.com/flex/mx"
          minWidth="955" minHeight="600"
          creationComplete="app_creationCompleteHandler()"
          >
      <fx:Script>
      <![CDATA[
      protected function app_creationCompleteHandler():void
      {
      var name:String;
      for (var i:int=0; i < deptCollection.length; i++)
      {
      var catObj:Object = deptCollection.getItemAt(i);
      trace (name = catObj.D);
      deptSelection.addItem(name);
      }
      deptMenu.selectedIndex = 0;
      }
      ]]>
      </fx:Script>
      <fx:Declarations>
      <fx:Model id="staffModel" source="data/dept_pack.xml"/>
      <mx:ArrayList id="deptSelection"/>

       

      <s:ArrayList id="deptCollection"
        source="{staffModel.departments.dept}"/>

       

      </fx:Declarations>

       

      <s:DropDownList id="deptMenu" dataProvider="{deptSelection}"
      x="100" y="100"/>
      </s:Application>

       

      My XML code is:

       

      <?xml version='1.0' encoding='ISO-8859-1'?>

      <staff>
        <departments>
         <dept> <D>302D</D></dept>
         <dept> <D>302E</D></dept>
         <dept> <D>303F</D></dept>
         <dept> <D>303G</D></dept>
        </departments>
      </staff>

       

      The result: The departments are displayed in a drop down menu, and the "D" in 302D is missing and the "F" in 303F is missing. The others display correctly.

        • 1. Re: XML not parsing correctly? Is this a bug?
          Peter deHaan Level 4

          Interesting, can you please file a bug at http://bugs.adobe.com/flex/ and somebody can take a look.

          I'm not an expert on Model usage, but my quick test showed that this seemed to work as expected if I loaded the XML file using HTTPService or using the Flash Player classes like URLRequest and URLLoader:

          <?xml version="1.0" encoding="utf-8"?>

          <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"

                         xmlns:s="library://ns.adobe.com/flex/spark"

                         xmlns:mx="library://ns.adobe.com/flex/mx"

                         minWidth="955" minHeight="600"

                         creationComplete="application1_creationCompleteHandler(event);">

              <fx:Script>

                  <![CDATA[

                      import mx.events.FlexEvent;

                      import mx.rpc.events.ResultEvent;

                      import mx.utils.ObjectUtil;

           

                      protected var obj:URLLoader;

           

                      protected function application1_creationCompleteHandler(evt:FlexEvent):void {

                          var req:URLRequest = new URLRequest("dept_pack.xml");

                          obj = new URLLoader();

                          obj.dataFormat =  URLLoaderDataFormat.TEXT;

                          obj.addEventListener(Event.COMPLETE, obj_complete);

                          obj.load(req);

           

                          ws.send();

                      }

           

                      protected function obj_complete(evt:Event):void {

                          var theX:XML = new XML(obj.data);

                          trace(ObjectUtil.toString(obj.data));

                          trace(theX.toXMLString());

                          debug2.text = ("---", theX.departments.dept.D[0].toString());

                      }

           

                      protected function ws_resultHandler(evt:ResultEvent):void {

                          debug1.text = evt.result.toXMLString();

                      }

                  ]]>

              </fx:Script>

           

              <fx:Declarations>

                  <s:HTTPService id="ws" url="dept_pack.xml" resultFormat="e4x" result="ws_resultHandler(event);" />

                  <s:XMLListCollection id="xmlListColl" source="{ws.lastResult.departments.dept.D}" />

              </fx:Declarations>

           

              <s:layout>

                  <s:VerticalLayout/>

              </s:layout>

           

              <s:TextArea id="debug1" />

              <s:TextArea id="debug2" />

              <s:DropDownList id="ddl" dataProvider="{xmlListColl}" requireSelection="true" />

           

          </s:Application>

           

           

          Peter

          1 person found this helpful
          • 2. Re: XML not parsing correctly? Is this a bug?
            webchic2008 Level 1

            Yes, thanks for doing this. It set us in the right direction.