我已經編寫了此代碼來生成此XML結構,但出於某種原因,它似乎並沒有工作。 它引發錯誤: - Undefined variable: operationtype in C:\wamp\www\sms-gateway\dev\testxml.php on line 11
和Call to a member function appendChild() on a non-object in C:\wamp\www\sms-gateway\dev\testxml.php on line 11
無法從PHP生成正確的XML
我使用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();
}
任何建議/幫助將不勝感激。
那麼錯誤信息很清楚 – Steve 2014-09-02 09:45:08