Создает DOMElement - эквивалентный состоянию дескриптора

@param DOMDocument $dom

@return DOMElement|null
@throws InvalidDescriptorException
@throws InvalidWriteWorkflowException
11967
public function writeXml(DOMDocument $dom = null)
    {
        if (null === $dom) {
            $errMsg = 'Не передан DOMDocument';
            throw new InvalidWriteWorkflowException($errMsg);
        }
        $descriptor = $dom->createElement('step');

        if (!$this->hasId()) {
            $errMsg = 'Отсутствует атрибут id';
            throw new InvalidDescriptorException($errMsg);
        }
        $id = $this->getId();
        $descriptor->setAttribute('id', $id);

        $name = (string)$this->getName();
        $name = trim($name);
        if (strlen($name) > 0) {
            $nameEncode = XmlUtil::encode($name);
            $descriptor->setAttribute('name', $nameEncode);
        }


        $metaAttributes = $this->getMetaAttributes();
        $baseMeta = $dom->createElement('meta');
        foreach ($metaAttributes as $metaAttributeName => $metaAttributeValue) {
            $metaAttributeNameEncode = XmlUtil::encode($metaAttributeName);
            $metaAttributeValueEnEncode = XmlUtil::encode($metaAttributeValue);

            $metaElement = clone $baseMeta;
            $metaElement->setAttribute('name', $metaAttributeNameEncode);
            $metaValueElement = $dom->createTextNode($metaAttributeValueEnEncode);
            $metaElement->appendChild($metaValueElement);

            $descriptor->appendChild($metaElement);
        }


        $preFunctions = $this->getPreFunctions();
        if ($preFunctions->count() > 0) {
            $preFunctionsElement = $dom->createElement('pre-functions');
            foreach ($preFunctions as $function) {
                $functionElement = $function->writeXml($dom);
                $preFunctionsElement->appendChild($functionElement);
            }

            $descriptor->appendChild($preFunctionsElement);
        }


        $permissions = $this->getPermissions();
        if ($permissions->count() > 0) {
            $permissionsElement = $dom->createElement('external-permissions');
            foreach ($permissions as $permission) {
                $permissionElement = $permission->writeXml($dom);
                $permissionsElement->appendChild($permissionElement);
            }

            $descriptor->appendChild($permissionsElement);
        }

        $actions = $this->getActions();
        $commonActions = $this->getCommonActions();

        if ($actions->count() > 0 || count($commonActions) > 0) {
            $actionsElement = $dom->createElement('actions');

            $commonActionElementBase = $dom->createElement('common-action');
            foreach ($commonActions as $commonActionId) {
                $commonActionElement = clone $commonActionElementBase;
                $commonActionElement->setAttribute('id', $commonActionId);

                $actionsElement->appendChild($commonActionElement);
            }

            foreach ($actions as $action) {
                if (!$action->isCommon()) {
                    $actionElement = $action->writeXml($dom);
                    $actionsElement->appendChild($actionElement);
                }
            }

            $descriptor->appendChild($actionsElement);
        }

        $postFunctions = $this->getPostFunctions();
        if ($postFunctions->count() > 0) {
            $postFunctionsElement = $dom->createElement('post-functions');
            foreach ($postFunctions as $function) {
                $functionElement = $function->writeXml($dom);
                $postFunctionsElement->appendChild($functionElement);
            }

            $descriptor->appendChild($postFunctionsElement);
        }


        return $descriptor;
    }
1251130
public function toDOM(\DOMDocument $doc): \DOMNode
    {
        $paragraph = $doc->createElement('p');

        $this->customAttributesToDOM($paragraph);
        $this->containerToDOM($doc, $paragraph);

        return $paragraph;
    }
227038
protected function validateSchema(\DOMDocument $dom)
    {
        try {
            $valid = $dom->schemaValidate($this->schema);
            return $valid;
        } catch (\Exception $e) {}

        throw new InvalidConfigurationSchema('Schema is not valid');
    }
1326439
public static function createFromXML( DOMElement $node )
    {
        $newObj = new eZPageBlockItem();

        if ( $node->hasAttributes() )
        {
            foreach ( $node->attributes as $attr )
            {
                $newObj->setAttribute( $attr->name, $attr->value );
            }
        }

        foreach ( $node->childNodes as $node )
        {
            if ( $node->nodeType == XML_ELEMENT_NODE )
                $newObj->setAttribute( $node->nodeName, $node->nodeValue );
        }

        return $newObj;
    }
