Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/kanvakanva.com/public_html/application/helpers/ |
Upload File : |
<?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'); // return new DOMDocument('1.0', 'UTF-8'); } } 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; } $child = $dom->createElement($name); $parent->appendChild($child); if($value != NULL) { if ($cdata) { $child->appendChild($dom->createCdataSection($value)); } else { $child->appendChild($dom->createTextNode($value)); } } return $child; } } 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); } return $node; } } if ( ! function_exists('xml_print')) { function xml_print($dom, $return = FALSE) { $dom->formatOutput = TRUE; $xml = $dom->saveXML(); if ($return) { return $xml; } else { echo $xml; } } } /* End of file xml_helper.php */ /* Location: ./system/application/helpers/MY_xml_helper.php */