You are here

public static function XmlHelper::normalizeDataToSimpleXml in Helper 7

2 calls to XmlHelper::normalizeDataToSimpleXml()
XmlHelper::convertToSimpleArray in lib/XmlHelper.php
XmlHelper::parseElements in lib/XmlHelper.php
Convert a string of XML to an associative array.

File

lib/XmlHelper.php, line 115

Class

XmlHelper

Code

public static function normalizeDataToSimpleXml($data, $class_name = NULL, $options = LIBXML_NOCDATA) {
  if (is_object($data) && is_a($data, 'SimpleXMLElement')) {
    return $data;
  }
  elseif (is_file($data) || valid_url($data, TRUE)) {
    $xml = simplexml_load_file($data, $class_name, $options);
    if ($xml === FALSE) {
      throw new Exception("Unable to parse XML from {$data}");
    }
    else {
      return $xml;
    }
  }
  else {
    $xml = simplexml_load_string((string) render($data), $class_name, $options);
    if ($xml === FALSE) {
      throw new Exception("Unable to parse XML");
    }
    else {
      return $xml;
    }
  }
}