Question
Need help in looping function
in this code i am fetching the details from the xml....
after that using addData() function i am producing the xml....
but in the getetailsfrmXML() i am using for loop for 60times ..so if i used the addData() function then it produced 60times result... so it make my system slow...
i need to get the all data from xml with single loop...
public function getetailsfrmXML(details) {
var __SeatingDetails:XML = new XML();
__SeatingDetails.parseXML(details);
var my_array:Array = new Array();
var totalElements = XPath.selectNodes(__SeatingDetails, "//Employee/");
for (var i = 0; i<=60; i++) {
var currentNode:XMLNode = totalElements ;
EmpName = currentNode.attributes.Empname;
SeatNumber = currentNode.attributes.SeatNumber;
prjName = currentNode.attributes.ProjectName;
pmName = currentNode.attributes.PM;
PamName = currentNode.attributes.PAM;
var emp:String = EmpName+"_"+String(SeatNumber)+"_"+prjName+"_"+pmName+"_"+PamName;
my_array.push(emp);
addData(EmpName, SeatNumber, prjName, pmName, PamName);
}
}
public function addData(Empname:String, SNumber:Number, ProjectName:String, Pmname:String, PamName:String) {
var Employee:XMLNode = __Employee_xml.createElement("Employee");
Employee.attributes.empname = Empname;
Employee.attributes.seatnumber = SNumber;
Employee.attributes.prjName = ProjectName;
Employee.attributes.PMName = Pmname;
Employee.attributes.PAMName = PamName;
__Employee_xml.firstChild.appendChild(Employee);
trace("__Employee_xml "+__Employee_xml);
}
after that using addData() function i am producing the xml....
but in the getetailsfrmXML() i am using for loop for 60times ..so if i used the addData() function then it produced 60times result... so it make my system slow...
i need to get the all data from xml with single loop...
public function getetailsfrmXML(details) {
var __SeatingDetails:XML = new XML();
__SeatingDetails.parseXML(details);
var my_array:Array = new Array();
var totalElements = XPath.selectNodes(__SeatingDetails, "//Employee/");
for (var i = 0; i<=60; i++) {
var currentNode:XMLNode = totalElements ;
EmpName = currentNode.attributes.Empname;
SeatNumber = currentNode.attributes.SeatNumber;
prjName = currentNode.attributes.ProjectName;
pmName = currentNode.attributes.PM;
PamName = currentNode.attributes.PAM;
var emp:String = EmpName+"_"+String(SeatNumber)+"_"+prjName+"_"+pmName+"_"+PamName;
my_array.push(emp);
addData(EmpName, SeatNumber, prjName, pmName, PamName);
}
}
public function addData(Empname:String, SNumber:Number, ProjectName:String, Pmname:String, PamName:String) {
var Employee:XMLNode = __Employee_xml.createElement("Employee");
Employee.attributes.empname = Empname;
Employee.attributes.seatnumber = SNumber;
Employee.attributes.prjName = ProjectName;
Employee.attributes.PMName = Pmname;
Employee.attributes.PAMName = PamName;
__Employee_xml.firstChild.appendChild(Employee);
trace("__Employee_xml "+__Employee_xml);
}