5 Replies Latest reply on Nov 19, 2009 9:19 AM by cmolinar1204

    dataProvider issue when XML node has a dash "-" on its name

    cmolinar1204

      Hello All,

       

      I have an XML file that has the following structure:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <sample>
        <dataset>

          <route>

          <route>

          ...

       

      I receive this file through an HTTPService with id="srv"

       

      I'm able to populate a datagrid with this data using:

       

      <mx:DataGrid id="route_info" dataProvider="{srv.lastResult.sample.dataset.route}" width="100%" height="100%">

       

      My problem is that the original XML file that I'm trying to use has "data-set" instead of "dataset" as the second tag and this:

       

      <mx:DataGrid id="route_info" dataProvider="{srv.lastResult.sample.data-set.route}" width="100%" height="100%">

       

      Throws a compilation error:

       

      Error: Access of undefined property set

       

      I have tried to escape the '-' with backslashes, I have use srv.lastResult.sample['data-set'] and something like srv.lastResult.sample.getElement('data-set') but none of them have worked.

       

      I cannot change the data-set name to dataset. It's fixed. This is not in the <mx:Script> part.

       

      Any help will be appreciated.

       

      Saludos

        • 1. Re: dataProvider issue when XML node has a dash "-" on its name
          Flex harUI Adobe Employee

          I would expect ["data-set"] to work.  What happened when you tried that?

           

          Alex Harui

          Flex SDK Developer

          Adobe Systems Inc.

          Blog: http://blogs.adobe.com/aharui

          • 2. Re: dataProvider issue when XML node has a dash "-" on its name
            cmolinar1204 Level 1

            These are some of the combinations I have tried:

             

            <mx:DataGrid id="route_info" dataProvider="{srv.lastResult.sample["data-set"].route}" width="100%" height="100%">

            Error: Element type "mx:DataGrid" must be followed by either attribute specifications, ">" or "/>".

             

            <mx:DataGrid id="route_info" dataProvider="{srv.lastResult.sample[\"data-set\"].route}" width="100%" height="100%">

            Error: Element type "mx:DataGrid" must be followed by either attribute specifications, ">" or "/>".

             

            <mx:DataGrid id="route_info" dataProvider="{srv.lastResult.sample['data-set'].route}" width="100%" height="100%">

            Warning: Data binding will not be able to detect changes when using square bracket operator.  For Array, please use ArrayCollection.getItemAt() instead.

            (With this option, the datagrid does not get populated after retreival of the XML).

             

            <mx:DataGrid id="route_info" dataProvider={srv.lastResult.sample["data-set"].route} width="100%" height="100%">

            Error: Open quote is expected for attribute "dataProvider".

             

            <mx:DataGrid id="route_info" dataProvider='{srv.lastResult.sample["data-set"].route}' width="100%" height="100%">

            Warning: Data binding will not be able to detect changes when using square bracket operator.  For Array, please use ArrayCollection.getItemAt() instead.

            (With this option, the datagrid does not get populated after retreival of the XML).

             

            <mx:DataGrid id="route_info" dataProvider="{srv.lastResult.sample.getItemAt('data-set').route}" width="100%" height="100%">

            (With this option, the datagrid does not get populated after retreival of the XML).

             

            If I change the XML tag from data-set to dataset and use:

            <mx:DataGrid id="route_info" dataProvider="{srv.lastResult.sample.dataset.route}" width="100%" height="100%">

            everything works as expected.

             

            Thank for the quick reply, I hope you can come up with another suggestion.

             

            Carlos

            • 3. Re: dataProvider issue when XML node has a dash "-" on its name
              paul.williams Level 4

              Check the resultFormat of your HttpService is set to e4x. Then try:

               

              dataProvider="{srv.lastResult['data-set'].route}"

               

              See section two of the link below for more on why you shouldn't include 'sample' in your expression:

               

              http://www.morearty.com/blog/2007/03/13/common-e4x-pitfalls/

              • 4. Re: dataProvider issue when XML node has a dash "-" on its name
                cmolinar1204 Level 1

                This format indeed provided the solution:

                 

                <mx:DataGrid id="route_info" dataProvider="{srv.lastResult.sample['data-set'].route}" width="100%" height="100%">

                 

                When I tried it the first time I had an error on my XML which made me think it wasnt a working solution but I just tested it again and it works.

                 

                Thanks for the help!

                • 5. Re: dataProvider issue when XML node has a dash "-" on its name
                  cmolinar1204 Level 1

                  I also tried this change and it worked, thanks a lot, I'll use this last one instead of my previous solution.

                   

                  The only difference is that when receiving an XML object, I list the dataFields for the datagrid by just specifing their names, regardless of wheater they are xml elements or attributes of an element.

                   

                  <mx:DataGridColumn dataField="id" headerText="Route Id"/>
                  <mx:DataGridColumn dataField="traveltime" headerText="Travel Time"/>

                   

                  On the other hand, when receiving a e4x result I had to add an '@' to the fields that were attributes.

                  <mx:DataGridColumn dataField="@id" headerText="Route Id"/>
                  <mx:DataGridColumn dataField="traveltime" headerText="Travel Time"/>

                   

                  That's it,

                   

                  Saludos