2016-04-27 73 views
1

我正在嘗試創建自定義xml,它將包含所有與訂單相關的信息。我已經創建了一個模塊,爲在該模塊塊我使用下面的代碼來生成XML -在模塊塊中創建自定義XML

$doc = new \DOMDocument('1.0', 'UTF-8'); 
$doc->formatOutput = true; 
$root = $doc->createElementNS('http://www.alshaya.com' ,'co:customerOrders'); 
$root->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:types', 'http://www.alshaya.com/schema/types/v1.0'); 
$doc->appendChild($root); 
$customerOrder = $doc->createElement("co:customerOrder"); 
$root->appendChild(111); 
echo $doc->saveXML(); 

但我得到下面的錯誤,我無法生成XML代碼。

**Fatal error**: Class 'DOMDocument' not found 

請建議。

+0

你檢查PHP-DOM是安裝在服務器上或不? – Muk

回答

0

嘗試在命名空間中導入它:

namespace ... 
use DOMDocument; 
class ... 
    { 
    ... 
    $doc = new DOMDocument('1.0', 'UTF-8'); 
相關問題