Question

I have one array like:

> ObjectArr[ID,x,y,distance,Type];

and one xml like:

 objectXML = 
    <objects>
      <object id={ID} x={x} y={y} distance={distance}>{Type}</object>
      <object id={ID} x={x} y={y} distance={distance}>{Type}</object>
      <object id={ID} x={x} y={y} distance={distance}>{Type}</object>
      <object id={ID} x={x} y={y} distance={distance}>{Type}</object>
    </objects>

Objective: Update the XML nodes according to objectArr

objectArr.length = 4 and objectXMl.length() = 4

i have done like this:

for(var i:int = 0; i < objectXML.length(); i++)
{
  objectXML.object[i].@ID = objectArr[i].ID;
  objectXML.object[i].@x = objectArr[i].x;
  objectXML.object[i].@y = objectArr[i].y;
  objectXML.object[i].@distance = objectArr[i].distance;
  objectXML.object[i]= objectArr[i].Type;
}

but xml was not updated as per the array elements. any other solutions should i choose??

if i need to update the xml after delete what should i do?? for deleting array i wrote this much

var ID:String = Obj.getObjectId();
for(var i:int=0; i < objectArr.length; i++)
{
  if(objectArr[i].objID == ID)
  objectArr.splice(i, 1);
}

and to remove the xml node i wrote this code ::

for(var i:int = 0; i<objectXML.object.length();i++)
{
  if(objectXML.object.length() && objectXML.object[i].@objID == objectArr[i].objID)
     delete objectXML.object[i];
}

but it shows this error

Error #1010: A term is undefined and has no properties.

Was it helpful?

Solution

  • objectXML.length() equals 1, not 4
  • @ID should be lowercase to match id attribute in the xml

try this:

for(var i:int = 0; i < objectXML.object.length(); i++){
   objectXML.object[i].@id=objectArr[i].ID;
   //....
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top