Essence\Utility\Xml::parse PHP Method

parse() public static method

Parses an XML document and returns an array of data.
public static parse ( string $xml ) : array
$xml string XML document.
return array Data.
    public static function parse($xml)
    {
        $internal = libxml_use_internal_errors(true);
        $Iterator = new SimpleXmlIterator($xml);
        $data = [];
        foreach ($Iterator as $key => $value) {
            $data[$key] = strval($value);
        }
        libxml_use_internal_errors($internal);
        return $data;
    }

Usage Example

Example #1
0
 /**
  *	Parses the given response depending on its format.
  *
  *	@param string $response Response.
  *	@param string $format Format.
  *	@return array Data.
  */
 protected function _parse($response, $format)
 {
     switch ($format) {
         case Format::json:
             return Json::parse($response);
         case Format::xml:
             return Xml::parse($response);
         default:
             throw new Exception('Unsupported response format.');
     }
 }
All Usage Examples Of Essence\Utility\Xml::parse