Delphi Serialize Object To Xml
I have now looked with a bit more detail at TConvertIt designed to serialize all of the fields only,which works for most serialization. Would might be great thing to look at for a binary serializer.But, when you want to mimic what.NET provides to provide a common code base, you need to work with just the public and published fields and properties.Although, I might be mistaken it also does not appear have an elegant way I could control if the serialization names and locations like I do with Attributes.http://robstechcorner.blogspot.com/2009/10/xml-serialization-control-via.html.
Delphi 2010 Generics of GenericsTXmlNode doesn't know what T is. What is it supposed to be?Maybe you meant: TXmlNode = className: String;Attributes: TList ;Nodes: TList ; end. Either that, or you need to specify a type.However, it seems you're missing something here. Generics allow you to create a separate class for each type - not a class for all types. In the code above, TList holds an array of types that are the same, and you probably want them different. Consider this instead: TXmlBuilder = classtypeTXmlAttribute = className: String;Value: Variant; end;TXmlNode = className: String;Attributes: TList;Nodes: TList; end. JVCL is one choice, but if you prefer a small, self-contained library, there's OmniXML (Mozilla Public License 1.1, ).
I've used it successfully in several projects, and I find it the simplest XML library to use in Delphi. OmniXML comes with 'OmniXMLPersistent' unit, which does what you need via RTTI, just like the JVCL solution does. // saving:pers: TPersistent; // SaveToFile is a class method, so no need to instantiate the object: TOmniXMLWriter.
Delphi Object Serialization Xml
SaveToFile ( pers, 'd:pathfile.xml', pfAttributes, ofIndent );pfAttributes means properties will be stored as attributes of XML elements; ofIndent will produce a nicely indented code for readability. // loading: TOmniXMLWriter. LoadFromFile ( pers, 'd:pathfile.xml' ).