save xml file on zend

rhondaburmest

New Member
this is my code . but I don't know why this code can't create xml file and don`t show any error !!it shows xml result perfectly but can`t save this file on determined path!!\[code\]public function indexAction(){ // XML-related routine - <urlset> $xml = new DOMDocument('1.0', 'utf-8'); $masterRoot = $xml->createElement('urlset'); $xml->appendChild($masterRoot); $publicpath = "/public"; $data = http://stackoverflow.com/questions/10684003/array( array('lastmod'=> date("Y-m-d"),'loc' => $this->view->serverUrl().$publicpath ,'changefreq' =>'daily','priority' =>'1.00'), array('lastmod'=> date("Y-m-d"),'loc' => $this->view->serverUrl().$publicpath ."/about us" ,'changefreq' =>'daily','priority' =>'0.98'), array('lastmod'=> date("Y-m-d"),'loc' => $this->view->serverUrl().$publicpath ."/contact us",'changefreq' =>'daily','priority' =>'0.98'), array('lastmod'=> date("Y-m-d"),'loc' => $this->view->serverUrl().$publicpath ."/useful links",'changefreq' =>'daily','priority' =>'0.98') ); $this->_url($xml,$masterRoot,$data); $output = $xml->saveXML(); $xml->save($this->view->serverUrl() . "/sitemap.xml" ); // Both layout and view renderer should be disabled Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true); Zend_Layout::getMvcInstance()->disableLayout(); // Setting up headers and body $this->_response->setHeader('Content-Type', 'text/xml; charset=utf-8')->setBody($output);}\[/code\]\[code\]protected function _url($xml,$masterRoot,$allData){ foreach($allData as $data) { // <url> $root = $xml->createElement('url'); $masterRoot->appendChild($root); //<loc>http://www.example.com/</loc> $elem = $xml->createElement('loc'); $root->appendChild($elem); $elemtext = $xml->createTextNode($data['loc']); $elem->appendChild($elemtext); //<lastmod>2005-01-01</lastmod> $elem = $xml->createElement('lastmod'); $root->appendChild($elem); $elemtext = $xml->createTextNode($data['lastmod']); $elem->appendChild($elemtext); //<changefreq>monthly</changefreq> $elem = $xml->createElement('changefreq'); $root->appendChild($elem); $elemtext = $xml->createTextNode($data['changefreq']); $elem->appendChild($elemtext); //<priority>0.8</priority> $elem = $xml->createElement('priority'); $root->appendChild($elem); $elemtext = $xml->createTextNode($data['priority']); $elem->appendChild($elemtext); }}\[/code\]these 2 functions are in a controller class
 
Back
Top