src/Xml.php
public static function populateXml($data)
  {
    $isFile = ( is_file($data) );
    
    libxml_use_internal_errors(true);
    
    if ( $isFile === true ){
      $xml = simplexml_load_file($data, '\SimpleXMLElement');
    }
    else {
      $xml = simplexml_load_string($data, '\SimpleXMLElement');
    }
    
    if ( empty($xml) ){
      $errors=[];
      if ( $isFile === true ){
        $errors[] = $data;
      }
      
      foreach(libxml_get_errors() as $error){
        $errors[] = 'XML: '.$error->message;
      }
      
      throw new Exception('XML file could not be loaded : '."\n".implode("\n", $errors));
    }
    
    return $xml;
  }
public static function populateXml($data)
  {
    $isFile = ( is_file($data) );
    
    libxml_use_internal_errors(true);
    
    if ( $isFile === true ){
      $xml = simplexml_load_file($data, '\SimpleXMLElement');
    }
    else {
      $xml = simplexml_load_string($data, '\SimpleXMLElement');
    }
    
    if ( empty($xml) ){
      $errors=[];
      if ( $isFile === true ){
        $errors[] = $data;
      }
      
      foreach(libxml_get_errors() as $error){
        $errors[] = 'XML: '.$error->message;
      }
      
      throw new Exception('XML file could not be loaded : '."\n".implode("\n", $errors));
    }
    
    return $xml;
  }
public static function populateXml ( $ data ) { $ isFile = ( is_file ( $ data ) ) ; libxml_use_internal_errors ( true ) ; if ( $ isFile === true ) { $ xml = simplexml_load_file ( $ data , '\SimpleXMLElement' ) ; } else { $ xml = simplexml_load_string ( $ data , '\SimpleXMLElement' ) ; } if ( empty ( $ xml ) ) { $ errors = [ ] ; if ( $ isFile === true ) { $ errors [ ] = $ data ; } foreach ( libxml_get_errors ( ) as $ error ) { $ errors [ ] = 'XML: ' . $ error -> message ; } throw new Exception ( 'XML file could not be loaded : ' . "\n" . implode ( "\n" , $ errors ) ) ; } return $ xml ; }
Reads a XML file

@param  string  $data  XML path or XML string
@return SimpleXMLElement  Xml element
@throws Exception
@see    SimpleXMLElement
Reads a XML file