如何使用CakePHP生成带注释的XML?

时间:2014-06-24 09:29:21

标签: php xml cakephp comments xml-comments

CakePHP提供了从数组生成XML文档/字符串的功能(s。CakePHP文档 - >核心库 - >实用程序 - > Xml - > Transforming an array into a string of XML)。

简单示例:

$xmlArray = array(
    'project' => array(
        '@id' => 1,
        'name' => 'Name of project, as tag',
        '@' => 'Value of project'
    )
);
$xmlObject = Xml::fromArray($xmlArray);
$xmlString = $xmlObject->asXML();

结果:

<?xml version="1.0"?>
<project id="1">Value of project<name>Name of project, as tag</name></project>

现在我想生成一个包含一个或多个注释的XML,如下所示:

<?xml version="1.0"?>
<!-- here is a comment -->
<project id="1">Value of project<name>Name of project, as tag</name></project>

有可能吗?怎么做?


COMMENT:

此问题被标记为&#34; Is it possible to insert a comment tag into an xml using simplexml?&#34;的重复。但它并没有重复这个问题,因为它更具体,并且引用了CakePHP XML生成环境中的XML注释 - 而不是&#34; plain&#34; PHP或SimpleXML

1 个答案:

答案 0 :(得分:1)

不,但是当您实际创建 SimpleXMLElement 时,您可以插入自己的评论。

查看该主题的现有问答: