[英]How to add a child via PHP in xml string with soap tag
我正在尝试在articoli节点中添加一个Child,但是当我执行代码时收到此错误,我在做什么错?
SimpleXMLElement :: addChild():无法添加子级。 父级不是XML树的永久成员
<?php
$note='<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<AddPrenotazione>
<sessionId>6355aa2c-21f5-4436-8fef-24f0211bbd86</sessionId>
<guid>4353999998999999</guid>
<articoli>
</articoli>
</AddPrenotazione>
</soap12:Body>
</soap12:Envelope>';
$xml = simplexml_load_string($note);
$xml->children('soap12', true)->Body->articoli->addChild("ArticoloPrenotazione","");
echo $xml->asXML();
?>
设置值时XML的结构需要几个额外的部分...
$xml->children('soap12', true)->Body->children()
->AddPrenotazione->articoli->addChild("ArticoloPrenotazione","");
您错过了AddPrenotazione
级别,但是由于它位于与Body
元素不同的名称空间中,因此您还需要使用children()
从默认名称空间获取元素。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.