我有以下 XML,我需要用数组中的一些数据填充它。问题是它有 3 个名为“contact”的节点,但每个节点都有不同的属性。我尝试使用 Xpath,但我没有设法让它工作,不断收到错误。我认为这可能是语法错误。
xml 示例
<command>
<create>
<domain:create xmlns:domain="urn:ietf:params:xml:ns:domain-1.0"
xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0
domain-1.0.xsd">
<domain:name>0000</domain:name>
<domain:period unit="y">2</domain:period>
<domain:ns>
<domain:hostObj>0000</domain:hostObj>
</domain:ns>
<domain:registrant>0000</domain:registrant>
<domain:contact type="tech">000</domain:contact>
<domain:contact type="admin">000</domain:contact>
<domain:contact type="billing">000</domain:contact>
<domain:authInfo>
<domain:pw>000</domain:pw>
</domain:authInfo>
</domain:create>
</create>
<clTRID>ABC:ics-forth:1079691187887</clTRID>
</command>
</epp>
在我的代码下面
$p2xml = new SimpleXmlElement($p2xmlf);
foreach ($p2xml->command->create as $entry2)
{
$namespaces = $entry2->getNameSpaces(true);
$dc = $entry2->children($namespaces['domain']);
$dc->create->name = $domain_fields['name'];
$dc->create->ns->hostObj = $domain_fields['ns1'];
$dc->create->ns->hostObj = $domain_fields['ns2'];
$dc->create->registrant = $domain_fields['registrant'];
$dc->create->contact = $domain_fields['contact']; <-- problem here
$dc->create->contact = $domain_fields['contact']; <-- problem here
$dc->create->contact = $domain_fields['contact']; <-- problem here
$dc->create->authInfo->pw = $domain_fields['pw'];
$oxml = $p2xml->asXML();
尝试用 //contact[@type=['tech'] 和其他一些替换联系人,但我被卡住了