|
XMLWriter::writeCData
Write full CDATA tag
()
Related Examples ( Source code ) » xmlwriter write cdata Examples ( Source code ) » XML Cdata handler Examples ( Source code ) » Write content to file Examples ( Source code ) » Write string to text file Examples ( Source code ) » Write to system log Code Examples / Notes » xmlwriter write cdataharvey dot robin
This function will not have any effect if the last node you output was a text node. This includes whitespace. Example: <?php /* <html> <![CDATA[ Summut nice ]]> something </html> */ $xw = new XMLWriter; $xw->openMemory(); $xw->startDocument('1.0', 'ISO-8859-1'); $xw->startElement('html'); $xw->text('Comment out this line to get the CDATA back!!'); $xw->writeCData('Summut nice'); $xw->writeElement('p', 'something'); $xw->endElement(); $xw->endDocument(); echo $xw->outputMemory(); ?> dave
i don't know if this is a bug with the underlying c code or not, or this is by design (i'm not a big xml guy), but for me, running on fedora core 5, php 5.2.1 to get this to work, the cdata functions need to wrap the description (or whatever element the cdata should appear in) for example. // initiate xmlwriter object as $xw // add header, titles, etc. // start cdata $xw->startCData(); // start description $xw->startElement('description'); // write cdata $xw->writeCData('<img src="http://php.net/images/php.gif" />'); // write the description contents $xw->text('php logo'); // end the description element $xw->endElement(); // end the cdata $xw->endCData(); // end xml, and output otherwise, i just got warnings about writing cdata in the wrong context, and no cdata would be written thesoupdragon
A rather strange effect with this. UTF8 Mysql database $xml->startElement('tablecolor2'); $xml->writeCData( $tablecolor2 ); $xml->endElement(); does not work ! but $xml->startElement('tablecolor2'); $tablecolor2 = utf8_decode ( $val['pcolor2']); $xml->writeCData( utf8_encode ($tablecolor2) ); $xml->endElement(); cannot explain this - but it may help someone |
Change LanguageXMLWriter::endAttribute XMLWriter::endCData XMLWriter::endComment XMLWriter::endDocument XMLWriter::endDTDAttlist XMLWriter::endDTDElement XMLWriter::endDTDEntity XMLWriter::endDTD XMLWriter::endElement XMLWriter::endPI XMLWriter::flush XMLWriter::fullEndElement XMLWriter::openMemory XMLWriter::openURI XMLWriter::outputMemory XMLWriter::setIndentString XMLWriter::setIndent XMLWriter::startAttributeNS XMLWriter::startAttribute XMLWriter::startCData XMLWriter::startComment XMLWriter::startDocument XMLWriter::startDTDAttlist XMLWriter::startDTDElement XMLWriter::startDTDEntity XMLWriter::startDTD XMLWriter::startElementNS XMLWriter::startElement XMLWriter::startPI XMLWriter::text XMLWriter::writeAttributeNS XMLWriter::writeAttribute XMLWriter::writeCData XMLWriter::writeComment XMLWriter::writeDTDAttlist XMLWriter::writeDTDElement XMLWriter::writeDTDEntity XMLWriter::writeDTD XMLWriter::writeElementNS XMLWriter::writeElement XMLWriter::writePI XMLWriter::writeRaw |