public function get_a_job()
 {
     $this->load->helper('form');
     $this->load->model('Jobs');
     $this->load->helper('xml');
     $results = $this->Jobs->get_oldest_job();
     $dom = xml_dom();
     $job = xml_add_child($dom, 'job');
     xml_add_child($job, 'description', $results[0]->description);
     xml_add_child($job, 'created', $results[0]->timestamp);
     xml_add_child($job, 'jobid', $results[0]->jobid);
     xml_print($dom);
 }
<?php

$this->load->helper('xml');
$dom = xml_dom();
$requests = xml_add_child($dom, 'service_requests');
foreach ($query->result() as $row) {
    $request = xml_add_child($requests, 'request');
    xml_add_child($request, 'service_request_id', $row->report_id);
    xml_add_child($request, 'token', $row->token);
    xml_add_child($request, 'service_notice', $row->service_notice);
    xml_add_child($request, 'account_id', $row->account_id);
}
xml_print($dom);
?>



<?php

$this->load->helper('xml');
$dom = xml_dom();
$error = xml_add_child($dom, 'error');
xml_add_child($error, 'code', $code);
xml_add_child($error, 'description', $description);
xml_print($dom);
?>



 public function createBannerXml($title, $file)
 {
     $path = VAST_PATH;
     $filename = 'banner' . str_replace(' ', '-', $title);
     $filename .= '-' . date('ymdhis');
     $this->load->helper('xml');
     $dom = xml_dom();
     $video = xml_add_child($dom, 'VAST');
     xml_add_attribute($video, 'version', '2.0');
     $ad = xml_add_child($video, 'Ad');
     $inline = xml_add_child($ad, 'InLine');
     $adsystem = xml_add_child($inline, 'AdSystem', 'demo video');
     $adtitle = xml_add_child($inline, 'AdTitle', $title);
     $creatives = xml_add_child($inline, 'Creatives');
     $creative = xml_add_child($creatives, 'Creative');
     $linear = xml_add_child($creative, 'NonLinearAds');
     $nonlinear = xml_add_child($linear, 'NonLinear');
     $staticsource = xml_add_child($nonlinear, 'StaticResource', $file);
     xml_add_child($nonlinear, 'NonLinearClickThrough', 'url');
     xml_add_attribute($staticsource, 'creativeType', "image/jpeg");
     xml_add_attribute($nonlinear, 'width', '480');
     xml_add_attribute($nonlinear, 'height', '270');
     xml_add_attribute($nonlinear, 'minSuggestedDuration', '00:00:15');
     $xml = xml_print($dom, true);
     $xmlobj = new SimpleXMLElement($xml);
     $xmlobj->saveXML($path . $filename . ".xml");
     return $path . $filename . ".xml";
 }
<?php

$this->load->helper('xml');
$dom = xml_dom();
$updates = xml_add_child($dom, 'service_request_updates');
$update = xml_add_child($updates, 'request_update');
xml_add_child($update, 'update_id', $new_update_id);
xml_print($dom);
?>



<?php

$this->load->helper('xml');
$dom = xml_dom();
$service_definition = xml_add_child($dom, 'service_definition');
$service_code = xml_add_child($service_definition, 'service_code', $category_id);
foreach ($attributes->result() as $row) {
    $attribute = xml_add_child($service_definition, 'attribute');
    xml_add_child($attribute, 'variable', $row->variable);
    xml_add_child($attribute, 'code', $row->attribute_id);
    xml_add_child($attribute, 'datatype', $row->datatype);
    xml_add_child($attribute, 'required', $row->required);
    xml_add_child($attribute, 'datatype_description', $row->datatype_description);
    xml_add_child($attribute, 'order', $row->order);
    xml_add_child($attribute, 'description', $row->description);
    xml_add_child($attribute, 'values', $row->values);
}
xml_print($dom);
?>



<?php

$this->load->helper('xml');
$dom = xml_dom();
$services = xml_add_child($dom, 'services');
foreach ($categories->result() as $row) {
    $service = xml_add_child($services, 'service');
    xml_add_child($service, 'service_code', $row->category_id);
    xml_add_child($service, 'metadata', $row->metadata);
    xml_add_child($service, 'type', $row->type);
    xml_add_child($service, 'keywords', $row->keywords);
    xml_add_child($service, 'group', $row->group);
    xml_add_child($service, 'service_name', $row->category_name);
    xml_add_child($service, 'description', $row->description);
}
xml_print($dom);
?>



<?php

