| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* E2pdf Zip Helper |
| 5 |
* |
| 6 |
* @copyright Copyright 2017 https://e2pdf.com |
| 7 |
* @license GPLv3 |
| 8 |
* @version 1 |
| 9 |
* @link https://e2pdf.com |
| 10 |
* @since 0.00.01 |
| 11 |
*/ |
| 12 |
if (!defined('ABSPATH')) { |
| 13 |
die('Access denied.'); |
| 14 |
} |
| 15 |
|
| 16 |
class Helper_E2pdf_SimpleXMLElement extends \SimpleXMLElement { |
| 17 |
|
| 18 |
/** |
| 19 |
* Add CDATA text in a node |
| 20 |
* @param string $cdata_text The CDATA value to add |
| 21 |
*/ |
| 22 |
private function addCData($cdata_text) { |
| 23 |
$node = dom_import_simplexml($this); |
| 24 |
$no = $node->ownerDocument; |
| 25 |
$node->appendChild($no->createCDATASection($cdata_text)); |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* Create a child with CDATA value |
| 30 |
* @param string $name The name of the child element to add. |
| 31 |
* @param string $cdata_text The CDATA value of the child element. |
| 32 |
*/ |
| 33 |
public function addChildCData($name, $cdata_text) { |
| 34 |
$child = $this->addChild($name); |
| 35 |
$child->addCData($cdata_text); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Add SimpleXMLElement code into a SimpleXMLElement |
| 40 |
* @param SimpleXMLElement $append |
| 41 |
*/ |
| 42 |
public function appendXML($append) { |
| 43 |
if ($append) { |
| 44 |
if (strlen(trim((string) $append)) == 0) { |
| 45 |
$xml = $this->addChild($append->getName()); |
| 46 |
foreach ($append->children() as $child) { |
| 47 |
$xml->appendXML($child); |
| 48 |
} |
| 49 |
} else { |
| 50 |
$xml = $this->addChild($append->getName(), (string) $append); |
| 51 |
} |
| 52 |
foreach ($append->attributes() as $n => $v) { |
| 53 |
$xml->addAttribute($n, $v); |
| 54 |
} |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
} |
| 59 |
|