protected function queryXml($apiUrl, $apiServiceFilter = null)
    {
        $useCache = self::$useCache;

        if ($apiServiceFilter) {
            $url = $apiUrl . $apiServiceFilter->getURLQuery();
        } else {
            $url = $apiUrl;
        }

        // no cache, so query from server
        if (!$useCache || $this->cacheManager->has(md5($url)) == false) {
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HEADER, true);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            // additional headers
            $headers = [
          'User-Agent: ' . \RGU\Dvoconnector\Utility\EmConfiguration::getSettings()->getHttpUserAgent(),
      ];
            if (!$useCache) {
                $headers[] = 'Cache-Control: no-cache';
            }
            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

            $response = curl_exec($ch);

            // separate response into header and body
            list($header, $body) = explode("\r\n\r\n", $response, 2);

            // check for response-code 200
            $headers = explode("\r\n", $header);
            $responseCode = preg_replace('/HTTP\/.* ([0-9]+) .*/', '${1}', $headers[0]);
            if ($responseCode{0} != '2') {
                throw new \Exception('Unexpected HTTP response code: ' . $responseCode . '|' . $url);
            }

            // caching
            if (!preg_match('/.*Cache-Control: .*no-cache.*/sm', $header)) {
                // check for Cache-Control max-age param
                $maxAge = preg_replace('/.*Cache-Control: .*max-age=(\d+).*/sm', '${1}', $header);

                // cache response
                $this->writeCache(md5($url), $body, ($maxAge == '') ? \RGU\Dvoconnector\Utility\EmConfiguration::getSettings()->getCachetime() : (int)$maxAge);
            }
        } elseif ($useCache && $this->cacheManager->has(md5($url)) == true) {
            $body = $this->readCache(md5($url));
        }

        try {
            $xml = new \SimpleXMLElement($body);
        } catch (\Exception $e) {
            throw $e;
        }

        return $xml;
    }