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

  • Home
  • SEARCH
  • 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 541853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:23:09+00:00 2026-05-13T10:23:09+00:00

I am trying to format visually how my XML file looks when it is

  • 0

I am trying to format visually how my XML file looks when it is output. Right now if you go here and view the source you will see what the file looks like.

The PHP I have that creates the file is: (Note, $links_array is an array of urls)

        header('Content-Type: text/xml');
        $sitemap = new DOMDocument;
        
        // create root element
        $root = $sitemap->createElement("urlset");
        $sitemap->appendChild($root);
         
        $root_attr = $sitemap->createAttribute('xmlns'); 
        $root->appendChild($root_attr); 

        $root_attr_text = $sitemap->createTextNode('http://www.sitemaps.org/schemas/sitemap/0.9'); 
        $root_attr->appendChild($root_attr_text); 

        
        
        foreach($links_array as $http_url){
        
                // create child element
                $url = $sitemap->createElement("url");
                $root->appendChild($url);
                
                $loc = $sitemap->createElement("loc");
                $lastmod = $sitemap->createElement("lastmod");
                $changefreq = $sitemap->createElement("changefreq");
                
                $url->appendChild($loc);
                $url_text = $sitemap->createTextNode($http_url);
                $loc->appendChild($url_text);
                
                $url->appendChild($lastmod);
                $lastmod_text = $sitemap->createTextNode(date("Y-m-d"));
                $lastmod->appendChild($lastmod_text);
                
                $url->appendChild($changefreq);
                $changefreq_text = $sitemap->createTextNode("weekly");
                $changefreq->appendChild($changefreq_text);
                
        }
        
        $file = "sitemap.xml";
        $fh = fopen($file, 'w') or die("Can't open the sitemap file.");
        fwrite($fh, $sitemap->saveXML());
        fclose($fh);
    }

As you can tell by looking at the source, the file isn’t as readable as I would like it to be. Is there any way for me to format the nodes?

Thanks,
Levi

  • 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-05-13T10:23:10+00:00Added an answer on May 13, 2026 at 10:23 am

    Checkout the formatOutput setting in DOMDocument.

    $sitemap->formatOutput = true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 290k
  • Answers 291k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Haven't tried anti-aliasing in GD myself, but it appears to… May 13, 2026 at 5:54 pm
  • Editorial Team
    Editorial Team added an answer There's a general consensus that you should reorganize ("defragment") your… May 13, 2026 at 5:54 pm
  • Editorial Team
    Editorial Team added an answer No, not at this time; it's a well-known limitation of… May 13, 2026 at 5:54 pm

Related Questions

I am trying to import a column of dates from a spreadsheet in Excel
I am trying to format some bad html to output into a pop window.
I am trying to format (bold or italics) only a portion of a textbox
I am trying to format a byte array in C#, by porting a code
I am trying to format strings depending on the type ...but I feel it's

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.