2 Replies Latest reply on Feb 24, 2014 2:46 AM by Pavan_Neeli

    Adobe Flex 3, unable to check existing XML nodes

    Pavan_Neeli

      I am getting an XML data from server(Pls refer xmlData value). I need to: i. Create another XML with non-duplicates Folders ii. Create another XML with final count on monthly basis.

      I am unable to do this with below code and getting duplicate records.

       

      private var xmlData:XML = new XML("<root><SUMMARY_RECORD><FOLDER>Folder1</FOLDER><COUNT>100</COUNT><MONTH>Feb</MONTH><QUARTER>Q1</QUARTER><YEAR>2014</YEAR></SUMMARY_RECORD><SUMMARY_RECORD><FOLDER>Folder1</FOLDER><COUNT>100</COUNT><MONTH>Feb</MONTH><QUARTER>Q1</QUARTER><YEAR>2014</YEAR></SUMMARY_RECORD></root>");

         
      var folderDataXML:XML = new XML("<root></root>");
         
      var folderDGDataXML:XML = new XML("<root></root>");

         
      private function loaded():void{
             
      var item:XML;
              folderDGDataXML
      .appendChild(new XML("<FOLDER_NAME><Name>ALL</Name></FOLDER_NAME>"));
             
      for each (item in xmlData.SUMMARY_RECORD){
                 
      if (folderDGDataXML.FOLDER_NAME.(Name==item.FOLDER).toString() == ""){
                      folderDGDataXML
      .appendChild(new XML("<FOLDER_NAME><Name>"+item.FOLDER+"</Name></FOLDER_NAME>"));
                 
      }  

                 
      if (folderDataXML.SUMMARY_RECORD.(Name==item.MONTH).toXMLString() == ""){
                      folderDataXML
      .appendChild(new XML("<SUMMARY_RECORD><Name>"+item.MONTH+"</Name><COUNT>"+item.COUNT+"</COUNT></SUMMARY_RECORD>"));
                 
      }else{
                     
      var count:int = Number(folderDataXML.SUMMARY_RECORD.(Name==item.MONTH).COUNT) + Number(item.COUNT);
                      folderDataXML
      .SUMMARY_RECORD.(Name==item.MONTH).COUNT = count;
                 
      }

             
      }
         
      }

      Final output:
      folderDGDataXML
      :   
      <root>
       
      <FOLDER_NAME>
         
      <Name>ALL</Name>
       
      </FOLDER_NAME>
       
      <FOLDER_NAME>
         
      <Name>Folder1</Name>
       
      </FOLDER_NAME>
       
      <FOLDER_NAME>
         
      <Name>Folder1</Name>
       
      </FOLDER_NAME>
      </root>

      folderDataXML
      : 
      <root>
       
      <SUMMARY_RECORD>
         
      <Name>Feb</Name>
         
      <COUNT>100</COUNT>
       
      </SUMMARY_RECORD>
       
      <SUMMARY_RECORD>
         
      <Name>Feb</Name>
         
      <COUNT>100</COUNT>
       
      </SUMMARY_RECORD>
      </root>

       

      Can you please help me where I am doing wrong? After getting correct XML, I need to populate datagrid & column chart.

      Thanks in advance for the help.

      Regards

      Pavan