9 Replies Latest reply on Sep 18, 2009 12:27 AM by _Natasha_

    Show XML tree faher label

    zakabalt Level 1

      Hello, I have one XMl with this estructure:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <Cuentas>
      <Cuenta id="cuenta1" label="cuenta1">
      <node label="Borrador"></node>
      <node label="Carpeta1"></node><node label="Carpeta2"></node>
      <node label="Elementos enviados"></node>
      <node label="INBOX"></node>
      <node label="Sent"></node>
      <node label="Trash"></node>
      <node label="[Gmail]">
          <node label="Bidalitako mezuak"></node>
          <node label="Izardunak"></node>
          <node label="Mezu guztiak"></node>
      </node>
      </Cuenta>
      </Cuentas>
      

       

      Now I'm only printing node labels, I can print also the Cuenta label, doing somethin not very complicate? I want something like this

       

      Cuenta1

      -> INBOX

      -> Sent

      ........

       

      No I have

       

      INBOX

      Sent

      .......

       

      Thanks!

        • 1. Re: Show XML tree faher label
          _Natasha_ Level 4

          Hi,

          what do you set as dataProvider for tree?

           

          In Tree there is an attribute "showRoot" (default true).

           

          So you can set Cuentas.* to dataProvider and check that showRoot = true and it should work.

          • 2. Re: Show XML tree faher label
            zakabalt Level 1

            I was searching showRoot thanks, I used one day but I didn't remember the name.

             

            I was searching this attribute but I'm using and doesn't work. Probably I'm giving wrong the dataprovider. I'm doing that to give the dataprovider for the tree.

             

            private function treeLoadedResult(event:ResultEvent):void {
                          xmlTree = XML(event.result.toString());//here I get the tree
                          var lista:XMLList= xmlTree.Cuenta;
                          for(var i:Number=0;i<lista.length(); i++)
                          {
                               var tmpTree:XMLList = xmlTree.Cuenta[i].node;
                              newTree.dataProvider = tmpTree;

             

                                treePanel.addChild(newTree);
                              openAllTreeNodes(newTree);

                           }

            }

             

             

            I use this function because sometimes I put it more than one tree in the Hbox(treePanel).

             

            What dataprovider I have to gice to put it Cuenta1?

             

            Thanks for your help!

            • 3. Re: Show XML tree faher label
              _Natasha_ Level 4

              Yes, you get only a nodes to your tree without Cuenta node.

               

              Try this:

               

              private function treeLoadedResult(event:ResultEvent):void {
                            xmlTree = XML(event.result.toString());//here I get the tree
                            var lista:XMLList= xmlTree.Cuenta;
                            newTree.dataProvider = lista;

               

                             treePanel.addChild(newTree);
                             openAllTreeNodes(newTree);

               

              }

              • 4. Re: Show XML tree faher label
                zakabalt Level 1

                Yes, you're right, now I can see the father label.

                 

                Thank you!

                 

                Best regards

                • 5. Re: Show XML tree faher label
                  zakabalt Level 1

                  I have solved this problem, but if I have more than one Cuenta with different id and label, how I can show the two Cuenta in different trees? If I only put it list in the dataprovider I can show the two(or three or...) trees? Or how I have to change in my code?

                   

                  Here the structure that I want, 3 trees in one VBox

                   

                  Cuenta1

                  -> Inbox

                  -> Trash

                   

                  Cuenta2

                  -> Inbox

                  -> Trash

                   

                  . . . . .

                   

                  Cuenta4

                  -> Inbox

                  -> Trash

                   

                  Thanks!

                  • 6. Re: Show XML tree faher label
                    _Natasha_ Level 4

                    You can try, it should work if all Cuenta elements is in one Cuentas element.

                    • 7. Re: Show XML tree faher label
                      zakabalt Level 1

                      Have you tried? I have tried and I only show one Cuenta, not all the cuentas of my xml. I don't know if I'm doing something wrong or you forgot to tell me something. Here my xml:

                       

                      <?xml version="1.0" encoding="UTF-8"?>
                      <Cuentas>
                      <Cuenta id="cuenta1" label="prueba@xxxx.com">
                           <node label="INBOX" id="(27217)">
                                <node label="Adur" id="(2)"></node>
                                <node label="Drafts"></node>
                                     <node label="Flex" id="(49)">
                                          <node label="Codigo"></node>
                                          <node label="Documentacion"></node>
                                     </node>
                                <node label="Sent"></node>
                                <node label="Trash"></node>
                           </node>
                      </Cuenta>
                      <Cuenta id="cuenta1" label="prueba2@xxxx.com">
                           <node label="INBOX" id=27217></node>
                      </Cuenta>
                      </Cuentas>
                      

                       

                      How should be my tree creator? I have something like this. I have tried with for and without for and didn't work any.

                       

                      private function treeLoadedResult(event:ResultEvent):void {
                                    xmlTree = XML(event.result.toString());//here I get the XML
                                    var lista:XMLList= xmlTree.Cuenta;
                                    //for(var i:Number=0;i<lista.length(); i++)
                                    //{
                                     //    var tmpTree:XMLList = xmlTree.Cuenta[i].node;
                                      newTree.dataProvider = lista;
                                      //newTree.labelField = "@label";
                                      newTree.labelFunction = treeLabelTrad;
                                      newTree.showRoot = true;
                              
                                                         
                                        treePanel.addChild(newTree);
                                        openAllTreeNodes(newTree);
                                 // }                            
                                 }

                       

                      If you have a better solution changing more than one thng don't worry, you can propose.

                      • 8. Re: Show XML tree faher label
                        _Natasha_ Level 4

                        In your XML:

                        <Cuenta id="cuenta1" label="prueba2@xxxx.com">
                             <node label="INBOX" id="27217"></node>
                        </Cuenta>

                        id is the same as previous - not good.

                         

                        Add in your function trace

                         

                        var lista:XMLList= xmlTree.Cuenta;

                        trace(lista.toXMLString());

                        // or

                        Alert.show(lista.toXMLString());

                        // and

                        trace(event.result);

                        // or

                        Alert.show(event.result.toString());

                        • 9. Re: Show XML tree faher label
                          zakabalt Level 1

                          I'm sorry, You're right since the first moment. I had an error in my service, not in my tree creator. I'm sorry

                           

                          Thaks!!