{"id":1386,"date":"2010-11-09T17:43:00","date_gmt":"2010-11-09T09:43:00","guid":{"rendered":""},"modified":"2013-11-17T16:33:48","modified_gmt":"2013-11-17T08:33:48","slug":"delphi-xml-data-binding","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1386.html","title":{"rendered":"Delphi XML Data Binding"},"content":{"rendered":"<p>\u5148\u751f\u6210\u8981\u64cd\u4f5c\u7684XML\u6587\u4ef6\u7684\u7c7b\uff1a \u9996\u5148\u65b0\u5efa-&gt;\u5176\u5b83-&gt;XML-&gt;XML Data Binding<br \/>\n<img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/352d0fe81ccdba75b90e2d31.jpg\" alt=\"\" border=\"0\" \/><\/p>\n<p>\u627e\u5230\u76f8\u5e94XML\u6587\u4ef6\uff0c\u4e00\u6b65\u4e00\u6b65\u786e\u5b9a\u3002<\/p>\n<p><img decoding=\"async\" src=\".\/wp-content\/uploads\/hibaidu\/19b689d798af056506088b3e.jpg\" alt=\"\" border=\"0\" \/><br \/>\n\u5b8c\u4e86\u540e\u4f1a\u751f\u6210\u76f8\u5e94\u7684\u7c7b\u5355\u5143\u6587\u4ef6(test.pas)\u3002 \u6d4b\u8bd5\u7684XML\u6587\u4ef6\uff08test.xml\uff09\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\r\n&lt;contrys&gt;\r\n &lt;homes id=&quot;n1&quot;&gt;&lt;names&gt;1&lt;\/names&gt;&lt;sum&gt;s1&lt;\/sum&gt;&lt;\/homes&gt;\r\n &lt;homes id=&quot;n2&quot;&gt;&lt;names&gt;2&lt;\/names&gt;&lt;sum&gt;s2&lt;\/sum&gt;&lt;\/homes&gt;\r\n &lt;homes id=&quot;n3&quot;&gt;&lt;names&gt;3&lt;\/names&gt;&lt;sum&gt;s3&lt;\/sum&gt;&lt;\/homes&gt;\r\n &lt;homes id=&quot;n4&quot;&gt;&lt;names&gt;4&lt;\/names&gt;&lt;sum&gt;s4&lt;\/sum&gt;&lt;\/homes&gt;\r\n&lt;\/contrys&gt;\r\n<\/pre>\n<p>\u7136\u540e\u653e\u4e00\u4e2a(XMLDocument\u63a7\u4ef6(XMLDocument2)\uff0c\u8bbe\u7f6e\u5176FileName\u5c5e\u6027\uff0c\u627e\u5230\u6211\u4eec\u7684XML\u6587\u4ef6test.xml\u3002 \u76f8\u5e94\u64cd\u4f5c\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nuses test;    \/\/\u7c7b\u7531XML Data Binding\u81ea\u52a8\u4ea7\u751f\uff0c\u65b0\u5efa-&gt;\u5176\u5b83-&gt;XML\u9875\u91cc\r\n\r\n{$R *.dfm}\r\n\r\nprocedure TForm1.Button1Click(Sender: TObject);\r\nvar\r\n  contrys: IXMLContrysType;\r\n  child2: IXMLHomesType;\r\nbegin\r\n  contrys := Getcontrys(XMLDocument2);\r\n  XMLDocument2.Options := XMLDocument2.Options+&#x5B;doAutoSave];  \/\/\u66f4\u6539\u540e\u81ea\u52a8\u4fdd\u5b58\r\n  \/\/ShowMessage(contrys.Homes&#x5B;1].Sum);\r\n  \/\/  ------------\u6dfb\u52a0\u8282\u70b9\r\n  child2 := contrys.Add;    \/\/\u4e0eInsert(-1)\u65b9\u6cd5\u4e00\u6837\u7684\u6548\u679c\r\n  child2.Id := 'n4';\r\n  child2.Names := 4;\r\n  child2.Sum := 's4';\r\n  contrys.Delete(0);        \/\/\u5220\u9664\u64cd\u4f5c\r\n  contrys.Homes&#x5B;1].Id := 'changed'; \/\/\u66f4\u6539\u5185\u5bb9\r\nend;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u751f\u6210\u8981\u64cd\u4f5c\u7684XML\u6587\u4ef6\u7684\u7c7b\uff1a \u9996\u5148\u65b0\u5efa-&gt;\u5176\u5b83-&gt;XML-&gt;XML Data Bindin [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-1386","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=1386"}],"version-history":[{"count":2,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1386\/revisions"}],"predecessor-version":[{"id":4690,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1386\/revisions\/4690"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}