Archive for August, 2010

Smudge IT is no more. (Well kinda)

Posted on August 18th, 2010 in Linux | 4 Comments »

I recently decided to sell my hosting side of the business.

If any customers are reading this, then thanks for all your support over the years.

Watch this space for new products and new branches of the business.

Share/Save/Bookmark

Validating XML files, including Google sitemap and atom XML using PHP

Posted on August 11th, 2010 in PHP | No Comments »

The following method is pulled from a class, in a php command line tool, that I created to generate google sitemap files and also Google Base atom files.

What I wanted to do was, vailidate the generated xml files against a schema, before saving them.

You can do this via the command using xmllint.

xmllint –schema atom.xsd.xml –valid –noout /xmlfiles/.test.xml.tmp

However you can easily do this in PHP.

Here are the schema files.

siteindex
sitemap
atom.xsd


static function validate_google_xml($xmlfile, $type)
{

print("Validating {$xmlfile} \n");

$xdoc = new DomDocument;
if($type == 'siteindex')
{
$schema = self::$scriptDir.'siteindex.xsd';
@$xdoc->Load($xmlfile);
if (@$xdoc->schemaValidate($schema))
{
return true;
}
}elseif($type == 'sitemap')
{
$schema = self::$scriptDir.'sitemap.xsd';
//echo $schema ; die;
@$xdoc->Load($xmlfile);
if (@$xdoc->schemaValidate($schema))
{
return true;
}

}elseif($type == 'atom')
{
$schema = self::$scriptDir.'atom.xsd.xml';
//echo $schema ; die;
@$xdoc->Load($xmlfile);
if (@$xdoc->schemaValidate($schema))
{
return true;
}

}

}

Share/Save/Bookmark