Location: PHPKode > projects > Mocovie web framework > mocovi/definitions/createControlMaster.php
<?php
$relaxNGNamespace	= 'http://relaxng.org/ns/structure/1.0';
$dir				= dirname(__FILE__);
$extension			= '.rng';
$master				= '_master'.$extension;
$template =
'<?xml version="1.0" encoding="utf-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
	<start>
		<ref name="'.$startElement.'"/>
	</start>
	<define name="any">
		<zeroOrMore>
			<choice>
				<text/>
				<!-- will be filled dynamically -->
			</choice>
		</zeroOrMore>
	</define>
</grammar>';

$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)
		{
			if($element != 'root'.$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', $relaxNGNamespace);
$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