webhost

Web hosting

Wednesday, February 15, 2012

CodeIgniter: Convert XML into Object

Codeigniter library that help you convert and parse xml data into php object

<?phpclass CI_Xml_Handle{
    var 
$xml='';
    function 
CI_Xml_Handle($xml_content)
    {
        
$this->xml=$xml_content;
    }
    function 
XMLtoObject () {
        try {
            
$xml_object = new SimpleXMLElement($this->xml);
            if (
$xml_object == false) {
                return 
false;
            }
        }
        catch (
Exception $e) {
            return 
false;
        }
        return 
$xml_object;
    }

This library works as an XML parser and convert any XML document to an object for further processing. Just copy and paste source code above, create a CodeIgniter library file, put it in usual CodeIgniter library folder, load it, and call it ;)

No comments:

Post a Comment