[ Mini Kiebo ]
Server: Windows NT AKFAR_SERVER 10.0 build 26200 (Windows 10) AMD64
Path:
D:
/
xampp
/
htdocs
/
bem2
/
application
/
helpers
/
[
Home
]
File: my_xml_helper.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); /* ********************************************************** Usage $this->load->helper('xml'); $dom = xml_dom(); $book = xml_add_child($dom, 'book'); xml_add_child($book, 'title', 'Hyperion'); $author = xml_add_child($book, 'author', 'Dan Simmons'); xml_add_attribute($author, 'birthdate', '1948-04-04'); xml_print($dom); ********************************************************** Result <?xml version="1.0"?> <book> <title>Hyperion</title> <author birthdate="1948-04-04">Dan Simmons</author> </book> */ if (!function_exists('xml_dom')) : function xml_dom() { return new DOMDocument('1.0', "UTF-8"); } endif; if (!function_exists('xml_add_child')) : function xml_add_child($parent, $name, $value = NULL, $cdata = FALSE) { if ($parent->ownerDocument != "") : $dom = $parent->ownerDocument; else : $dom = $parent; endif; $child = $dom->createElement($name); $parent->appendChild($child); if ($value != NULL) : if ($cdata) : $child->appendChild($dom->createCdataSection($value)); else : $child->appendChild($dom->createTextNode($value)); endif; endif; return $child; } endif; if (!function_exists('xml_add_attribute')) : function xml_add_attribute($node, $name, $value = NULL) { $dom = $node->ownerDocument; $attribute = $dom->createAttribute($name); $node->appendChild($attribute); if ($value != NULL) : $attribute_value = $dom->createTextNode($value); $attribute->appendChild($attribute_value); endif; return $node; } endif; if (!function_exists('xml_print')) : function xml_print($dom, $return = FALSE) { $dom->formatOutput = TRUE; $dom->preserveWhiteSpace = false; $xml = $dom->saveXML(); if ($return) : return $xml; else : echo $xml; endif; } endif; /* End of file xml_helper.php */ /* Location: ./system/application/helpers/MY_xml_helper.php */