Script:
<?php
$writer = new \Wazly\SimpleXmlWriter\Writer(
'<?xml version="1.0" encoding="UTF-8"?>'.
'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">'.
'</urlset>',
['filters' => 'htmlspecialchars']
);
$writer
->addChild('url')
->addChild('loc', 'https://dev.wazly.net')
->addChild('lastmod', date('Y-m-d', time()))
->addChild('image:image')
->addChild('image:loc', 'https://img.wazly.net/home.jpg')
->rewind()
// Shift pointer to root
->addChild('url')
->addChild('loc', 'https://dev.wazly.net/profile?cache=0&rev=4')
->addChild('lastmod', date('Y-m-d', time()))
->addChild('image:image')
->addChild('image:loc', 'https://img.wazly.net/profile.jpg')
->store('/path/to/sitemap.xml');
Output (prettified) :
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>https://dev.wazly.net</loc>
<lastmod>2020-02-20</lastmod>
<image:image>
<image:loc>https://img.wazly.net/home.jpg</image:loc>
</image:image>
</url>
<url>
<loc>https://dev.wazly.net/profile?cache=0&rev=4</loc>
<lastmod>2020-02-20</lastmod>
<image:image>
<image:loc>https://img.wazly.net/profile.jpg</image:loc>
</image:image>
</url>
</urlset>
$writer = new Writer('<items></items>');
or
$writer = new Writer;
$writer->loadFromString('<items></items>');
$writer = new Writer;
$writer->loadFromFile('/path/to/src.xml');
$writer->store('/path/to/dest.xml');
or
// Only when loaded from file
$writer->store();