{"id":621,"date":"2009-09-08T14:15:00","date_gmt":"2009-09-08T06:15:00","guid":{"rendered":""},"modified":"2013-11-26T15:52:13","modified_gmt":"2013-11-26T07:52:13","slug":"php%e5%a2%9e%e5%8a%a0xml%e8%8a%82%e7%82%b9","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/621.html","title":{"rendered":"PHP\u589e\u52a0xml\u8282\u70b9"},"content":{"rendered":"<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nclass addnode extends DomDocument\r\n{\r\nfunction __construct()\r\n{\r\n   parent::__construct();\r\n}\r\nfunction add($url,$caption,$width,$height,$po)\r\n{\r\n   $image=$this-&gt;createElement(&quot;image&quot;);\r\n   $url=$this-&gt;createElement(&quot;url&quot;,$url);\r\n   $caption=$this-&gt;createElement(&quot;caption&quot;,$caption);\r\n   $width=$this-&gt;createElement(&quot;width&quot;,$width);\r\n   $height=$this-&gt;createElement(&quot;height&quot;,$height);\r\n   $image-&gt;appendChild($url);\r\n   $image-&gt;appendChild($caption);\r\n   $image-&gt;appendChild($width);\r\n   $image-&gt;appendChild($height);\r\n   \/\/$this-&gt;documentElement-&gt;appendChild($image);  appendChild\u53ea\u662f\u6dfb\u52a0\u5230\u6700\u540e\r\n   \/\/$y=$this.getElementsByTagName(&quot;image&quot;)&#x5B;0];\r\n   $this-&gt;documentElement-&gt;insertBefore($image,$po);\r\n}\r\n}\r\n\/\/==================================\u5199\u5165xml\u51fd\u6570==============================\r\nfunction addimage($url,$caption,$width,$height)\r\n{\r\n$dom=new addnode();\r\n$dom-&gt;load(&quot;gallery.xml&quot;);\r\n$po=$dom-&gt;getElementsByTagName(&quot;image&quot;);\r\n$po=$po-&gt;item(0);\r\n$dom-&gt;add($url,$caption,$width,$height,$po);\r\n$dom-&gt;save(&quot;gallery.xml&quot;);\r\n}\r\n\/\/==================================END\u5199\u5165xml\u51fd\u6570============================\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>class addnode extends DomDocument { function __construc [&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-621","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/621","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=621"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/621\/revisions"}],"predecessor-version":[{"id":5258,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/621\/revisions\/5258"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=621"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}