Created
August 11, 2018 17:09
-
-
Save nullthoughts/718f4d81da204edd41de16681e5c431c to your computer and use it in GitHub Desktop.
Extends SimpleXMLElement to support writing CDATA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class SimpleXMLExtended extends SimpleXMLElement | |
{ | |
// Inspired by: https://stackoverflow.com/questions/6260224/how-to-write-cdata-using-simplexmlelement/6260295 | |
public function addCDATA($string) | |
{ | |
$node = dom_import_simplexml($this); | |
$nodeOwner = $node->ownerDocument; | |
$node->appendChild($nodeOwner->createCDATASection($string)); | |
} | |
public function appendChildWithCDATA($key, $value) | |
{ | |
$this->addChild($key); | |
$this->{$key}->addCData($value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clean