【问题标题】:Create custom XML in module block在模块块中创建自定义 XML
【发布时间】:2016-04-27 10:04:01
【问题描述】:

我正在尝试创建包含所有订单相关信息的自定义 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

请提出建议。

【问题讨论】:

  • 您是否检查过您的服务器上是否安装了 php-dom?

标签: xml magento2


【解决方案1】:

尝试将其导入您的命名空间:

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

【讨论】:

    猜你喜欢
    • 2017-05-30
    • 2012-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-12
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多