Whats wrong with this code plz any one suggest me

<?php

class sitemap
{
public function load()
{
global $dom;
$dom = new DOMDocument;
$dom->preserveWhiteSpace = true;
$dom->loadXML(file_get_contents(‘Sitemap.xml’));
}

public function generate()
{
global $dom,$urlset;
$dom = new DOMDocument();

$dom->loadXML(‘<?xml version=“1.0” encoding=“UTF-8”?>
<urlset
xml:ns=“http://www.sitemaps.org/schemas/sitemap/0.9
xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation=“http://www.sitemaps.org/schemas/sitemap/0.9
http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd”>
</urlset>’);
$dom->save(‘Sitemap.xml’);
}

public function addrow($vars)
{
global $dom,$urlset;
    if(!isset($urlset))
        $urlset = $dom-&gt;getElementsByTagName('urlset')-&gt;item(0);
$node = $dom-&gt;createElement('url');
$node-&gt;setAttribute('id',md5($vars['loc']));
    foreach($vars as $key =&gt; $var)
    {
    $node2 = $dom-&gt;createElement($key,$var);
   // $node3 = $dom-&gt;createTextNode($var);
   // $node2-&gt;appendChild($node3);
    $node-&gt;appendChild($node2);
    }
$urlset-&gt;appendChild($node);
$vars['md5'] = md5($vars['loc']);
$dom-&gt;save('sitemap.xml');
}

public function editrow($id)
{
global $dom;
$xpath = new DOMXPath($dom);
$mod = $xpath-&gt;query("/urlset/url[@id='$id']/lastmod");
$mod-&gt;item(0)-&gt;nodeValue = strftime("%Y-%m-%d",time() - gmmktime() + mktime());
$dom-&gt;save('Sitemap.xml');
}

public function deleterow($id)
{
global $dom;
$xpath = new DOMXPath($dom);
$urlset = $dom-&gt;getElementsByTagName('urlset')-&gt;item(0);
$row = $xpath-&gt;query("/urlset/url[@id='$id']")-&gt;item(0);
    if($row)
        $row-&gt;parentNode-&gt;removeChild($row);
$dom-&gt;save('Sitemap.xml');
}

}
?>

and it showing errors like:
Fatal error: Call to a member function appendChild() on a non-object in C:\wamp\www\sitemap.php (it showing error on
$urlset->appendChild($node):wink: …plz help me

Did you find this on the internet or did you write it yourself?

Are you even sure that the DOM extension is installed on this server?

i found it on internet and i used it in my application…but actually the entire code was right …but its not working

Do you mean it was working and now it isn’t or you think the code was right but it has never worked for you?

is thr any prbm with code???i got some fatal error

What is the exact error?

Warning: DOMDocument::loadXML(): Start tag expected, ‘<’ not found in Entity, line: 2 in C:\wamp\www\sitemap.php on line 10

Fatal error: Call to a member function appendChild() on a non-object in C:\wamp\www\sitemap.php on line 39

line 10 is $dom->loadXML(file_get_contents(‘Sitemap.xml’));
line 39 is $newnode=$urlset->appendChild($node);
these are the errors i got in this program

can u plz help me how to solve this one@serverstorm

This error seems to be commonly caused by not passing valid XML string. Have you verified that your Sitemap.xml is located in the same directory as the code you are running and that it is properly formed XML?

actally this prgrm dynamically create the xml file(Sitemap.xml) and at the time of creation of xml file …it shows like <?xml version=“1.0”?> at first line and remaining it shows empty page…

try changing your loadXML() methods to load();

thnks @serverStorm. finally warning is out… now prbm with fatal error…may be element append is not proper…can u see once that code…

Hi will not be able to look at that till tonight or the weekend. In the mean time, google your error and find out what other people have done then try to make incremental changes. If a change doesn’t work, roll it back.