Location: PHPKode > projects > Mocovie web framework > mocovi/definitions/createMaster.php
<?php
$relaxNGNamespace	= 'http://relaxng.org/ns/structure/1.0';
$dir				= dirname(__FILE__);
$extension			= '.rng';
$master				= '_master'.$extension;
$startElement		= 'root';
$template = file_get_contents($master);

$relaxNG = new DomDocument();
$relaxNG->loadXML($template);
$relaxNG->preserveWhiteSpace = false;

$start = $relaxNG->getElementsByTagNameNS($relaxNGNamespace, 'start')->item(0);
$anyElements = array();
if($handle = opendir($dir))
{
	while($element = readdir($handle))
	{
		if(is_file($path = $dir.'/'.$element) && $element[0] != '_' && substr($element, strlen($element) - strlen($extension), strlen($element)) == $extension)
		{
			$anyElements[] = substr($element, 0, strlen($element) - strlen($extension));
			$tempDom = new DomDocument();
			$tempDom->load($path);
			$tempDom->preserveWhiteSpace = false;
			$start->parentNode->appendChild($relaxNG->importNode($tempDom->documentElement, true));
		}
	}
	closedir($handle);
}
else
	throw new Exception('Couldn\'t open this dir.');
$xpath = new DomXpath($relaxNG);
$xpath->registerNameSpace('rng', 'http://relaxng.org/ns/structure/1.0');
$anyNode = $xpath->query('//rng:define[@name="any"]/rng:zeroOrMore/rng:choice')->item(0);
foreach($anyElements as $element)
{
	$anyNode->appendChild($ref = $relaxNG->createElement('ref'));
	$ref->setAttribute('name', $element);
}
$relaxNG->formatOutput = true;
$relaxNG->preserveWhiteSpace = false;
// echo $relaxNG->saveXML();
Return current item: Mocovie web framework