439336
protected final function loadHTML(DOMDocument $dom, string $html)
   {
       try {
           $dom->loadHTML($html, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
       } catch (Throwable $e) {
           throw new RuntimeException("Can't load HTML: " . $e->getMessage());
       }
   }
585827
public function process(\DOMDocument $xml)
    {
        $xpath = new \DOMXPath($xml);
        $nodes = $xpath->query(
            '/project/file/class/docblock/tag[@name="property"]'
            . '|/project/file/class/docblock/tag[@name="property-read"]'
            . '|/project/file/class/docblock/tag[@name="property-write"]'
        );

        /** @var \DOMElement $node */
        foreach ($nodes as $node) {
            $class = $node->parentNode->parentNode;

            $property = new \DOMElement('property');
            $class->appendChild($property);

            $property->setAttribute('final', 'false');
            $property->setAttribute('static', 'false');
            $property->setAttribute('visibility', 'public');
            $property->setAttribute('line', $node->getAttribute('line'));
            $property->appendChild(
                new \DOMElement('name', $node->getAttribute('variable'))
            );
            $property->appendChild(new \DOMElement('default'));

            $docblock = new \DOMElement('docblock');
            $property->appendChild($docblock);
            $docblock->appendChild(
                new \DOMElement('description', $node->getAttribute('description'))
            );
            $docblock->appendChild(new \DOMElement('long-description'));

            $var_tag = new \DOMElement('tag');
            $docblock->appendChild($var_tag);
            $var_tag->setAttribute('name', 'var');
            $var_tag->setAttribute('description', $node->getAttribute('description'));
            $var_tag->setAttribute('type', $node->getAttribute('type'));
            $var_tag->setAttribute('line', $node->getAttribute('line'));

            $var_tag_type = new \DOMElement('type', $node->getAttribute('type'));
            $var_tag->appendChild($var_tag_type);
            $var_tag_type->setAttribute('by_reference', 'false');

            $magic_tag = new \DOMElement('tag');
            $docblock->appendChild($magic_tag);
            $magic_tag->setAttribute('name', 'magic');
            $magic_tag->setAttribute('line', $node->getAttribute('line'));

            $node->parentNode->removeChild($node);
            $docblock->appendChild($node);
        }

        return $xml;
    }
1161586
public function getXML(\DOMDocument $document)
    {
        $xml = $document->createElement(sprintf('%s:TransactionDetails', $this->namespace));

        $comments = $document->createElement('ns1:Comments');
        $comments->textContent = $this->comments;

        $xml->appendChild($comments);

        if (!empty($this->invoiceNumber)) {
            $invoiceNumber = $document->createElement('ns1:InvoiceNumber');
            $invoiceNumber->textContent = $this->invoiceNumber;

            $xml->appendChild($invoiceNumber);
        }

        return $xml;
    }
1249907
protected function processTemplate(DOMDocument $document, DOMXPath $xpath, DOMElement $template)
    {
        $content = null;
        $templateName = $template->getAttribute('name');
        $templateType = $template->hasAttribute('type') ? $template->getAttribute('type') : 'tag';
        $parameters = [
            'name' => $templateName,
            'params' => $this->extractTemplateConfiguration($template, $xpath),
        ];

        $contentNodes = $xpath->query('./docbook:ezcontent', $template);
        $innerContent = '';
        foreach ($contentNodes as $contentNode) {
            $innerContent .= $this->getCustomTemplateContent($contentNode);
        }
        if (!empty($innerContent)) {
            $parameters['content'] = $innerContent;
        }

        if ($template->hasAttribute('ezxhtml:align')) {
            $parameters['align'] = $template->getAttribute('ezxhtml:align');
        }

        $content = $this->renderer->renderTemplate(
            $templateName,
            $templateType,
            $parameters,
            $template->localName === 'eztemplateinline'
        );

        if (isset($content)) {
            // If current tag is wrapped inside another template tag we can't use CDATA section
            // for its content as these can't be nested.
            // CDATA section will be used only for content of root wrapping tag, content of tags
            // inside it will be added as XML fragments.
            if ($this->isWrapped($template)) {
                $fragment = $document->createDocumentFragment();
                $fragment->appendXML(htmlspecialchars($content));
                $template->parentNode->replaceChild($fragment, $template);
            } else {
                $payload = $document->createElement('ezpayload');
                $payload->appendChild($document->createCDATASection($content));
                $template->appendChild($payload);
            }
        }
    }
1187134
private static function createTypeElement(\DOMDocument $document, $parentElement = null, $type)
    {
        if ($parentElement->parentNode === null) {
            $typeElement = $document->createElementNS(
                'https://github.com/RhubarbPHP/Rhubarb/blob/master/docs/simple-xml-transcoder.md',
                self::XMLNS . ':' . $type
            );
            $parentElement->appendChild($typeElement);
        } else {
            $parentElement->setAttribute(self::XMLNS . ':' . self::ATTR_TYPE, $type);
            $typeElement = $parentElement;
        }

        return $typeElement;
    }
981527
protected function createTreeNodeDOMElement( DOMDocument $domDocument, eZContentObjectTreeNode $node )
    {
        $nodeElement = $domDocument->createElement( 'Node' );

        // Set attributes.
        $nodeElement->setAttribute( 'nodeID', $node->attribute( 'node_id' ) );
        $nodeElement->setAttribute( 'parentID', $node->attribute( 'parent_node_id' ) );

        // Get child information.
        $conditions = array( 'Depth' => 1,
                             'DepthOperator' => 'eq' );
        $nodeElement->setAttribute( 'childCount', eZContentObjectTreeNode::subTreeCountByNodeID( $conditions, $node->attribute( 'node_id' ) ) );

        // Get child information for tree structure.
        $conditions['ClassFilterType'] = 'include';
        $conditions['ClassFilterArray'] = eZINI::instance( 'contentstructuremenu.ini' )->variable( 'TreeMenu', 'ShowClasses' );
        $nodeElement->setAttribute( 'childMenuCount', eZContentObjectTreeNode::subTreeCountByNodeID( $conditions, $node->attribute( 'node_id' ) ) );

        // Get access rights element.
        $nodeElement->appendChild( $this->createAccessDOMElement( $domDocument, $node ) );

        // Get object element.
        $nodeElement->appendChild( $this->createObjectDOMElement( $domDocument, $node->attribute( 'object' ) ) );

        return $nodeElement;
    }
438408
public static function getJSNodes(DOMDocument $dom)
	{
		$regexp = '/^(?:data-s9e-livepreview-postprocess$|on)/i';
		$nodes  = array_merge(
			self::getAttributesByRegexp($dom, $regexp),
			self::getElementsByRegexp($dom, '/^script$/i')
		);

		return $nodes;
	}
1303393
public function writeXml(DOMDocument $dom = null)
    {
        if (null === $dom) {
            $errMsg = 'Не передан DOMDocument';
            throw new InvalidWriteWorkflowException($errMsg);
        }
        $descriptor = $dom->createElement('register');


        if ($this->hasId()) {
            $id = $this->getId();
            $descriptor->setAttribute('id', $id);
        }

        $variableName = $this->getVariableName();
        if (null === $variableName) {
            $errMsg = 'Некорректное значение для атрибута variable-name';
            throw new InvalidDescriptorException($errMsg);
        }
        $descriptor->setAttribute('variable-name', $variableName);

        $type = $this->getType();
        if (null === $type) {
            $errMsg = 'Некорректное значение для атрибута type';
            throw new InvalidDescriptorException($errMsg);
        }

        $descriptor->setAttribute('type', $type);

        $this->writeArgs($descriptor);

        return $descriptor;
    }
1212178
private function readDocument(\DOMDocument $document, $workflowId = null)
    {
        $errorToExceptionContext = new ErrorToExceptionContext(E_WARNING, function () use ($document) {
            $document->schemaValidate(dirname(__DIR__).'/Resources/config/workflower/schema/BPMN20.xsd');
        });
        $errorToExceptionContext->invoke();

        $workflowBuilder = new WorkflowBuilder($workflowId);

        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'process') as $element) {
            /* @var $element \DOMElement */
            if ($element->hasAttribute('id')) {
                $workflowBuilder->setWorkflowId($element->getAttribute('id'));
            }

            if ($element->hasAttribute('name')) {
                $workflowBuilder->setWorkflowName($element->getAttribute('name'));
            }
        }

        $flowObjectRoles = array();
        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'lane') as $element) {
            if (!$element->hasAttribute('id')) {
                throw $this->createIdAttributeNotFoundException($element, $workflowId);
            }

            $workflowBuilder->addRole(
                $element->getAttribute('id'),
                $element->hasAttribute('name') ? $element->getAttribute('name') : null
            );

            foreach ($element->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'flowNodeRef') as $childElement) {
                $flowObjectRoles[$childElement->nodeValue] = $element->getAttribute('id');
            }
        }

        if (count($flowObjectRoles) == 0) {
            $workflowBuilder->addRole(Workflow::DEFAULT_ROLE_ID);
        }

        $messages = array();
        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'message') as $element) {
            if (!$element->hasAttribute('id')) {
                throw $this->createIdAttributeNotFoundException($element, $workflowId);
            }

            $messages[$element->getAttribute('id')] = $element->getAttribute('name');
        }

        $operations = array();
        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'operation') as $element) {
            if (!$element->hasAttribute('id')) {
                throw $this->createIdAttributeNotFoundException($element, $workflowId);
            }

            $operations[$element->getAttribute('id')] = $element->getAttribute('name');
        }

        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'startEvent') as $element) {
            if (!$element->hasAttribute('id')) {
                throw $this->createIdAttributeNotFoundException($element, $workflowId);
            }

            $workflowBuilder->addStartEvent(
                $element->getAttribute('id'),
                $this->provideRoleIdForFlowObject($flowObjectRoles, $element->getAttribute('id')),
                $element->hasAttribute('name') ? $element->getAttribute('name') : null,
                $element->hasAttribute('default') ? $element->getAttribute('default') : null
            );
        }

        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'task') as $element) {
            if (!$element->hasAttribute('id')) {
                throw $this->createIdAttributeNotFoundException($element, $workflowId);
            }

            $workflowBuilder->addTask(
                $element->getAttribute('id'),
                $this->provideRoleIdForFlowObject($flowObjectRoles, $element->getAttribute('id')),
                $element->hasAttribute('name') ? $element->getAttribute('name') : null,
                $element->hasAttribute('default') ? $element->getAttribute('default') : null
            );
        }

        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'serviceTask') as $element) {
            if (!$element->hasAttribute('id')) {
                throw $this->createIdAttributeNotFoundException($element, $workflowId);
            }

            $workflowBuilder->addServiceTask(
                $element->getAttribute('id'),
                $this->provideRoleIdForFlowObject($flowObjectRoles, $element->getAttribute('id')),
                $element->hasAttribute('operationRef') ? $operations[$element->getAttribute('operationRef')] : null,
                $element->hasAttribute('name') ? $element->getAttribute('name') : null,
                $element->hasAttribute('default') ? $element->getAttribute('default') : null
            );
        }

        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'sendTask') as $element) {
            if (!$element->hasAttribute('id')) {
                throw $this->createIdAttributeNotFoundException($element, $workflowId);
            }

            $workflowBuilder->addSendTask(
                $element->getAttribute('id'),
                $this->provideRoleIdForFlowObject($flowObjectRoles, $element->getAttribute('id')),
                $element->hasAttribute('messageRef') ? $messages[$element->getAttribute('messageRef')] : null,
                $element->hasAttribute('operationRef') ? $operations[$element->getAttribute('operationRef')] : null,
                $element->hasAttribute('name') ? $element->getAttribute('name') : null,
                $element->hasAttribute('default') ? $element->getAttribute('default') : null
            );
        }

        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'exclusiveGateway') as $element) {
            if (!$element->hasAttribute('id')) {
                throw $this->createIdAttributeNotFoundException($element, $workflowId);
            }

            $workflowBuilder->addExclusiveGateway(
                $element->getAttribute('id'),
                $this->provideRoleIdForFlowObject($flowObjectRoles, $element->getAttribute('id')),
                $element->hasAttribute('name') ? $element->getAttribute('name') : null,
                $element->hasAttribute('default') ? $element->getAttribute('default') : null
            );
        }

        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'endEvent') as $element) {
            if (!$element->hasAttribute('id')) {
                throw $this->createIdAttributeNotFoundException($element, $workflowId);
            }

            $workflowBuilder->addEndEvent($element->getAttribute('id'), $this->provideRoleIdForFlowObject($flowObjectRoles, $element->getAttribute('id')), $element->hasAttribute('name') ? $element->getAttribute('name') : null);
        }

        foreach ($document->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'sequenceFlow') as $element) {
            if (!$element->hasAttribute('id')) {
                throw $this->createIdAttributeNotFoundException($element, $workflowId);
            }

            $condition = null;
            foreach ($element->getElementsByTagNameNs('http://www.omg.org/spec/BPMN/20100524/MODEL', 'conditionExpression') as $childElement) {
                $condition = $childElement->nodeValue;
                break;
            }

            $workflowBuilder->addSequenceFlow(
                $element->getAttribute('sourceRef'),
                $element->getAttribute('targetRef'),
                $element->getAttribute('id'),
                $element->hasAttribute('name') ? $element->getAttribute('name') : null,
                $condition === null ? null : $condition
            );
        }

        return $workflowBuilder->build();
    }
