eZXMLInputParser::processBySchemaPresence PHP Method

processBySchemaPresence() public method

Check if the element is allowed to exist in this document and remove it if not.
public processBySchemaPresence ( $element )
    function processBySchemaPresence($element)
    {
        $parent = $element->parentNode;
        if ($parent instanceof DOMElement) {
            // If this is a foreign element, remove it
            if (!$this->XMLSchema->exists($element)) {
                if ($element->nodeName == 'custom') {
                    $this->handleError(self::ERROR_SCHEMA, ezpI18n::tr('kernel/classes/datatypes/ezxmltext', "Custom tag '%1' is not allowed.", false, array($element->getAttribute('name'))));
                }
                $element = $parent->removeChild($element);
                return false;
            }
            // Delete if children required and no children
            // If this is an auto-added element, then do not throw error
            if ($element->nodeType == XML_ELEMENT_NODE && ($this->XMLSchema->childrenRequired($element) || $element->getAttribute('children_required')) && !$element->hasChildNodes()) {
                $element = $parent->removeChild($element);
                if (!$element->getAttributeNS('http://ez.no/namespaces/ezpublish3/temporary/', 'new-element')) {
                    $this->handleError(self::ERROR_SCHEMA, ezpI18n::tr('kernel/classes/datatypes/ezxmltext', "<%1> tag can't be empty.", false, array($element->nodeName)));
                    return false;
                }
            }
        } elseif ($element->nodeName != 'section') {
            return false;
        }
        return true;
    }