Parse conditions in assertion.

@param \DOMElement $xml The assertion XML element.
@throws \Exception
@return void
777820
private function parseConditions(DOMElement $xml) : void
    {
        /** @var \DOMElement[] $conditions */
        $conditions = Utils::xpQuery($xml, './saml_assertion:Conditions');
        if (empty($conditions)) {
            /* No <saml:Conditions> node. */

            return;
        } elseif (count($conditions) > 1) {
            throw new \Exception('More than one <saml:Conditions> in <saml:Assertion>.');
        }
        $conditions = $conditions[0];

        if ($conditions->hasAttribute('NotBefore')) {
            $notBefore = Utils::xsDateTimeToTimestamp($conditions->getAttribute('NotBefore'));
            if ($this->getNotBefore() === null || $this->getNotBefore() < $notBefore) {
                $this->setNotBefore($notBefore);
            }
        }
        if ($conditions->hasAttribute('NotOnOrAfter')) {
            $notOnOrAfter = Utils::xsDateTimeToTimestamp($conditions->getAttribute('NotOnOrAfter'));
            if ($this->getNotOnOrAfter() === null || $this->getNotOnOrAfter() > $notOnOrAfter) {
                $this->setNotOnOrAfter($notOnOrAfter);
            }
        }

        foreach ($conditions->childNodes as $node) {
            if (!$node instanceof DOMElement) {
                continue;
            }
            if ($node->namespaceURI !== Constants::NS_SAML) {
                throw new \Exception('Unknown namespace of condition: '.var_export($node->namespaceURI, true));
            }
            switch ($node->localName) {
                case 'AudienceRestriction':
                    $audiences = Utils::extractStrings($node, Constants::NS_SAML, 'Audience');
                    if ($this->validAudiences === null) {
                        /* The first (and probably last) AudienceRestriction element. */
                        $this->validAudiences = $audiences;
                    } else {
                        /*
                         * The set of AudienceRestriction are ANDed together, so we need
                         * the subset that are present in all of them.
                         */
                        $this->validAudiences = array_intersect($this->validAudiences, $audiences);
                    }
                    break;
                case 'OneTimeUse':
                    /* Currently ignored. */
                    break;
                case 'ProxyRestriction':
                    /* Currently ignored. */
                    break;
                default:
                    throw new \Exception('Unknown condition: '.var_export($node->localName, true));
            }
        }
    }
593
protected function parseArgs(DOMElement $element)
    {
        $args = XmlUtil::getChildElements($element, 'arg');
        foreach ($args as $arg) {
            $name = XmlUtil::getRequiredAttributeValue($arg, 'name');
            $this->args[$name] = XmlUtil::getText($arg);
        }
    }
27619
public function addXML($xml)
    {
        $next_elem = $this->createDocumentFragment();
        $next_elem->appendXML($xml);
        $this->doc->appendChild($next_elem);

    }
346204
protected function cleanHrefs(\DOMElement $element)
    {
        $href = $element->getAttribute('href');
        if (preg_match(self::SCRIPT_REGEX, $href) === 1) {
            $element->removeAttribute('href');
            $this->xmlIssues[] = array(
                'message' => 'Suspicious attribute \'href\'',
                'line' => $element->getLineNo(),
            );
        }
    }
1093879
public static function fromXml(\DOMElement $xml)
    {
        $static = new static();
        $static->libraryItemMetadata = LibraryItemMetadata::fromXml($xml);
        $static->pickupLocation = PickupLocation::fromXml($xml);

        $requestStartDate = $xml->getElementsByTagName('requestDate');
        $requestEndDate = $xml->getElementsByTagName('endRequestDate');
        $static->requestDateRange = DateTimeRange::fromXml($requestStartDate, $requestEndDate);

        $holdStartDate = $xml->getElementsByTagName('holdDate');
        $holdEndDate = $xml->getElementsByTagName('endHoldDate');
        $static->holdDateRange = DateTimeRange::fromXml($holdStartDate, $holdEndDate);

        $cancelable = $xml->getElementsByTagName('cancelable');
        $static->cancelable = BoolLiteral::fromXml($cancelable);

        $stringLiterals = array(
            'requestNumber' => $xml->getElementsByTagName('requestNumber'),
            'sequence' => $xml->getElementsByTagName('sequence'),
            'queuePosition' => $xml->getElementsByTagName('queuePosition'),
            'itemSequence' => $xml->getElementsByTagName('itemSequence'),
            'status' => $xml->getElementsByTagName('status'),
        );
        foreach ($stringLiterals as $propertyName => $xmlTag) {
            $static->$propertyName = StringLiteral::fromXml($xmlTag);
        }

        return $static;
    }
319338
protected function logBadXML($xml)
    {
        $file = @fopen($this->badXmlLog, 'a');
        if (!$file) {
            throw new \Exception("Problem opening {$this->badXmlLog}.");
        }
        fputs($file, $xml . "\n\n");
        fclose($file);
    }
383178
public function check(DOMElement $template, Tag $tag)
	{
		$this->template = $template;
		$this->checkEmbeds();
		$this->checkObjects();
	}
