0

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.

1 Answer 1

1
  • 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;
   //....
}
Sign up to request clarification or add additional context in comments.

3 Comments

thank you for this....just a silly mistake but cost me lots of time... i just forgot to check the length...
Glad to know it helped :)
i have edited the question so for that i deselect the accepted mark...so after i get my answer i will select your answer as correct one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.