You are here

public function WSDecoderXML::decode in Web Service Data 8

Same name and namespace in other branches
  1. 2.0.x src/Plugin/WSDecoder/WSDecoderXML.php \Drupal\wsdata\Plugin\WSDecoder\WSDecoderXML::decode()

Decode the web service response string.

Overrides WSDecoderBase::decode

File

src/Plugin/WSDecoder/WSDecoderXML.php, line 22

Class

WSDecoderXML
XML Decoder.

Namespace

Drupal\wsdata\Plugin\WSDecoder

Code

public function decode($data) {
  if (!isset($data) || empty($data)) {
    return;
  }
  $data = trim($data);
  libxml_use_internal_errors(TRUE);
  try {
    $data = new \SimpleXMLElement($data);
    if ($data
      ->count() == 0) {
      return [
        $data
          ->getName() => $data
          ->__toString(),
      ];
    }
    $data = get_object_vars($data);
    foreach ($data as $key => $value) {
      $data[$key] = $this
        ->decodeXml($value);
    }
  } catch (exception $e) {
    return FALSE;
  }
  libxml_use_internal_errors(FALSE);
  return $data;
}