//Alle objekte einer ArrayList in xml speichern
//Item objekte die in der Liste sind
TMyItem =
class
protected
Fname :
String;
public
property Name :
string read FName;
end;
[XmlInclude(typeof(TMyItem))]
//WICHTIG
TMyItemsArrayList =
class(ArrayList)
....
var
AMyItemsArrayList : TMyItemsArrayList;
procedure SaveToXML;
var
AXMLSerializer : XMLSerializer;
AXMLTextWriter : XMLTextWriter;
begin
AXMLTextWriter := XMLTextWriter.Create('
c:\myfile.xml');
try
AXMLSerializer := XMLSerializer.Create(TypeOf(TMyItemsArrayList));
AXMLSerializer.Serialize(AXMLTextWriter, AMyItemsArrayList);
finally
AXMLTextWriter.Close;
end;
end;
function LoadXML : TMyItemsArrayList;
var
AXMLSerializer : XMLSerializer;
AXMLTextReader : XMLTextReader;
begin
Result :=
nil;
AXMLTextReader := AXMLTextReader.Create('
c:\myfile.xml');
try
AXMLSerializer := XMLSerializer.Create(TypeOf(TMyItemsArrayList));
Result := TMyItemsArrayList(AXMLSerializer.Deserialize(AXMLTextReader));
finally
AXMLTextReader.Close;
end;
end;