Problem with updating XML file


I am adding two nodes with link between them. At that time my XML file looks like
<?xml version="1.0" encoding="utf-8"?>

It displays propely after reading XML file.
now i add one more node and link between 2nd and newly added node
and replace current file
now it looks like
<?xml version="1.0" encoding="utf-8"?>

now its not showing diagram with proper link.
Can u plz tell what is the proplem exactly?
id's are generating wrongly so that link also.
thanks in advanced.

Is the XML that you are generating what you really want?

I suspect not: notice the additional two s at the end of the , with ids of 4 and 7.
Also: do you really need to remember the "xy" and "location" for s?