You are here

public function wsdata_simple_xml_processor::parse in Web Service Data 7

Overrides WsData::parse

File

./wsdata_simple_xml.wsdata.processor.inc, line 6

Class

wsdata_simple_xml_processor

Code

public function parse($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 array(
        $data
          ->getName() => $data
          ->__toString(),
      );
    }
    $data = get_object_vars($data);
    foreach ($data as $key => $value) {
      $data[$key] = $this
        ->_parsexml($value);
    }
  } catch (exception $e) {
    return FALSE;
  }
  libxml_use_internal_errors(FALSE);
  return $data;
}