I have a project I am working on that requires me to periodically update an XML file. My code follows:
Have a great day!
Bud
Code:
// asOrigDir is set on program startup to current dir
// Load the data set
ADODataSet1->LoadFromFile(asOrigDir + "\\TEMP.XML");
// Set the headings
StringGrid1->Cells[0][0] = "SSN";
StringGrid1->Cells[1][0] = "Name";
StringGrid1->Cells[2][0] = "Weeks";
StringGrid1->RowCount = ADODataSet1->RecordCount + 1;
// Load the StringGrid
for(int i = 1; i <= ADODataSet1->RecordCount; i++)
{
StringGrid1->Cells[0][i] = (WideString)ADODataSet1->Fields->FieldByName("SSN")->Text;
StringGrid1->Cells[1][i] = (WideString)ADODataSet1->Fields->FieldByName("Name")->Text;
StringGrid1->Cells[2][i] = (WideString)ADODataSet1->Fields->FieldByName("Weeks Worked")->Text;
ADODataSet1->Next();
}
// Life is good to here...
// Now, user edits the Weeks Worked field in the StringGrid
// ...
// ...
// user clicks the Save button...
for(int i = 1; i <= ADODataSet1->RecordCount; i++)
{
AnsiString tmp = StringGrid1->Cells[2][i];
ADODataSet1->Edit();
ADODataSet1->Fields->FieldByName("Weeks Worked")->AsString = tmp;
ADODataSet1->UpdateRecord();
ADODataSet1->Post();
}
// Save back to XML file... no changes made!
ADODataSet1->SaveToFile(asOrigDir + "\\TEMP.XML", pfXML);
Have a great day!
Bud