Reputation: 14532
CakePHP provides a functionality to generate XML documents/strings from an array (s. CakePHP docu -> Core Libraries -> Utilities -> Xml -> Transforming an array into a string of XML).
Simple example:
$xmlArray = array(
'project' => array(
'@id' => 1,
'name' => 'Name of project, as tag',
'@' => 'Value of project'
)
);
$xmlObject = Xml::fromArray($xmlArray);
$xmlString = $xmlObject->asXML();
Result:
<?xml version="1.0"?>
<project id="1">Value of project<name>Name of project, as tag</name></project>
Now I'd like to generate an XML with one or more comments, like this:
<?xml version="1.0"?>
<!-- here is a comment -->
<project id="1">Value of project<name>Name of project, as tag</name></project>
Is it possible? How to do that?
COMMENT:
This question was marked as duplicate of "Is it possible to insert a comment tag into an xml using simplexml?". But it does NOT duplicate that question, since it's more specific and refers to the XML comments in the context of the CakePHP XML generation -- and not to the "plain" PHP or SimpleXML
.
Upvotes: 2
Views: 79
Reputation: 197777
No, but as you're actually creating a SimpleXMLElement you can insert the comment your own.
See the existing Q&A of that topic:
Upvotes: 1