934891
public static function createFromSoapFault(\DOMDocument $document)
    {
        $response = null;
        $errorElement = $document->getElementsByTagNameNS(OrderService::NAMESPACE_SOAP, 'Fault');

        if ($errorElement->length > 0) {
            $response = new Error();

            $faultCode              = $document->getElementsByTagName('faultcode');
            $response->errorMessage = $document->getElementsByTagName('faultstring')->item(0)->nodeValue;

            switch ($faultCode->item(0)->nodeValue) {
                case self::SOAP_ERROR_SERVER:
                    $response->errorType = self::ERROR_TYPE_SERVER;

                    break;

                case self::SOAP_ERROR_CLIENT:
                    $response->errorType   = self::ERROR_TYPE_CLIENT;
                    $errorDetail = $document->getElementsByTagName('detail');

                    if (strpos($response->errorMessage, ':') !== false) {
                        $response->clientErrorType = substr($response->errorMessage, 0, strpos($response->errorMessage, ':'));
                    } else {
                        $response->clientErrorType = $response->errorMessage;
                    }

                    switch ($response->clientErrorType) {
                        case self::SOAP_CLIENT_ERROR_MERCHANT:
                            $response->clientErrorDetail = $errorDetail->item(0)->nodeValue;
                            break;

                        case self::SOAP_CLIENT_ERROR_PROCESSING:
                            $response->clientErrorDetail = $response->firstElementByTagNSString($document, OrderService::NAMESPACE_N3, 'ErrorMessage');;
                            break;

                        default:
                            throw new \Exception("Undefined SOAP Client Exception: " . $response->clientErrorType . ' (Complete SOAP Fault: ' . $document->saveXML() . ')');
                    }
                    break;

                default:
                    throw new \Exception("Undefined SOAP Error: (" . $document->saveXML() . ")");
            }
        }

        return $response;
    }
