first commit
This commit is contained in:
46
_plugins/class.simplexml.php
Normal file
46
_plugins/class.simplexml.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?
|
||||
class SimpleXMLElementExtended extends SimpleXMLElement
|
||||
{
|
||||
/**
|
||||
* Add value as CData to a given XML node
|
||||
*
|
||||
* @param SimpleXMLElement $node SimpleXMLElement object representing the child XML node
|
||||
* @param string $value A text to add as CData
|
||||
* @return void
|
||||
*/
|
||||
private function addCDataToNode(SimpleXMLElement $node, $value = '')
|
||||
{
|
||||
if ($domElement = dom_import_simplexml($node))
|
||||
{
|
||||
$domOwner = $domElement->ownerDocument;
|
||||
$domElement->appendChild($domOwner->createCDATASection("{$value}"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add child node with value as CData
|
||||
*
|
||||
* @param string $name The child XML node name to add
|
||||
* @param string $value A text to add as CData
|
||||
* @return SimpleXMLElement
|
||||
*/
|
||||
public function addChildWithCData($name = '', $value = '')
|
||||
{
|
||||
$newChild = parent::addChild($name);
|
||||
if ($value) $this->addCDataToNode($newChild, "{$value}");
|
||||
return $newChild;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add value as CData to the current XML node
|
||||
*
|
||||
* @param string $value A text to add as CData
|
||||
* @return void
|
||||
*/
|
||||
public function addCData($value = '')
|
||||
{
|
||||
$this->addCDataToNode($this, "{$value}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user