调用未定义的方法DOMElement :: appendChid()

时间:2014-06-02 12:22:01

标签: php

我生成xml。当我尝试添加cdata时,它会给我错误

$dom = new DomDocument("1.0", "ISO-8859-1");
$root = $dom->appendChild($dom->createElement( "Questions")); 
$sxe = simplexml_import_dom( $dom ); 
$question = $sxe->addchild("Question");
$question->addAttribute('id', $Question_Id);
$question->addAttribute('type', $type);                     
$question->appendChild($sxe->createCDATASection( $Questiontext));//error
$question->addChild('Option_One', $Option_One);
$dom->formatOutput = true; 
$xmlString = $dom->saveXML(); 
print($xmlString);
$dom->save("{$Campaign_Name}.xml");

2 个答案:

答案 0 :(得分:1)

您拼写错误,而不是appendChild您写的appendChid

答案 1 :(得分:0)

$question->appendChild(new DOMElement('direction'))->appendChild(new DOMCdataSection('<p>Hello!</p>'));

for DOM