首先創建 DOMdocument 然後找到相應的節點,removechild replacechild 節點可以刪除自己的子節點, $t1->parentnode->removechild($t1)
節點不能修改只能替換,createElement一個新的然後replace
simplexml_load_file 又是對象又是數組比較麻煩,考慮全部轉化數組
XML文檔轉數組有利於操作,數組轉XML有利於數據交換 ,用於封裝和打開藉口
利用simpleXML實現XML轉數組,
SimpleXMLElement Object
(
[article] => Array
(
[0] => SimpleXMLElement Object
(
[title] => 深入淺出CURL
[author] => SimpleXMLElement Object
(
[aaa] => Array
(
[0] => sad
[1] => sss
)
)
)
[1] => SimpleXMLElement Object
(
[title] => 深入理解execution context
[author] => jack.yin
)
)
)
array強制轉換隻轉最外層、使用函數Array遞歸進行轉換,
同樣使用
遞歸實現通過數組生成XML,新建SimpleXMLElement 對象,增加子節點然後save實現;具體函數在linux系統下的2.php與3.php文件中。