2

我已经查看了有关此主题的许多帖子,并尝试对我的代码进行调整,但似乎无法使其正常工作,非常感谢任何帮助。

如何更新 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();
?>
4

1 回答 1

3

我更改了代码以保存新文档并得到了我正在寻找的结果:

$doc->save("newdoc.xml");
于 2013-03-11T15:56:01.947 回答