Fatal error: Class 'Drupal\module_name\DOMDocument' not found Fatal error: Class 'Drupal\module_name\DOMDocument' not found in
  /var/www/drupal/modules/module_name/src/form_xml.php on line 359


Any idea why Drupal cannot find DOMDocument class? 

I want to execute a code when a form is submitted

  public function submitForm(array &amp;$form, FormStateInterface $form_state) {
    // Find out what was submitted.
    $form_field = $form_state-&gt;getValue('content_types');

    foreach ($form_field as $key =&gt; $value){    
      if (!empty($value)){  
        $return = File::generate(); 
      }
    }
  }


In case you are wondering, module_name is the name of my custom module.

File::generate() is a static method which contains the DOMDocument class

The code works fine when I use devel to execute it, so any idea why can't it find the DOMDocument class on form submit? 

Seems to me as if the form blocks access to the DOMDocument class.
You need to rename the form class file CamelCase and make a namespace declaration at the top. The namespace will be Drupal\module_name\Form. Place the form class file in directory module_name/src/Form/.