{"id":4873,"date":"2014-03-30T16:16:57","date_gmt":"2014-03-30T16:16:57","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/whats-a-good-way-to-serialize-delphi-object-tree-to-xml-using-rtti-and-not-custom-code-collection-of-common-programming-errors\/"},"modified":"2014-03-30T16:16:57","modified_gmt":"2014-03-30T16:16:57","slug":"whats-a-good-way-to-serialize-delphi-object-tree-to-xml-using-rtti-and-not-custom-code-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/whats-a-good-way-to-serialize-delphi-object-tree-to-xml-using-rtti-and-not-custom-code-collection-of-common-programming-errors\/","title":{"rendered":"What&#39;s a good way to serialize Delphi object tree to XML&#8211;using RTTI and not custom code?-Collection of common programming errors"},"content":{"rendered":"<p>JVCL is one choice, but if you prefer a small, self-contained library, there&#8217;s <strong>OmniXML<\/strong> (Mozilla Public License 1.1, http:\/\/www.omnixml.com\/ ). I&#8217;ve used it successfully in several projects, and I find it the simplest XML library to use in Delphi. OmniXML comes with &#8216;OmniXMLPersistent&#8217; unit, which does what you need via RTTI, just like the JVCL solution does.<\/p>\n<pre><code>\/\/ saving:\npers : TPersistent;\n\/\/ SaveToFile is a class method, so no need to instantiate the object:\nTOmniXMLWriter.SaveToFile( pers, 'd:\\path\\file.xml', pfAttributes, ofIndent );\n<\/code><\/pre>\n<p>pfAttributes means properties will be stored as attributes of XML elements; ofIndent will produce a nicely indented code for readability.<\/p>\n<pre><code>\/\/ loading:\nTOmniXMLWriter.LoadFromFile( pers, 'd:\\path\\file.xml' );\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JVCL is one choice, but if you prefer a small, self-contained library, there&#8217;s OmniXML (Mozilla Public License 1.1, http:\/\/www.omnixml.com\/ ). I&#8217;ve used it successfully in several projects, and I find it the simplest XML library to use in Delphi. OmniXML comes with &#8216;OmniXMLPersistent&#8217; unit, which does what you need via RTTI, just like the JVCL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4873","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4873","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4873"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4873\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4873"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4873"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4873"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}