2
我已閱讀了許多關於此主題的帖子,並試圖對我的代碼進行調整,但似乎無法使其工作,任何幫助都非常感謝。如何更改XML節點值?
如何更新cen_inst_units_z_name的值?
XML
<?xml version="1.0" encoding="UTF-8" ?>
<xfa:data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<form1>
<cen_inst_units_z_name>Department of School</cen_inst_units_z_name>
</form1>
</xfa:data>
PHP
<?php
$doc = new DOMDocument();
$doc->load('52500_data.xml');
$xpath = new DOMXPath($doc);
$parent = $doc->getElementsByTagName('form1')->item(0);
$query = $xpath->query('cen_inst_units_z_name',$parent);
//Checked to make sure I was pulling the correct node
echo $query->item(0)->textContent;
$query->item(0)->nodeValue = 'Test123';
$doc->saveXML();
?>
我想你需要照顧名稱空間? – michi 2013-03-08 23:56:36
你的代碼正常:http://eval.in/private/a641a2ada98318 - 至少對我而言。你在使用某些特定的PHP/libxml版本嗎? – hakre 2013-03-09 05:53:34
當我將它保存爲新文檔時工作!你的代碼給了我這個想法,謝謝! – 2013-03-11 15:54:46