Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7966843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:32:34+00:00 2026-06-04T06:32:34+00:00

this is my code . but I don’t know why this code can’t create

  • 0

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!!

public function indexAction()
{

 // XML-related routine - <urlset>
    $xml = new DOMDocument('1.0', 'utf-8');
    $masterRoot = $xml->createElement('urlset');
    $xml->appendChild($masterRoot);
    $publicpath = "/public";

    $data = 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);
}

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);

    }

}

these 2 functions are in a controller class

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T06:32:35+00:00Added an answer on June 4, 2026 at 6:32 am
    $xml->save($this->view->serverUrl() . "/sitemap.xml");
    

    You are attempting to save to a full HTTP URL. Unless your server supports PUT method uploads (which I doubt, and that is a good thing) this will not work.

    DOMDocument::saveXML() expects a local file system path. Since you seem to want to save this in your document root, I suspect that simply:

    $xml->save("sitemap.xml");
    

    …will do the job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code, I know I'm missing something but don't know what. It
I have this code but is not working and I don't know why... function
I currently have this code but it leaks because I don't know how to
I got this code on didFinishLaunching but I don't know how to customize it
I have this code to draw an ellipse in the screen but I don't
I just started learning C but I don't understand this part of the code.
runat=server /> But this code is not working How can I add multiple controls
I am using this following code but it don't seem to work properly I
I don't know why this is happening. I have this code here . It
I don't like this code but I always get confused with threads so wanted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.