function processAttributesBySchema($element)
{
// Remove attributes that don't match schema
$schemaAttributes = $this->XMLSchema->attributes($element);
$schemaCustomAttributes = $this->XMLSchema->customAttributes($element);
$attributes = $element->attributes;
for ($i = $attributes->length - 1; $i >= 0; $i--) {
$attr = $attributes->item($i);
if ($attr->prefix == 'tmp') {
$element->removeAttributeNode($attr);
continue;
}
$allowed = false;
$removeAttr = false;
$fullName = $attr->prefix ? $attr->prefix . ':' . $attr->localName : $attr->nodeName;
// check for allowed custom attributes (3.9)
if ($attr->prefix == 'custom' && in_array($attr->localName, $schemaCustomAttributes)) {
$allowed = true;
} else {
if (in_array($fullName, $schemaAttributes)) {
$allowed = true;
} elseif (in_array($fullName, $schemaCustomAttributes)) {
// add 'custom' prefix if it is not given
$allowed = true;
$removeAttr = true;
$element->setAttributeNS($this->Namespaces['custom'], 'custom:' . $fullName, $attr->value);
}
}
if (!$allowed) {
$removeAttr = true;
$this->handleError(self::ERROR_SCHEMA, ezpI18n::tr('kernel/classes/datatypes/ezxmltext', "Attribute '%1' is not allowed in <%2> element.", false, array($fullName, $element->nodeName)));
} elseif ($this->RemoveDefaultAttrs) {
// Remove attributes having default values
$default = $this->XMLSchema->attrDefaultValue($element->nodeName, $fullName);
if ($attr->value == $default) {
$removeAttr = true;
}
}
if ($removeAttr) {
$element->removeAttributeNode($attr);
}
}
}