【发布时间】:2016-07-01 18:08:07
【问题描述】:
在将 XML 文档提交给 EPP 服务之前,我需要更改嵌套命名空间属性的值。
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<epp xmlns="urn:ietf:params:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:ietf:params:xml:ns:epp-1.0 epp-1.0.xsd">
<command>
<info>
<host:info xmlns:host="urn:ietf:params:xml:ns:host-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:host-1.0 host-1.0.xsd">
<host:name>ns1.example.test.example.com</host:name>
</host:info>
</info>
<clTRID>NORID-14373-1207137695427775</clTRID>
</command>
</epp>
在上面的 XML 中,我需要更改 host:name 元素的值。我正在使用 PHP simplexml_load_string 首先修改 XML 模式中的值,如下所示。
$xml = simplexml_load_string(file_get_contents($fn));
$xml->command->clTRID = GUID(); // This works perfectly
$xml->command->info->name = 'somename'; // Does not work :)
这样做的正确方法是什么?
【问题讨论】: