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 8430951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:43:30+00:00 2026-06-10T05:43:30+00:00

i have the following code, but i want the proper sitemap standard. my code

  • 0

i have the following code, but i want the proper sitemap standard.

my code

$xml = new DomDocument('1.0', 'utf-8'); 
$xml->formatOutput = true; 
$products= $xml->createElement('url'); 
$product = $xml->createElement('url'); 
$xml->appendChild($products); 
$products->appendChild($product); 
$product->appendChild(new DomAttr('loc', '123')); 
$xml->save("data.xml");

but the output of the stated code is lile:

<?xml version="1.0" encoding="utf-8"?>
<url>
<url loc="123"/>
</url>

But i want the following standard…

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.example.com/</loc>
      <lastmod>2012-08-11T04:08:53+01:00</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.5</priority>
   </url>
</urlset>

please help me in this regard.

  • 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-10T05:43:31+00:00Added an answer on June 10, 2026 at 5:43 am

    You have already proven to create an XML document by your syntax – just recreate the standard template.

    For example’s sake, I will pretend your website info is stored in array such as:

    $yourSiteContent = array(
        array('permalink' => 'http://www.somesite.com/someurl1', 'updated' => '2012-08-11T04:08:53+01:00'),
        array('permalink' => 'http://www.somesite.com/someurl2', 'updated' => '2012-09-11T04:08:53+01:00'),
        array('permalink' => 'http://www.somesite.com/someurl3', 'updated' => '2012-10-11T04:08:53+01:00')
    );
    

    Then sticking back to your example:

    $xml = new DomDocument('1.0', 'utf-8'); 
    $xml->formatOutput = true; 
    
    // creating base node
    $urlset = $xml->createElement('urlset'); 
    $urlset -> appendChild(
        new DomAttr('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9')
    );
    
        // appending it to document
    $xml -> appendChild($urlset);
    
    // building the xml document with your website content
    foreach($yourSiteContent as $entry)
    {
    
        //Creating single url node
        $url = $xml->createElement('url'); 
    
        //Filling node with entry info
        $url -> appendChild( $xml->createElement('loc', $entry['permalink']) ); 
        $url -> appendChild( $lastmod = $xml->createElement('lastmod', $entry['updated']) ); 
        $url -> appendChild( $changefreq = $xml->createElement('changefreq', 'monthly') ); 
        $url -> appendChild( $priority = $xml->createElement('priority', '0.5') ); 
    
        // append url to urlset node
        $urlset -> appendChild($url);
    
    }
    
    $xml->save("data.xml");
    

    The rest is up to you.

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

Sidebar

Related Questions

I have the following code below which works, but I want to insert values
I have the following code which works perfectly, but I want to allow access
I have the following code that works great for row click, but I want
I have the following code which will allow only numbers 0-9. But i want
I have the following code I want to run, but the problem is $this->type
I have the following code, WHICH WORKS JUST FINE...WORKS AS I WANT. But if
I have the following code but it never selects the value I want. List<SelectListItem>
I have the following code but it doesnt seem to work: <td align=center style=padding-bottom:52.5px>
I have the following code but the lon/lat seems to be returning null; package
I have the following code but I am unsure how I would adjust it

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.