Validate and return the asserts from the validation process based on a xml string

@param string $xmlString
@return Asserts|\CfdiUtils\Validate\Assert[]
514029
public function validateXml(string $xmlString): Asserts
    {
        return $this->validate($xmlString, XmlNodeUtils::nodeFromXmlString($xmlString));
    }
774498
final public static function xmlEscape($strString)
    {
        if ((mb_strpos($strString, '<', 0, QCUBED_ENCODING) !== false) ||
            (mb_strpos($strString, '&', 0, QCUBED_ENCODING) !== false)
        ) {
            $strString = str_replace(']]>', ']]]]><![CDATA[>', $strString);
            $strString = sprintf('<![CDATA[%s]]>', $strString);
        }

        return $strString;
    }
713345
public static function checkString($xml, $filename = '')
    {
        $doc = Utilities::stringToDOMDocument($xml, $filename);
        $errors = null;
        $preUseInternalErrors = libxml_use_internal_errors(true);
        try {
            if (!$doc->schemaValidateSource(static::getSchema())) {
                $errors = Utilities::explainLibXmlErrors($filename);
            }
        } catch (Exception $x) {
            libxml_use_internal_errors($preUseInternalErrors);
            libxml_clear_errors();
            throw $x;
        }
        libxml_use_internal_errors($preUseInternalErrors);

        return $errors;
    }
1097619
private function checkDateString($dateTimeString)
    {
        if (empty($dateTimeString)) {
            return null;
        }

        try {
            $date = new \DateTime($dateTimeString);
        } catch (Exception $e) {
            return null;
        }

        return $date;
    }
85021
public function removeAnnouncement($xmlString)
    {
        $matches = [];

        preg_match('/<?xml version="(.*)" encoding="(.*)"?>(.*)$/isuU', $xmlString, $matches);

        return isset($matches[3]) ? $matches[3] : $xmlString;
    }
1098695
public static function parse($string)
    {
        if (static::isJSON($string)) {
            $result = static::jsonDecode($string);
        } elseif (static::isXML($string)) {
            $result = static::xmlDecode($string);
        } else {
            throw new \InvalidArgumentException(sprintf('Unable to parse: %s', (string) $string));
        }

        return (array) $result;
    }
1331695
public function validate(DOMDocument $xml)
    {
        $errors = [];

        $xpath = new DOMXPath($xml);
        foreach ($xpath->query('//link') as $link) {
            if ($link->hasAttribute('object_id')) {
                $objectId = $link->getAttribute('object_id');
                if ($objectId && !$this->validateEzObject($objectId)) {
                    $errors[] = $this->getInvalidLinkError('ezobject', $objectId, $link->getAttribute('anchor_name'));
                }
            } elseif ($link->hasAttribute('node_id')) {
                $nodeId = $link->getAttribute('node_id');
                if ($nodeId && !$this->validateEzNode($nodeId)) {
                    $errors[] = $this->getInvalidLinkError('eznode', $nodeId, $link->getAttribute('anchor_name'));
                }
            }
        }

        return $errors;
    }
226922
function xmlString()
    {
        $doc = new DOMDocument( '1.0', 'utf-8' );
        $root = $doc->createElement( "ezmultioption2" );
        $doc->appendChild( $root );


        $this->createDomElementForGroup( $doc, $root );

        $rulesNode = $doc->createElement( "rules" );

        foreach ( $this->Rules as $ruleFor => $rule )
        {
            unset( $ruleNode );
            $ruleNode = $doc->createElement( "rule" );
            $ruleNode->setAttribute( "option_id", $ruleFor );
            foreach ( $rule as $multioptionID => $ruleData )
            {
                unset( $ruleDataNode );
                $ruleDataNode = $doc->createElement( "rule_data" );
                $ruleDataNode->setAttribute( "multioption_id", $multioptionID );
                foreach ( $ruleData as $optionID )
                {
                    unset( $includeNode );
                    $includeNode = $doc->createElement( "option_id", $optionID );
                    $ruleDataNode->appendChild( $includeNode );
                }
                $ruleNode->appendChild( $ruleDataNode );
            }
            $rulesNode->appendChild( $ruleNode );
        }
        $root->appendChild( $rulesNode );

        $xml = $doc->saveXML();
        return $xml;
    }
797973
protected function initFromSpec(string $specString)
    {
        $pattern = '/
        (
                (?:[a-zA-Z0-9-]+)
                (?:
                    \|
                    (?:[a-zA-Z0-9-]+)
                )?
        )

        # option attribute operators
        ([:+?])?

        # value types
        (?:=(bool|boolean|string|int|number|date|datetime|file|dir|url|email|ip|ipv6|ipv4))?
        /x';
        $ret = preg_match($pattern, $specString, $regs);
        if ($ret === false || $ret === 0) {
            throw new InvalidArgumentException('Incorrect spec string');
        }

        // $orig = $regs[0];
        $name = $regs[1];
        $attributes = $regs[2] ?? null;
        $type = $regs[3] ?? null;

        $short = null;
        $long = null;

        // check long,short option name.
        if (strpos($name, '|') !== false) {
            list($short, $long) = explode('|', $name);
        } elseif (strlen($name) === 1) {
            $short = $name;
        } elseif (strlen($name) > 1) {
            $long = $name;
        }

        $this->short = $short;
        $this->long = $long;

        // option is required.
        if (strpos($attributes, ':') !== false) {
            $this->required();
        } elseif (strpos($attributes, '+') !== false) {
            // option with multiple value
            $this->multiple();
        } elseif (strpos($attributes, '?') !== false) {
            // option is optional.(zero or one value)
            $this->optional();
        } else {
            $this->flag();
        }
        if ($type) {
            $this->isa($type);
        }
    }
