Hello everyone I am trying to create a XML request with multiple same node.
(defn boolean [x]
(cond
(= x nil) false
(= x false) false
:else true))
This is my XML request it is an SMS request sending SMS to numbers in $xml='<?xml version="1.0" encoding="UTF-8"?>
<mainbody>
<header>
<company dil="TR">Netgsm</company>
<usercode>usercode</usercode>
<password>pass</password>
<startdate></startdate>
<stopdate></stopdate>
<type>1:n</type>
<msgheader>S.KARABACAK</msgheader>
</header>
<body>
<msg><![CDATA['.$message.']]></msg>
<no></no>
</body>
</mainbody>';
nodes.
<no></no>
I am getting numbers in databases with a PHP while loop but i couldn't figure out how to add item $xml->body as $newXML=new SimpleXMLElement($xml);
$noNode=$newXML->body->no;
$noNode->addChild("no",$new_number);
It must be like this
<no></no>
答案 0 :(得分:0)
您需要从父节点addChild()
调用<body>
。
$newXML->body->addChild("no", "123-456789");
$newXML->body->addChild("no", "987-654321");
$newXML->body->addChild("no", "567-890123");
在行动中看到它:https://eval.in/518329
如果您想直接访问新<no>
,可以使用变量引用它:
$newnode = newXML->body->addChild("no", "123-456789");
// do something with $newnode