メインコンテンツまでスキップ
Version: Fegg 5.x

Sitemap::toXml

サイトマップのXMLを返します

説明​

public string Sitemap::toXml()

サイトマップをXMLの文字列で返します。URLは追加した順に並びます。display()が送信するのも同じ文字列です。

例​

use Fegg\Tool\Sitemap;

$sitemap = new Sitemap('https://www.example.com');
$sitemap->add('/')->add('/news/post_12.html', '2026-11-15 10:00:00');

file_put_contents(FEGG_HTML_DIR . '/sitemap.xml', $sitemap->toXml());
Output
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://www.example.com/</loc>
</url>
<url>
<loc>https://www.example.com/news/post_12.html</loc>
<lastmod>2026-11-15T10:00:00+09:00</lastmod>
</url>
</urlset>