am using schemavalidate() from php to validate my sitemap.xml file. This sitemap.xml file is generated by drupal module(xmlsitemap). When I run the schemavalidate, I get errors. Here is the code,

libxml_use_internal_errors(false);

$xmlDom = new DomDocument('1.0', 'utf-8');
$xmlDom->validateOnParse = true;

if(!$xmlDom->load(xml file location - url))
{
$errors = libxml_get_errors();
libxml_clear_errors();
$is_file_valid = FALSE;
}
else
{
if (!$xmlDom->schemaValidate('http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd'))
{
$Errors = libxml_get_errors();
$is_file_valid = FALSE;
libxml_clear_errors();
}
else
{
$is_file_valid = TRUE;
}
}
I see the following error, Element '{http://www.sitemaps.org/schemas/sitemap/0.9}lastmod': '2011-03-07T01:53Z' is not a valid value of the union type '{http://www.sitemaps.org/schemas/sitemap/0.9}tLastmod'

Let me know, If I am missing something with validation or do I have to workaround with this error.

Note: If I generate sitemap.xml for my site online and then do a validation, I do not see any errors.

On my drupal pages I see this message,
warning: DOMDocument::schemaValidate() [domdocument.schemavalidate]: Validation failed: no DTD found !Element '{http://www.sitemaps.org/schemas/sitemap/0.9}lastmod': '2011-03-07T01:53Z' is not a valid value of the union type '{http://www.sitemaps.org/schemas/sitemap/0.9}tLastmod'.

I have PHP Version 5.3.5. Regards.

Comments

Dave Reid’s picture

The XML does not contain the required elements to validate, therefore you can't actually do that.