<?php
class SimpleXMLExtended extends SimpleXMLElement {
public function addCData($cdata_text) {
$node = dom_import_simplexml($this);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($cdata_text));
}
}
$oXML = new SimpleXMLExtended('<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0" />');
$oChannel = $oXML->addChild('channel');
$oChannel->addChild('title', 'TEST');
$oProduct = $oChannel->addChild('item');
$oProduct->addChild('product_type', 'used', 'http://base.google.com/ns/1.0');
echo $oXML->asXML();
- Output for 7.1.25 - 7.1.31, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- <?xml version="1.0"?>
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0"><channel><title>TEST</title><item><g:product_type>used</g:product_type></item></channel></rss>
preferences:
164.98 ms | 408 KiB | 5 Q