$this->load->helper('xml');
$dom = xml_dom();
$service_definition = xml_add_child($dom, 'service_definition');
$service_code = xml_add_child($service_definition, 'service_code', $category_id);
foreach ($attributes->result() as $row) {
    $attribute = xml_add_child($service_definition, 'attribute');
    xml_add_child($attribute, 'variable', $row->variable);
    xml_add_child($attribute, 'code', $row->attribute_id);
    xml_add_child($attribute, 'datatype', $row->datatype);
    xml_add_child($attribute, 'required', $row->required);
    xml_add_child($attribute, 'datatype_description', $row->datatype_description);
    xml_add_child($attribute, 'order', $row->order);
    xml_add_child($attribute, 'description', $row->description);
    xml_add_child($attribute, 'values', json_decode($row->values));
}
xml_print($dom);
?>



    public function createVideoXml($title,$files,$duration)
    {
        $path =VAST_PATH;
        $filename = 'video'.str_replace(' ','-',$title);
        $filename .= '-'.date('ymdhis').rand();
        $this->load->helper('xml');
        $dom = xml_dom();
        $video = xml_add_child($dom, 'VAST');
        xml_add_attribute($video, 'version', '2.0');
        $ad = xml_add_child($video, 'Ad');
        $inline = xml_add_child($ad, 'InLine');	
        $adsystem  = xml_add_child($inline, 'AdSystem','demo video');
        $adtitle  = xml_add_child($inline, 'AdTitle',$title);
        $creatives = xml_add_child($inline, 'Creatives');
        $creative = xml_add_child($creatives, 'Creative');
        $linear = xml_add_child($creative, 'Linear');
        $duration = xml_add_child($linear, 'Duration',$duration);
        $mediafiles  = xml_add_child($linear, 'MediaFiles');
        foreach($files as $row){
           // $mediafile = xml_add_child($mediafiles, 'MediaFile',$row->path);
           // if($row->type == 'ios' || $row->type == 'android'){
           //  xml_add_attribute($mediafile,'type','mobile/m3u8');
          //  }else if($row->type == 'window'){
          //      xml_add_attribute($mediafile,'type','mobile/manifest');
           // }else{
           if($row->type=='desktop'){
            $mediafile = xml_add_child($mediafiles, 'MediaFile',$row->path);
                 xml_add_attribute($mediafile,'type','video/mp4');
                 xml_add_attribute($mediafile,'bitrate','300');
                 xml_add_attribute($mediafile,'width','480');
                 xml_add_attribute($mediafile,'height','270');
           }
            //}
            //xml_add_attribute($mediafile,'bitrate','300');
            //xml_add_attribute($mediafile,'width','480');
           // xml_add_attribute($mediafile,'height','270');
        }
        $xml = xml_print($dom,true);

        $xmlobj=new SimpleXMLElement($xml);           
        $xmlobj->saveXML($path.$filename.".xml");
        return $path.$filename.".xml";
    }
$requests = xml_add_child($dom, 'service_requests');
function dateformat($datetime)
{
    $datetime = $datetime == '0000-00-00 00:00:00' ? '' : date("Y-m-d\\TH:i:s\\Z", strtotime($datetime));
    return $datetime;
}
foreach ($query->result() as $row) {
    $request = xml_add_child($requests, 'request');
    xml_add_child($request, 'service_request_id', $row->report_id);
    xml_add_child($request, 'status', $row->status_name);
    xml_add_child($request, 'status_notes', $row->status_notes);
    //xml_add_child($request, 'service_name', $row->category_name);
    xml_add_child($request, 'service_code', $row->category_id);
    xml_add_child($request, 'description', stripslashes($row->description));
    xml_add_child($request, 'agency_responsible', $row->agency_responsible);
    xml_add_child($request, 'service_notice', $row->service_notice);
    xml_add_child($request, 'requested_datetime', dateformat($row->requested_datetime));
    xml_add_child($request, 'updated_datetime', dateformat($row->updated_datetime));
    xml_add_child($request, 'expected_datetime', dateformat($row->expected_datetime));
    xml_add_child($request, 'address', $row->address);
    xml_add_child($request, 'address_id', $row->address_id);
    xml_add_child($request, 'zipcode', $row->postal_code);
    xml_add_child($request, 'lat', $row->lat);
    xml_add_child($request, 'long', $row->long);
}
xml_print($dom);
?>



{
    $datetime = $datetime == '0000-00-00 00:00:00' ? '' : date("Y-m-d\\TH:i:s\\Z", strtotime($datetime));
    return $datetime;
}
foreach ($query->result() as $row) {
    $request = xml_add_child($requests, 'request');
    xml_add_child($request, 'service_request_id', $row->report_id);
    xml_add_child($request, 'status', $row->status);
    xml_add_child($request, 'status_notes', $row->status_notes);
    //xml_add_child($request, 'service_name', $row->category_name);
    xml_add_child($request, 'service_code', $row->category_id);
    xml_add_child($request, 'description', $row->description);
    xml_add_child($request, 'agency_responsible', $row->agency_responsible);
    xml_add_child($request, 'service_notice', $row->service_notice);
    xml_add_child($request, 'requested_datetime', dateformat($row->requested_datetime));
    xml_add_child($request, 'updated_datetime', dateformat($row->updated_datetime));
    xml_add_child($request, 'expected_datetime', dateformat($row->expected_datetime));
    xml_add_child($request, 'address', $row->address);
    xml_add_child($request, 'address_id', $row->address_id);
    xml_add_child($request, 'zipcode', $row->postal_code);
    xml_add_child($request, 'lat', $row->lat);
    xml_add_child($request, 'long', $row->long);
    xml_add_child($request, 'email', $row->email);
    xml_add_child($request, 'media_url', $row->media_url);
}
xml_print($dom);
?>



//         <status>OPEN</status>
//         <updated_datetime>2010-04-14T10:37:38-01:00</updated_datetime>
//         <description>This problem has been scheduled for inspection</description>
//     </request_update>
// </service_request_updates>
$this->load->helper('xml');
$dom = xml_dom();
$request_updates = xml_add_child($dom, 'service_request_updates');
function dateformat($datetime)
{
    $datetime = $datetime == '0000-00-00 00:00:00' ? '' : date("Y-m-d\\TH:i:s\\Z", strtotime($datetime));
    return $datetime;
}
foreach ($query->result() as $row) {
    $update = xml_add_child($request_updates, 'request_update');
    xml_add_child($update, 'update_id', $row->id);
    xml_add_child($update, 'service_request_id', $row->report_id);
    if (is_config_true($this->config->item('open311_simple_status_only'))) {
        xml_add_child($update, 'status', $row->is_closed ? "CLOSED" : "OPEN");
    } else {
        xml_add_child($update, 'status', strtoupper($row->status_name));
    }
    xml_add_child($update, 'updated_datetime', dateformat($row->updated_at));
    xml_add_child($update, 'description', $row->update_desc);
}
xml_print($dom);
?>