668397
public static function xml2array($xmlstring)
    {
        $result = [];
        self::normalizeSimpleXML(simplexml_load_string($xmlstring, null, LIBXML_NOCDATA), $result);

        return $result;
    }
112940
public function restoreValueFromXmlString($xmlString)
    {
        $zones = array();
        $attributes = array();
        $layout = null;

        if ($xmlString) {
            $dom = new DOMDocument('1.0', 'utf-8');
            $dom->loadXML($xmlString);
            $root = $dom->documentElement;

            foreach ($root->childNodes as $node) {
                if ($node->nodeType !== XML_ELEMENT_NODE) {
                    continue;
                }

                switch ($node->nodeName) {
                    case 'zone':
                        $zone = $this->restoreZoneFromXml($node);
                        $zones[] = $zone;
                        break;
                    case 'zone_layout':
                        $layout = $node->nodeValue;
                        break;
                    default:
                        $attributes[$node->nodeName] = $node->nodeValue;
                        break;
                }
            }

            if ($root->hasAttributes()) {
                foreach ($root->attributes as $attr) {
                    $attributes[$attr->name] = $attr->value;
                }
            }
        }

        return new Parts\Page(
            array(
                'zones' => $zones,
                'layout' => $layout,
                'attributes' => $attributes,
            )
        );
    }
1299985
protected function processReport($xmlString)
    {
        $xml = simplexml_load_string($xmlString);

        if ($xml === false) {
            $this->phpci->log($xmlString);
            throw new \Exception('Could not process PHPMD report XML.');
        }

        $warnings = 0;

        foreach ($xml->file as $file) {
            $fileName = (string)$file['name'];
            $fileName = str_replace($this->phpci->buildPath, '', $fileName);

            foreach ($file->violation as $violation) {
                $warnings++;

                $this->build->reportError(
                    $this->phpci,
                    'php_mess_detector',
                    (string)$violation,
                    PHPCI\Model\BuildError::SEVERITY_HIGH,
                    $fileName,
                    (int)$violation['beginline'],
                    (int)$violation['endline']
                );
            }
        }

        return $warnings;
    }
1108148
public function validateMetadata($xml)
    {
        assert('is_string($xml)');

        $errors = array();
        $res = OneLogin_Saml2_Utils::validateXML($xml, 'saml-schema-metadata-2.0.xsd', $this->_debug);
        if (!$res instanceof DOMDocument) {
            $errors[] = $res;
        } else {
            $dom = $res;
            $element = $dom->documentElement;
            if ($element->tagName !== 'md:EntityDescriptor') {
                $errors[] = 'noEntityDescriptor_xml';
            } else {
                $validUntil = $cacheDuration = $expireTime = null;

                if ($element->hasAttribute('validUntil')) {
                    $validUntil = OneLogin_Saml2_Utils::parseSAML2Time($element->getAttribute('validUntil'));
                }
                if ($element->hasAttribute('cacheDuration')) {
                    $cacheDuration = $element->getAttribute('cacheDuration');
                }

                $expireTime = OneLogin_Saml2_Utils::getExpireTime($cacheDuration, $validUntil);
                if (isset($expireTime) && time() > $expireTime) {
                    $errors[] = 'expired_xml';
                }
            }
        }

        // TODO: Support Metadata Sign Validation

        return $errors;
    }
1234368
function decodeXML( $xmlString )
    {
        $dom = new DOMDocument( '1.0', 'utf-8' );
        $success = $dom->loadXML( $xmlString );

        if ( $success )
        {
            $authors = $dom->getElementsByTagName( 'author' );
            foreach ( $authors as $author )
            {
                $this->addAuthor( $author->getAttribute( "id" ), $author->getAttribute( "name" ), $author->getAttribute( "email" ) );
            }
        }
    }
427385
public function validateNode(NodeInterface $node): Asserts
    {
        return $this->validate(XmlNodeUtils::nodeToXmlString($node), $node);
    }
1061468
public function convert($xmlString) {

        $dom = new \DOMDocument ();
        $dom->loadXML($xmlString);

        $documentElement = $dom->documentElement;
        return $documentElement ? $this->convertDOM($dom->documentElement) : $xmlString;
    }
489102
public function read($string)
    {
        try {
            $wasUsingErrors = libxml_use_internal_errors();
            @$xmlObject = simplexml_load_string($string);
            libxml_use_internal_errors($wasUsingErrors);
            if ($xmlObject) {
                return $this->recurseToArray($xmlObject);
            }
        } catch (\Exception $e) {
            // Do nothing
        }
        return null;
    }