Title: Empty XML files
Last modified: January 17, 2019

---

# Empty XML files

 *  Resolved [jochl](https://wordpress.org/support/users/jochl/)
 * (@jochl)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/empty-xml-files/)
 * Hi WP-ALL-IMPORT,
 * First of all, thank you for answering all these questions on this forum. It really
   helped out with a few other features I needed.
 * However I’m stuck myself now and could not find an answer. I have an export that
   creates an xml file with the latest orders (hourly) that need processing elsewhere.
   It works but it keeps creating xml files even when there are no orders to export.
   So it creates an empty xml file which is _unwanted_.
 * I started on a function myself but the syntax is probably not right.
    Hopefully
   you can correct it, I would be ever grateful.

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [jochl](https://wordpress.org/support/users/jochl/)
 * (@jochl)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/empty-xml-files/#post-11102350)
 *     ```
       	add_action( 'pmxe_before_export', 'wp_all_export_before_export', 10, 1 );
       	function wp_all_export_before_export( $export_id )
       	{
       		// Unless you want this to execute for every export you should check the id here:
       		if($export_id == 2){
       			$export = new PMXI_Export_Record(); 
       			$export->getById($export_id);	 
       			if ( !$export->isEmpty() && $export->count < 1 ) {
       				echo 'Import skipped because of empty file / < 100 records';  
       				// stop import processing 
       				die(); 			 
       			}	 
   
       		}
       	}
       ```
   
 *  Thread Starter [jochl](https://wordpress.org/support/users/jochl/)
 * (@jochl)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/empty-xml-files/#post-11102355)
 * Created something along these lines but it does not work – probably need to set
   the log aswell but I’m kind of stuck.
 *  Thread Starter [jochl](https://wordpress.org/support/users/jochl/)
 * (@jochl)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/empty-xml-files/#post-11107907)
 *     ```
       add_action( 'pmxe_before_export', 'wp_all_export_before_export', 10, 1 );
        function wp_all_export_before_export( $export_id )
           {
               if ($export_id == 2) {
                   $exportRecord = new PMXE_Export_Record();
                   $exportRecord->getById($export_id);
                   if ( $exportRecord->count == 0){
                       $exportRecord->set(array(
                           'triggered'   => 0,
                           'processing'  => 0,
                           'executing'   => 0,
                           'canceled'    => 1,
                           'canceled_on' => date('Y-m-d H:i:s')
                       ))->update();	
                       die();
                   } 
               }
           }
       ```
   
 * I feel like this should work – but it does not. Triggered via Cron.
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/empty-xml-files/#post-11110328)
 * Hey [@jochl](https://wordpress.org/support/users/jochl/)
 * I can see that we’ve answered your question in our ticket system. For anyone 
   else reading this, here’s an example snippet that shows how to delete an empty
   export file after the export completes: [https://gist.github.com/KittenCodes/dd4882c92f2c8b0421bd5849cad629ac](https://gist.github.com/KittenCodes/dd4882c92f2c8b0421bd5849cad629ac)

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Empty XML files’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-export/assets/icon-256x256.png?rev=2570162)
 * [WP All Export – Drag & Drop Export to Any Custom CSV, XML & Excel](https://wordpress.org/plugins/wp-all-export/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-export/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-export/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-export/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-export/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-export/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [7 years, 4 months ago](https://wordpress.org/support/topic/empty-xml-files/#post-11110328)
 * Status: resolved