Skip navigation
Pavan_Neeli
Currently Being Moderated

Adobe Flex 3, unable to check existing XML nodes

Feb 18, 2014 4:37 AM

Tags: #flex #3

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


 
Replies
  • Currently Being Moderated
    Feb 18, 2014 9:17 AM   in reply to Pavan_Neeli

    Most loops that eliminate duplicates keep a list/map of the data that has already been processed and compares the loop value against that.

     

     

    In ActionScript, it is more efficient to use a map which is usually a plain object.

     

    
    
    var alreadySeenFolders:Map = {};
    
    

     

     

    In the loop you compare:

     

    
    
        var folderName:String = item.FOLDER.toString();
    
        if (alreadySeenFolders[folderName] == 1)
    
            continue; // was already in map
    
        alreadySeenFolders[folderName] = 1; // store it in map
    
    

     

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points