note 85621 deleted from function.xmlwriter-write-cdata by cmb
| From: | cmb@php.net | Date: | Sun, 20 Sep 2020 16:41:56 +0000 |
| Subject: | note 85621 deleted from function.xmlwriter-write-cdata by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215164@lists.php.net to get a copy of this message | ||
Note Submitter: t dot w dot natt at UNIVERSITY dot bath dot ac dot uk
----
Seen a couple of bug reports and gotchas with this one but not a simple code example. Just in case
someone finds it useful:
<?php
// serve xml doc as xml
header('Content-type: application/xml');
// set up the document
$xml = new XmlWriter();
$xml->openMemory();
$xml->startDocument('1.0', 'UTF-8');
$xml->startElement('mydoc');
$xml->startElement('myele');
// CData output
$xml->startElement('mycdataelement');
$xml->writeCData("text for inclusion within CData tags");
$xml->endElement();
// end the document and output
$xml->endElement();
$xml->endElement();
echo $xml->outputMemory(true);
?>
Outputs:
<?xml version="1.0" encoding="UTF-8"?>
<mydoc>
<myele>
<mycdataelement><![CDATA[text for inclusion within CData tags]]>
</mycdataelement>
</myele>
</mydoc>