0

I develop a XML sitemap generator, everything works well but I have problems with image node, this should be image:image, normal is my code so:

$xml->addChild('lastmod', date('Y-m-d'));

I try to add my image node so:

$xml->addChild('image:image', '');

If I create sitemap then I don't see but

How can I fix it to see node like image:image?

Full code:

$xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"></urlset>');


        $i = 1;

        foreach ($results as $result) :
            if ($i < 17) :
                $map = $xml->addChild('url');
                $map->addChild('loc', pageURL());
                $map->addChild('lastmod', date('Y-m-d'));
                $map->addChild('image:image', true);
            endif;

            $i++;

        endforeach;

        file_put_contents('sitemap.xml',$xml->saveXML());
        echo '<pre><b>Sitemap generated</b></pre>';

NOTE: ignore foreach, it works perfect.

My prevous source:

PHP library for parsing XML with a colons in tag names?

http://www.php.net/manual/en/simplexmlelement.children.php

http://php.net/manual/en/simplexmlelement.addchild.php

Community
  • 1
  • 1
Caner
  • 186
  • 1
  • 10
  • 1
    The part before `:` is the XML namespace. Can you please edit above to post an abbreviated sample of the existing XML, and a sample of what you are trying to add to it? Also, post a little more of the PHP code for context, such as how you create the `$xml` object. – Michael Berkowski Nov 30 '15 at 15:21
  • @MichaelBerkowski I added this like here: http://stackoverflow.com/questions/3018808/phps-simplexml-how-to-use-colons-in-names , it works, but can I add a new node inside of: image:image? – Caner Nov 30 '15 at 16:00
  • Yes, if you first target the new `` node using `children()`. You can then `addChild()` to it. http://stackoverflow.com/questions/1186107/simple-xml-dealing-with-colons-in-nodes http://stackoverflow.com/questions/1186107/simple-xml-dealing-with-colons-in-nodes – Michael Berkowski Nov 30 '15 at 16:05

0 Answers0