988348
protected function parseName(DOMElement $element, $flagRequired = false)
    {
        if ($flagRequired || (!$flagRequired && $element->hasAttribute('name'))) {
            $this->name = XmlUtil::getRequiredAttributeValue($element, 'name');
        }
    }
1168845
protected function init(DOMElement $action)
    {
        $this->parseId($action);
        $this->parseName($action);

        if ($action->hasAttribute('view')) {
            $view = XmlUtil::getRequiredAttributeValue($action, 'view');
            $this->setView($view);
        }

        if ($action->hasAttribute('auto')) {
            $autoValue = XmlUtil::getRequiredAttributeValue($action, 'auto');
            $auto = strtolower($autoValue);
            $autoExecute = 'true' === $auto;
            $this->setAutoExecute($autoExecute);
        }

        if ($action->hasAttribute('finish')) {
            $finishValue = XmlUtil::getRequiredAttributeValue($action, 'finish');
            $finish = strtolower($finishValue);
            $finish = 'true' === $finish;
            $this->setFinish($finish);
        }

        $metaElements = XmlUtil::getChildElements($action, 'meta');
        $metaAttributes = [];
        foreach ($metaElements as $meta) {
            $value = XmlUtil::getText($meta);
            $name = XmlUtil::getRequiredAttributeValue($meta, 'name');

            $metaAttributes[$name] = $value;
        }
        $this->setMetaAttributes($metaAttributes);

        // set up validators -- OPTIONAL
        $v = XMLUtil::getChildElement($action, 'validators');
        if (null !== $v) {
            $validators = XMLUtil::getChildElements($v, 'validator');
            foreach ($validators as $validator) {
                $validatorDescriptor = DescriptorFactory::getFactory()->createValidatorDescriptor($validator);
                $validatorDescriptor->setParent($this);
                $this->validators->attach($validatorDescriptor);
            }
        }

        // set up pre-functions -- OPTIONAL
        $pre = XMLUtil::getChildElement($action, 'pre-functions');
        if (null !== $pre) {
            $preFunctions = XMLUtil::getChildElements($pre, 'function');
            foreach ($preFunctions as $preFunction) {
                $functionDescriptor = DescriptorFactory::getFactory()->createFunctionDescriptor($preFunction);
                $functionDescriptor->setParent($this);
                $this->preFunctions->attach($functionDescriptor);
            }
        }

        // set up results - REQUIRED
        $resultsElement = XMLUtil::getChildElement($action, 'results');
        if (!$resultsElement instanceof DOMElement) {
            $errMsg = 'Отсутствует обязательный блок results';
            throw new InvalidWorkflowDescriptorException($errMsg);
        }
        $results = XMLUtil::getChildElements($resultsElement, 'result');
        foreach ($results as $result) {
            $conditionalResultDescriptor = new ConditionalResultDescriptor($result);
            $conditionalResultDescriptor->setParent($this);
            $this->conditionalResults->attach($conditionalResultDescriptor);
        }

        $unconditionalResult = XMLUtil::getChildElement($resultsElement, 'unconditional-result');
        if (null !== $unconditionalResult) {
            $unconditionalResult = DescriptorFactory::getFactory()->createResultDescriptor($unconditionalResult);
            $unconditionalResult->setParent($this);
            $this->setUnconditionalResult($unconditionalResult);
        }


        // set up post-functions - OPTIONAL
        $post = XMLUtil::getChildElement($action, 'post-functions');
        if (null !== $post) {
            $postFunctions = XMLUtil::getChildElements($post, 'function');
            foreach ($postFunctions as $postFunction) {
                $functionDescriptor = DescriptorFactory::getFactory()->createFunctionDescriptor($postFunction);
                $functionDescriptor->setParent($this);
                $this->postFunctions->attach($functionDescriptor);
            }
        }

        // set up restrict-to - OPTIONAL
        $restrictElement = XMLUtil::getChildElement($action, 'restrict-to');
        if (null !== $restrictElement) {
            $restriction = new RestrictionDescriptor($restrictElement);

            if (null !== $restriction->getConditionsDescriptor()) {
                $restriction->setParent($this);
                $this->setRestriction($restriction);
            }
        }
    }
1182707
protected function parseXml($xml) {
        if (!$xml){
            return false;
        }

        if (isset($xml->Subscription)) {
            $this->data = array();
            $this->data['NotificationType'] = (string)$xml->Subscription->NotificationType;
            $this->data['IsEnabled'] = (string)$xml->Subscription->IsEnabled;
            $this->data['Destination']['DeliveryChannel'] = (string)$xml->Subscription->Destination->DeliveryChannel;
            foreach ($xml->Subscription->Destination->AttributeList->children() as $x) {
                $this->data['Destination']['AttributeList'][(string)$x->Key] = (string)$x->Value;
            }
        }
    }
940079
protected function checkUnsupported($xml)
	{
		if (strpos($xml, '<!') !== false)
		{
			throw new InvalidArgumentException('DTDs, CDATA nodes and comments are not allowed');
		}
		if (strpos($xml, '<?') !== false)
		{
			throw new InvalidArgumentException('Processing instructions are not allowed');
		}
	}
