/*
Turns the raw response into an xml object
@access private
@return object
769993
private function processResponse()
    {
        $xmlstr = '';
        $record = 0;
        foreach ($this->response as $line) {
            if ($record == 1) {
                $xmlstr .= $line;
            } elseif (substr($line, 0, 1) == '<') {
                $record = 1;
            } elseif (preg_match('/^HTTP\/1.[0-9]{1} ([5-9]{1}[0-9]{2}.*)/', $line, $matches)) {

                throw new ConnectionException($this->host . ': Service not available (' . trim($matches[1]) . ')');
            }
        }
        try {
            libxml_use_internal_errors(true);
            $xml = new SimpleXMLElement($xmlstr);
        } catch (\Exception $error) {

            throw new ConnectionException($error->getMessage());
        }
        if((string)$xml->attributes()->status === 'failed' )
        {
            throw new ApiFailedException($xml->error, intval($xml->error['code']));
        }
        if (!isset($error)) {
            // All is well :)
            return $xml;
        }
    }
1300293
public function toArray()
    {
        $response = $this->simpleXmlObject();
        
        // Converting the SimpleXMLElement Object to array()
        $response = json_encode($response);
        
        return (json_decode($response, true));
    }
532423
public function parseData(): self
    {
        if (!is_array($this->raw_data)) {
            throw new RuntimeException('Response must be an array');
        }

        if (!array_key_exists('status', $this->raw_data)) {
            $this->result_code = ResponseInterface::RESULT_DATA_MALFORMED;

            return $this;
        }

        $this->result_code = $this->raw_data['status'];

        // ios > 7 receipt validation
        if ($this->isIOS7StyleReceipt()) {
            $this->parseIOS7StyleReceipt();
        } elseif ($this->isIOS6StyleReceipt()) {
            $this->parseIOS6StyleReceipt();
        }

        return $this;
    }
1251699
public function serialize()
	{
		$xmlString = sprintf(
			'<%s %s>%s</%1$s>',
			$this->_getRootNodeName(),
			$this->_serializeRootAttributes(),
			$this->_serializeContents()
		);
		$canonicalXml = $this->_helper->getPayloadAsDoc($xmlString)->C14N();
		return $this->_canSerialize() ? $canonicalXml : '';
	}
923570
public function getDomDocumentResponse()
    {
        $response = $this->getResponse();
        $xml = new DOMDocument();
        $xml->loadXML($response);
        return $xml;
    }
918200
public function toXml($rst = null) {
        $statusCode = 200;
        if ($rst === null) {
            $this->content = $rst = curl_exec($this->curl);
            if ($rst === false) {
                log_warn(curl_error($this->curl), 'rest.err');
            }
            $this->code = $statusCode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
            curl_close($this->curl);
            $this->curl = null;
        } else {
            $this->content = $rst;
        }

        if ($statusCode == 200) {
            try {
                return @new \SimpleXMLElement($rst);
            } catch (\Exception $e) {
                return new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><response><error><code>512</code><msg>' . __('Not supported response format.@restful') . '</msg><body><![CDATA[' . $rst . ']]></body></error></response>');
            }
        } else {
            return new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><response><error><code>' . $statusCode . '</code><msg>' . status_header($statusCode) . '</msg><body><![CDATA[' . $rst . ']]></body></error></response>');
        }
    }
292946
protected function parseDataFromResponse()
    {
        $content = $this->rawResponse->body;
        $xml = simplexml_load_string($content);
        if (isset($xml->UploadId)) {
            return strval($xml->UploadId);
        }
        throw new OssException("cannot get UploadId");
    }
743877
protected function init()
    {
        if ($this->request->getResponseFormat() == 'xml') {
            $aggregated = new \SimpleXMLElement('<response/>');
            foreach ($this->responseRaw as $name => $response) {
                $child = $aggregated->addChild('classification');
                $child->addAttribute('classifier', $name);
                $xml = simplexml_load_string($response);

                if (! $xml instanceof \SimpleXMLElement) {
                    throw new ServiceReaderException('Failed parsing XML response.');
                }

                if ((string) $xml->status->attributes()->success !== 'true') {
                    throw new ServiceReaderException($xml->status->attributes()->statusCode);
                }

                foreach ($xml->readCalls->classify as $classify) {
                    $child->addAttribute('textCoverage', $classify->classification->attributes()->textCoverage);
                    foreach ($classify->classification->class as $class) {
                        $this->simplexmlImportXml($child, $class->asXML());
                    }
                }
            }

            return $aggregated->asXML();
        }

        if ($this->request->getResponseFormat() == 'json') {
            $aggregated = array();
            foreach ($this->responseRaw as $name => $response) {
                $current = json_decode($response, 1);

                if (! array_key_exists('success', $current)) {
                    throw new ServiceReaderException('Unable to complete request');
                }

                if ($current['success'] !== true) {
                    throw new ServiceReaderException($current['statusCode'] . ' ' . $current['errorMessage']);
                }

                array_key_exists('textCoverage', $current) ? '' : $current['textCoverage'] = null;
                array_key_exists('cls1', $current) ? '' : $current['cls1'] = null;

                $aggregated[] = array(
                    'classifier' => $name,
                    'textCoverage' => $current['textCoverage'],
                    'classes' => $current['cls1']
                );
            }

            return json_encode($aggregated);
        }

        return $this->responseRaw;
    }
230706
private function parse($body)
    {
        $xmlObject = simplexml_load_string($body);
        foreach ($xmlObject as $key => $value) {
            $response[$key] = (string) $value;
        }

        return $response;
    }
764217
protected function parseDataFromResponse()
    {
        $content = $this->rawResponse->body;
        if (empty($content)) {
            throw new OssException("body is null");
        }
        $xml = simplexml_load_string($content);
        return $xml;
    }
202791
private function createRawXmlDocument()
    {
        $xmlDocument = new \DOMDocument;
        $xmlDocument->encoding = 'UTF-8';
        $xmlDocument->strictErrorChecking = false;
        $xmlDocument->formatOutput = true;
        $libXmlState = libxml_use_internal_errors(true);
        $xmlDocument->loadHTML($this->getUnifiedHtml());
        libxml_clear_errors();
        libxml_use_internal_errors($libXmlState);
        $xmlDocument->normalizeDocument();

        return $xmlDocument;
    }
327098
public function getGeneratedXML()
    {

        $dom = new XmlDomConstruct('1.0', 'utf-8');
        $dom->fromMixed(array(
            'request' => $this->_args
        ));
        $post_data = $dom->saveXML();
        $post_data = str_replace('<request/>', '<request method="' . $this->_method . '" />', $post_data);
        $post_data = str_replace('<request>', '<request method="' . $this->_method . '">', $post_data);

        return $post_data;

    }
1271196
protected function parseDataFromResponse()
    {
        $content = $this->rawResponse->body;
        $config = new LifecycleConfig();
        $config->parseFromXml($content);
        return $config;
    }
627002
protected function parseDataFromResponse()
    {
        $content = $this->rawResponse->body;
        $xml = simplexml_load_string($content);
        $bucket = isset($xml->Bucket) ? strval($xml->Bucket) : "";
        $key = isset($xml->Key) ? strval($xml->Key) : "";
        $uploadId = isset($xml->UploadId) ? strval($xml->UploadId) : "";
        $nextPartNumberMarker = isset($xml->NextPartNumberMarker) ? intval($xml->NextPartNumberMarker) : "";
        $maxParts = isset($xml->MaxParts) ? intval($xml->MaxParts) : "";
        $isTruncated = isset($xml->IsTruncated) ? strval($xml->IsTruncated) : "";
        $partList = array();
        if (isset($xml->Part)) {
            foreach ($xml->Part as $part) {
                $partNumber = isset($part->PartNumber) ? intval($part->PartNumber) : "";
                $lastModified = isset($part->LastModified) ? strval($part->LastModified) : "";
                $eTag = isset($part->ETag) ? strval($part->ETag) : "";
                $size = isset($part->Size) ? intval($part->Size) : "";
                $partList[] = new PartInfo($partNumber, $lastModified, $eTag, $size);
            }
        }
        return new ListPartsInfo($bucket, $key, $uploadId, $nextPartNumberMarker, $maxParts, $isTruncated, $partList);
    }
1201864
public function parse()
    {
        try {
            $xml       = simplexml_load_string($this->parsedMail->getMessageBody());
        } catch(\Exception $e) {
            $this->warningCount++;

            return $this->failed('XML expected, but got something else. Make sure google is set to send XML based reports!');
        }


        $timestamp = strtotime($xml->attributes()->date);

        foreach ($xml->list as $reports) {
            $this->feedName = (string)$reports->attributes()->type;

            // If feed is known and enabled, validate data and save report
            if ($this->isKnownFeed() && $this->isEnabledFeed()) {
                foreach ($reports->url_info as $url_info) {
                    $url = (string)$url_info->attributes()->url;
                    $ip = (string)$url_info->attributes()->ip;

                    $urlData = getUrlData($url);

                    if (filter_var($ip, FILTER_VALIDATE_IP) === false) {
                        // No IP supplied by Google
                        if (!empty($urlData['host']) &&
                            !filter_var($urlData['host'], FILTER_VALIDATE_IP) === false
                        ) {
                            // Hostname is an IP address
                            $ip = $urlData['host'];
                        } else {
                            // We have no IP address, try to get the IP address by resolving the domain
                            $ip = @gethostbyname($urlData['host']);

                            // If it fails, set to localhost
                            $ip = ($ip == $urlData['host']) ? '127.0.0.1' : $ip;
                        }
                    }

                    $report = [
                        'domain'    => getDomain($url),
                        'uri'       => getUri($url),
                        'category'  => config("{$this->configBase}.feeds.{$this->feedName}.category"),
                    ];

                    // Sanity check
                    if ($this->hasRequiredFields($report) === true) {
                        // incident has all requirements met, filter and add!
                        $report = $this->applyFilters($report);

                        $incident = new Incident();
                        $incident->source      = config("{$this->configBase}.parser.name");
                        $incident->source_id   = false;
                        $incident->ip          = $ip;
                        $incident->domain      = $report['domain'];
                        $incident->class       = config("{$this->configBase}.feeds.{$this->feedName}.class");
                        $incident->type        = config("{$this->configBase}.feeds.{$this->feedName}.type");
                        $incident->timestamp   = $timestamp;
                        $incident->information = json_encode(array_merge($urlData, $report));

                        $this->incidents[] = $incident;
                    }
                }
            }
        }

        return $this->success();
    }
851527
public function to_xml() {
        $this->validate();
        foreach ($this->entries as $entry) {
            $entry->id = 'portfolio:' . $entry->id;
            $this->feed->appendChild($entry->to_dom($this->dom, $this->user));
        }
        return $this->dom->saveXML();
    }
1169559
public function toXml()
    {
        $xml = new \SimpleXMLElement(
                '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><parser></parser>');
        
        $xml->addChild('fqdn', $this->fqdn);
        $xml->addChild('idn_fqdn', $this->idnFqdn);
        $xml->addChild('domain', $this->domain);
        $xml->addChild('idnDomain', $this->idnDomain);
        $xml->addChild('tld', $this->tld);
        $xml->addChild('idnTld', $this->idnTld);
        $xml->addChild('tldGroup', $this->tldGroup);
        $xml->addChild('validHostname', $this->validHostname);
        
        return $xml->asXML();
    }