wc_correios_safe_load_xml

Safe load XML.

Description

(SimpleXMLElement|bool) wc_correios_safe_load_xml( (string) $source, (int) $options = 0 ); 

Returns (SimpleXMLElement|bool)

Parameters (2)

0. $source (string)
The source.
1. $options — Optional. (int)
Reading options.

Usage

  1. if ( !function_exists( 'wc_correios_safe_load_xml' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce-correios/includes/wc-correios-functions.php'; 
  3.  
  4. // The source. 
  5. $source = ''; 
  6.  
  7. // Reading options. 
  8. $options = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wc_correios_safe_load_xml($source, $options); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-correios-functions.php  
  1. function wc_correios_safe_load_xml( $source, $options = 0 ) { 
  2. $old = null; 
  3.  
  4. if ( function_exists( 'libxml_disable_entity_loader' ) ) { 
  5. $old = libxml_disable_entity_loader( true ); 
  6.  
  7. $dom = new DOMDocument(); 
  8. $return = $dom->loadXML( trim( $source ), $options ); 
  9.  
  10. if ( ! is_null( $old ) ) { 
  11. libxml_disable_entity_loader( $old ); 
  12.  
  13. if ( ! $return ) { 
  14. return false; 
  15.  
  16. if ( isset( $dom->doctype ) ) { 
  17. throw new Exception( 'Unsafe DOCTYPE Detected while XML parsing' ); 
  18.  
  19. return false; 
  20.  
  21. return simplexml_import_dom( $dom );