fXmlRpc\Parser\XmlChecker::validXml PHP Method

validXml() public static method

public static validXml ( string $xml )
$xml string
    public static function validXml($xml)
    {
        $useErrors = libxml_use_internal_errors(true);
        $isCorrect = simplexml_load_string($xml);
        if ($isCorrect === false) {
            libxml_use_internal_errors($useErrors);
            throw ParserException::notXml($xml);
        }
        libxml_use_internal_errors($useErrors);
    }

Usage Example

Beispiel #1
0
 /** {@inheritdoc} */
 public function parse($xmlString)
 {
     if ($this->validateResponse) {
         XmlChecker::validXml($xmlString);
     }
     $result = xmlrpc_decode($xmlString, 'UTF-8');
     $toBeVisited = [&$result];
     while (isset($toBeVisited[0]) && ($value =& $toBeVisited[0])) {
         $type = gettype($value);
         if ($type === 'object') {
             $xmlRpcType = $value->{'xmlrpc_type'};
             if ($xmlRpcType === 'datetime') {
                 $value = DateTime::createFromFormat('Ymd\\TH:i:s', $value->scalar, isset($timezone) ? $timezone : ($timezone = new DateTimeZone('UTC')));
             } elseif ($xmlRpcType === 'base64') {
                 if ($value->scalar !== '') {
                     $value = Base64::serialize($value->scalar);
                 } else {
                     $value = null;
                 }
             }
         } elseif ($type === 'array') {
             foreach ($value as &$element) {
                 $toBeVisited[] =& $element;
             }
         }
         array_shift($toBeVisited);
     }
     if (is_array($result)) {
         reset($result);
         if (xmlrpc_is_fault($result)) {
             throw FaultException::fault($result);
         }
     }
     return $result;
 }
All Usage Examples Of fXmlRpc\Parser\XmlChecker::validXml
XmlChecker