361610
protected function parseXML($xml){
        if (!$xml){
            return false;
        }
        foreach($xml->children() as $key=>$x){
            if ($key == 'Count'){
                $this->count = (string)$x;
            }
            if ($key != 'ReportSchedule'){
                continue;
            }
            $i = $this->index;
            
            $this->scheduleList[$i]['ReportType'] = (string)$x->ReportType;
            $this->scheduleList[$i]['Schedule'] = (string)$x->Schedule;
            $this->scheduleList[$i]['ScheduledDate'] = (string)$x->ScheduledDate;
            
            $this->index++;
        }
    }
112141
public static function fromXml(\DOMElement $xml)
    {
        $static = new static();

        $title = $xml->getElementsByTagName('title');
        $static->title = StringLiteral::fromXml($title);

        $author = $xml->getElementsByTagName('author');
        $static->author = StringLiteral::fromXml($author);

        $year = $xml->getElementsByTagName('year');
        $static->year = StringLiteral::fromXml($year);

        $imprint = $xml->getElementsByTagName('imprint');
        $static->imprint = StringLiteral::fromXml($imprint);

        $url = $xml->getElementsByTagName('docUrl');
        $static->url = Path::fromXml($url);

        $isbnIssn = $xml->getElementsByTagName('isbn_issn');
        $static->isbnIssn = StringLiteral::fromXml($isbnIssn);

        $docNumber = $xml->getElementsByTagName('docNumber');
        $static->docNumber = StringLiteral::fromXml($docNumber);

        $itemId = $xml->getElementsByTagName('itemId');
        $static->itemId = StringLiteral::fromXml($itemId);

        return $static;
    }
986688
private function parseAuthnStatement(DOMElement $xml) : void
    {
        /** @var \DOMElement[] $authnStatements */
        $authnStatements = Utils::xpQuery($xml, './saml_assertion:AuthnStatement');
        if (empty($authnStatements)) {
            $this->authnInstant = null;

            return;
        } elseif (count($authnStatements) > 1) {
            throw new \Exception('More than one <saml:AuthnStatement> in <saml:Assertion> not supported.');
        }
        $authnStatement = $authnStatements[0];

        if (!$authnStatement->hasAttribute('AuthnInstant')) {
            throw new \Exception('Missing required AuthnInstant attribute on <saml:AuthnStatement>.');
        }
        $this->authnInstant = Utils::xsDateTimeToTimestamp($authnStatement->getAttribute('AuthnInstant'));

        if ($authnStatement->hasAttribute('SessionNotOnOrAfter')) {
            $this->sessionNotOnOrAfter = Utils::xsDateTimeToTimestamp(
                $authnStatement->getAttribute('SessionNotOnOrAfter')
            );
        }

        if ($authnStatement->hasAttribute('SessionIndex')) {
            $this->sessionIndex = $authnStatement->getAttribute('SessionIndex');
        }

        $this->parseAuthnContext($authnStatement);
    }
1317172
public static function assert(\DOMDocument $dom) {
        $queryNode = (new \DOMXPath($dom))->query("/BPQL/header/exception");
        if ($queryNode->length) {
            $nodeException = $queryNode->item(0);
            $source = $nodeException->getAttribute("source");
            $code = $nodeException->getAttribute("code");
            $id = $nodeException->getAttribute("id");
            $pushable = ($nodeException->getAttribute("pushable") ?: $nodeException->getAttribute("push")) === "true";
            $message = $nodeException->nodeValue;

            $e = new Exception(sprintf("[%s:%s/%s] %s", $code, $source, $id, $message, $pushable), $code);
            $e->setAttributes($code, $source, $id, $message, $pushable);
            throw $e;
        }
    }
1070820
public function doProcess( $xml ) {

		$domDocument = new DOMDocument();
		$domDocument->loadXml( $xml );

		$this->findElementsForPubMed( $domDocument );
		$this->findElementsForPubMedCentral( $domDocument );
	}
341862
protected function parseSOAP12Response($xml)
    {
        $doc = new \DOMDocument('1.0', 'UTF-8');

        if ($doc->loadXML($xml) === false) {
            throw new Exception('Failed load xml');
        }

        $response = new Response();

        // Get the standard CDATA elements
        foreach (array('uri', 'checkedby', 'doctype', 'charset') as $var) {
            $element = $doc->getElementsByTagName($var);
            if ($element->length) {
                $response->{'set' . ucfirst($var)}($element->item(0)->nodeValue);
            }
        }

        // Handle the bool element validity
        $element = $doc->getElementsByTagName('validity');
        if ($element->length && $element->item(0)->nodeValue === 'true') {
            $response->setValidity(true);
        } else {
            $response->setValidity(false);
        }

        if (!$response->isValidity()) {
            $errors = $doc->getElementsByTagName('error');
            foreach ($errors as $error) {
                $response->addError(new Error($error));
            }
        }
        $warnings = $doc->getElementsByTagName('warning');
        foreach ($warnings as $warning) {
            $response->addWarning(new Warning($warning));
        }

        return $response;
    }