How to update/change the value stored in an XML record with AS3
I have the following xml file........
<Customers>
<Email address="jbloggs@me.com">
<FName>joe</FName>
<Surname>bloggs</Surname>
<DayBirth>02</DayBirth>
<MonthBirth>01</MonthBirth>
<YearBirth>1981</YearBirth>
<House>2</House>
<Address1>Johns Street</Address1>
<Address2>Trekville</Address2>
<City>Timbuktoo</City>
<PostCode>CF67TH</PostCode>
<Gender>Male</Gender>
</Email>
<Email address="fbloggs@me.com">
<FName>fred</FName>
<Surname>bloggs</Surname>
<DayBirth>03</DayBirth>
<MonthBirth>02</MonthBirth>
<YearBirth>1982</YearBirth>
<House>22</House>
<Address1>Johns Street</Address1>
<Address2>Fredville</Address2>
<City>Cardiff</City>
<PostCode>CF71TH</PostCode>
<Gender>Male</Gender>
</Email>
</Customers>
I have loaded the XMLfile into my flash website and I'm able to filter by the email address and display corresponding data. Code below....
var custXML:XMLList;
var xmlCustLoader:URLLoader = new URLLoader();
xmlCustLoader.load(new URLRequest("Customers.xml"));
xmlCustLoader.addEventListener(Event.COMPLETE, custXMLLoaded);
function custXMLLoaded(e:Event):void {
xmlCustLoader.removeEventListener(Event.COMPLETE, custXMLLoaded);
//load xml data into custXML object
custXML = new XMLList(e.target.data);
//run the parse function
ParseCustomer(custXML);
}
function ParseCustomer(customerInput:XMLList):void {
trace("XML Output");
trace("------------------------");
var custAtts:XMLList = customerInput.Email.(@address == entEmail);
for each (var custEmail:XML in custAtts) {
trace(custEmail);
}
//set variables to the filtered result
entFName = customerInput.Email.(@address == entEmail).FName;
entSurname = customerInput.Email.(@address == entEmail).Surname;
entDay = customerInput.Email.(@address == entEmail).DayBirth;
entMonth = customerInput.Email.(@address == entEmail).MonthBirth;
entYear = customerInput.Email.(@address == entEmail).YearBirth;
entHouse = customerInput.Email.(@address == entEmail).House;
entAdd1 = customerInput.Email.(@address == entEmail).Address1;
entAdd2 = customerInput.Email.(@address == entEmail).Address2;
entCity = customerInput.Email.(@address == entEmail).City;
entPCode = customerInput.Email.(@address == entEmail).PostCode;
entGender = customerInput.Email.(@address == entEmail).Gender;
}
I now want to amend a record in this file (eg. change the <FName> from fred to say Paul and save the changes back to the Customers.xml. How do i do this?
