我试图更新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