7 Replies Latest reply on Jul 13, 2010 6:16 AM by rootsounds

    dot in xml tag

    manishmulani

      I've a pie chart whose dataprovider is from xml source.

       

      problem is "xml contains tags containing dots"

       

      for eg : <data>

                    <data.emp>

                               <full.name></full.name>

                               <last.name></last.name>

                               <value></value>

                    </data.emp>

                    <data.emp>

                          .

                          .

                    </data.emp>

                          .

                          .

                    </data>

       

      how do i define dataprovider ??

       

      Thanks,

      Manish

        • 1. Re: dot in xml tag
          rootsounds Level 4

          You can use [] bracket notation in place of the dot operator which will get you around the issue of having a dot in the node name.

           

          Example:

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
              <mx:XML id="testdata">
                  <data>
                      <data.emp><full.name>Bob Smith</full.name>
                          <last.name>Smith</last.name>
                          <value>3</value>
                      </data.emp>
                  </data>
              </mx:XML>
             
             <mx:List dataProvider="{testdata['data.emp']}" labelField="full.name"/>
          </mx:Application>
          1 person found this helpful
          • 2. Re: dot in xml tag
            manishmulani Level 1

            Thanks for the reply rootsounds,

             

            but i'm trying to use httpService's lastResult here

             

            dataProvider = "{httpService.lastResult['data.emp']}"

             

            gives this warning


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

             

             

            Thanks,

            Manish

            • 3. Re: dot in xml tag
              rootsounds Level 4

              First, make sure that HTTPService.resultFormat = "e4x". Then it's just a matter of casting since HTTPService.lastResult returns an Object. What we want is XML, so just cast it as such:

               

              dataProvider = "{XML(httpService.lastResult)['data.emp']}"

              • 4. Re: dot in xml tag
                manishmulani Level 1

                Awesome.. you are too good..

                 

                Thanks a lot

                • 5. Re: dot in xml tag
                  Matt Le Fevre Level 4

                  why are you usings dots in the tags? With the way flex deals with XML you're shooting yourself in the foot before you start

                   

                  to make things far easier in the long run, especially if you plan to re-use this information i'd recommend simply adopting a different format, something like

                   

                  <data>
                       <emp>
                            <fullname></fullname>
                            <lastname></lastname>
                            <value></value>
                       </emp>
                  </data>
                  

                   

                  <data>
                       <emp>
                            <name>
                                 <full></full>            
                                  <last></last>
                            </name>
                            <value></value>
                       </emp>
                  </data>
                  

                   

                   

                  or you could even do something like

                   

                  <data>
                       <emp firstname="" lastname="" value=""/>
                       <emp firstname="" lastname="" value=""/>
                  </data>
                  

                   

                   

                  unless you're being forced to use that model...

                  • 6. Re: dot in xml tag
                    rootsounds Level 4

                    Glad I could help. You should definitely read up on E4X as it can XML very easy to use.

                     

                    While having dots in the node names forces you to use the somewhat less readable [] bracket syntax, as far as I can tell you won't lose anything beyond that.

                    • 7. Re: dot in xml tag
                      manishmulani Level 1

                      @Matt Le Fevre

                       

                      As I told in my previous message, I'm using a web service to obtain the data and rendering it in my app.

                      So, I don't have control over the xml data that I get from the web service.

                       

                      Thanks,

                      Manish