336070
private function importXml(\DOMDocument $doc)
    {
        $importNodes=$doc->getElementsByTagName("import");
        for($i=$importNodes->length-1;$i>=0;$i--){
            $node = $importNodes->item($i);
            if($node->hasAttribute("file")){
                $file=$node->getAttribute("file");
                $path=rtrim(dirname($this->m_configFile),"/");
                $file=$path."/".ltrim($file,"/");
                if(file_exists($file)){
                    $_doc=new \DOMDocument();
                    $_doc->load($file);
                    $this->importXml($_doc);
                    $children=$_doc->documentElement->childNodes;
                    for($j=0;$j<$children->length;$j++){
                        $_node=$children->item($j);
                        if(is_a($_node,"DOMElement")){
                            $_node = $doc->importNode($_node, true);
                            $node->parentNode->insertBefore($_node,$node);
                        }
                    }
                    if(!in_array($file, $this->m_configFiles)){
                        $this->m_configFiles[]=$file;
                    }
                }
            }
            $node->parentNode->removeChild($node);
        }
    }
897256
public function writeXml(DOMDocument $dom = null)
    {
        $countConditions = $this->getConditions()->count();

        if ($countConditions > 0) {
            $descriptor = $dom->createElement('conditions');

            if ($countConditions > 1) {
                $type = $this->getType();
                if (null === $type) {
                    $errMsg = 'Некорректное значение для атрибута type';
                    throw new InvalidDescriptorException($errMsg);
                }
                $descriptor->setAttribute('type', $type);
            }

            foreach ($this->getConditions() as $condition) {
                $conditionDescriptor = $condition->writeXml($dom);
                $descriptor->appendChild($conditionDescriptor);
            }

            return $descriptor;
        }

        return null;
    }
1229927
public function parseDocument(\DOMDocument $document)
    {
        $doc = $this->extensions->parseDocument($document);
        if ($doc) {
            return $doc;
        }

        throw new \InvalidArgumentException(
            sprintf('Unexpected root element "%s"', $document->documentElement->localName)
        );
    }