eZXMLInputParser::setAttributes PHP Method

setAttributes() public method

public setAttributes ( $element, $attributes )
    function setAttributes($element, $attributes)
    {
        $thisOutputTag = $this->OutputTags[$element->nodeName];
        foreach ($attributes as $key => $value) {
            // Convert attribute names
            if (isset($thisOutputTag['attributes']) && isset($thisOutputTag['attributes'][$key])) {
                $qualifiedName = $thisOutputTag['attributes'][$key];
            } else {
                $qualifiedName = $key;
            }
            // Filter classes
            if ($qualifiedName == 'class') {
                $classesList = $this->XMLSchema->getClassesList($element->nodeName);
                if (!in_array($value, $classesList)) {
                    $this->handleError(self::ERROR_DATA, ezpI18n::tr('kernel/classes/datatypes/ezxmltext', "Class '%1' is not allowed for element <%2> (check content.ini).", false, array($value, $element->nodeName)));
                    continue;
                }
            }
            // Create attribute nodes
            if ($qualifiedName) {
                if (strpos($qualifiedName, ':')) {
                    list($prefix, $name) = explode(':', $qualifiedName);
                    if (isset($this->Namespaces[$prefix])) {
                        $URI = $this->Namespaces[$prefix];
                        $element->setAttributeNS($URI, $qualifiedName, $value);
                    } else {
                        eZDebug::writeWarning("No namespace defined for prefix '{$prefix}'.", 'eZXML input parser');
                    }
                } else {
                    $element->setAttribute($qualifiedName, $value);
                }
            }
        }
        // Check for required attrs are present
        if (isset($this->OutputTags[$element->nodeName]['requiredInputAttributes'])) {
            foreach ($this->OutputTags[$element->nodeName]['requiredInputAttributes'] as $reqAttrName) {
                $presented = false;
                foreach ($attributes as $key => $value) {
                    if ($key == $reqAttrName) {
                        $presented = true;
                        break;
                    }
                }
                if (!$presented) {
                    $this->handleError(self::ERROR_SCHEMA, ezpI18n::tr('kernel/classes/datatypes/ezxmltext', "Required attribute '%1' is not presented in tag <%2>.", false, array($reqAttrName, $element->nodeName)));
                }
            }
        }
    }