无法从PHP生成正确的XML
我编写了这段代码来生成这个XML结构,但由于某种原因,它似乎不起作用。 它抛出错误:-无法从PHP生成正确的XML,php,xml,domdocument,Php,Xml,Domdocument,我编写了这段代码来生成这个XML结构,但由于某种原因,它似乎不起作用。 它抛出错误:-未定义变量:第11行的C:\wamp\www\sms网关\dev\testxml.php中的operationtype和第11行的C:\wamp\www\sms网关\dev\testxml.php中对非对象的成员函数appendChild()的调用 我正在使用php的DOMDocument库,我不知道;我没有这方面的经验。 以下是我需要生成的内容:- 这是我的密码:- function gen_xml($nu
未定义变量:第11行的C:\wamp\www\sms网关\dev\testxml.php中的operationtype
和第11行的C:\wamp\www\sms网关\dev\testxml.php中对非对象的成员函数appendChild()的调用
我正在使用php的DOMDocument库,我不知道;我没有这方面的经验。
以下是我需要生成的内容:-
这是我的密码:-
function gen_xml($number,$message,$smssender)
{
/* create a dom document with encoding utf8 */
$domtree = new DOMDocument('1.0', 'UTF-8');
/* create the root element of the xml tree */
$xmlRoot = $domtree->createElement("sms-teknik");
/* append it to the document created */
$xmlRoot = $domtree->appendChild($xmlRoot);
$operationtype->appendChild($domtree->createElement('operationtype','0'));
$flash->appendChild($domtree->createElement('flash','0'));
$multisms->appendChild($domtree->createElement('multisms','0'));
$maxmultisms->appendChild($domtree->createElement('maxmultisms','0'));
$compresstext->appendChild($domtree->createElement('compresstext','0'));
$smssender->appendChild($domtree->createElement('smssender',$smssender));
$deliverystatustype->appendChild($domtree->createElement('deliverystatustype','0'));
$usereplynumber->appendChild($domtree->createElement('usereplynumber','0'));
$usereplyforwardtype->appendChild($domtree->createElement('usereplyforwardtype','0'));
$usee164->appendChild($domtree->createElement('usee164','0'));
$item=$domtree->createElement("items");
$item = $domtree->appendChild($item);
$recipient = $domtree->createElement("recipient");
$recipient = $domtree->appendChild($recipient);
$orgaddress->appendChild($domtree->createElement('orgaddress',$number));
echo $domtree->saveXML();
}
如有任何建议/帮助,将不胜感激 您需要像这样替换第11行
$xmlRoot-> appendChild($domtree->createElement('operationtype','0'));
下面的所有行都是相同的,它们将抛出相同的错误。
您应该将child添加到根xml元素。也可以尝试它的真正简单的名称:)错误消息非常清楚