php - How to generate xml in codeigniter -
i trying generate xml database query.
here generated xml link: http://mydeal.ge/api/xml
but when try parse xml, error: http://wallsparade.com/test.php.
my code is:
public function xml() { $res = $this->db->query('custom query'); if($res->num_rows() > 0) {$output = '<?xml version="1.0"?>'. "\n"; $output .= "<deals>"; foreach($res->result() $item) { $output .= "<sale id = '".$item->id."'>"; $output .= "<link>".$item->link."</link>"; $output .= "<title>".urlencode($item->title)."</title>"; $output .= "<image>".$item->image."</image>"; $output .= "<text>".urlencode($item->text)."</text>"; $output .= "<time>".$item->time."</time>"; $output .= "<price>".$item->price."</price>"; $output .= "<parcent>".$item->parcent."</parcent>"; $output .= "</sale>"; } $output .= '</deals>'; } echo $output; }
what problem?
looks developing api. why don't use restserver plugin codeigniter?
it's handled , don't have worry format. can choose output in json or xml.
plugin developed phil: https://github.com/philsturgeon/codeigniter-restserver
Comments
Post a Comment