How to create XML file?

Hi, I have to create a XML file but I don’t know how to do that with Yii.

Can someone explain how to do that? I need a XML to store in a/path/of/the/server



I would appreciate this too. cheers

you can create an action on your controller like…

public function actions() {

    return array(




then create a xml doc

    header("Content-type: text/xml;charset=utf-8");

    $s = "<?xml version='1.0' encoding='utf-8'?>";

    $s .= "<rows>";

    $s .= "<records>".$count."</records>";

    foreach($result as $n=> $row):

        $s .= "<row id='". $row->$fieldID."'>";

            $s .= "<cell>". $row->$field."</cell>";

        $s .= "</row>";


    $s .= "</rows>";

    header("Content-Type: application/xml");

    header("Content-Length: " . strlen($s));

echo $s;


$xml = new SimpleXMLElement("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

$tmp = $xml->addChild(‘data’, $res->RecordCount());

foreach($res as $row) {

&#036;node = &#036;xml-&gt;addChild('prospect');

&#036;node-&gt;addChild(&#036;field, &#036;row[&#036;field]);


echo $xml->asXML();

Zend Framework has related components, which you can freely integrate with Yii. It’s not very confidential, so I can say that XML generation and aggregating is planned in the new extension library.