27 lines
576 B
PHP
27 lines
576 B
PHP
|
<?php
|
||
|
|
||
|
namespace External\Utilities;
|
||
|
|
||
|
/**
|
||
|
* From https://stackoverflow.com/a/20511976/1460422
|
||
|
*/
|
||
|
class SimpleXMLElementExtended extends SimpleXMLElement {
|
||
|
|
||
|
/**
|
||
|
* Adds a child with $value inside CDATA
|
||
|
* @param string $name
|
||
|
* @param string $value
|
||
|
*/
|
||
|
public function addChildWithCDATA($name, $value = NULL) {
|
||
|
$new_child = $this->addChild($name);
|
||
|
|
||
|
if ($new_child !== NULL) {
|
||
|
$node = dom_import_simplexml($new_child);
|
||
|
$no = $node->ownerDocument;
|
||
|
$node->appendChild($no->createCDATASection($value));
|
||
|
}
|
||
|
|
||
|
return $new_child;
|
||
|
}
|
||
|
}
|