Problem with creating an XML element

Hi folks,

i need to create the following

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
   <url>
      <loc>http://www.erikastokes.com/</loc>
      <lastmod>2010-07-29</lastmod>
      <changefreq>monthly</changefreq>
      <priority>0.8</priority>
   </url>
</urlset> 

now i have this code

<?php
$xml = new DomDocument("1.0","UTF-8");
$container = $xml->createElement("urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"");
$container = $xml->appendChild($container);


    $url = $xml->createElement("url");
    $url = $container->appendChild($url);
        $loc = $xml->createElement("loc","http://xxxxxx.com/property/234");
        $loc = $url->appendChild($loc);
        $changefreq = $xml->createElement("changefreq","never");
        $changefreq = $url->appendChild($changefreq);    
        $priority = $xml->createElement("priority","0.5");
        $priority = $url->appendChild($priority);                            
$xml->FormatOutput = true;
$string_value = $xml->saveXML();
$xml->save("example.xml");
?>

i am getting an error in 3rd line.
Fatal error: Uncaught exception ‘DOMException’ with message ‘Invalid Character Error’ in …DOMDocument->createElement(‘urlset xmlns="h…’) #1

Thank you,
the error has now been fixed

$xml = new DomDocument("1.0","UTF-8"); //documen type
$container=$xml->createElement('urlset');
$container->appendChild(new DomAttr('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9'));
$xml->appendChild($container);
......
......

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.