我試圖更新XML文檔。我從一個包含XML的字符串開始。PHP - 更新XML屬性
我加載該字符串SimpleXMLElement對象:
$xmlDoc = simplexml_load_string($my_xml_string);
我發現我想更新,像這樣一個節點:以
$node= $xmlDoc->xpath("//nodename[@node_attribute='{$search_attribute_value}']");
現在我想更新node_attribute
屬性。我試圖做$node['node_attribute']=$new_attribute_value
然而$node
是它自己的對象,並且這不會更新$xmlDoc
對象。
如何找到並更新$xmlDoc
中的屬性值?
是的,向該節點添加索引的確有竅門。 '$ node [0] ['node_attribute'] = $ new_attribute_value;'不知道之前發生了什麼。 – 2014-09-24 04:47:44
@ dev.e.loper還要注意,如果你的節點有一個文本部分,你將使用'$ node [0] - > {'0'}',就像這樣寫在[在這裏](https://eval.in /私營/ 50fd041d061d09)。 – 2014-09-24 04:49:12