Creating a WordPress addon for ContactForm7 submission (.XML file export)

The file is not created, because the function my_generate_xml exists, but is never called.

All that code looks correct. The only problem is that you have to call the function that generates the XML file…

add_action('wpcf7_before_send_mail', 'my_get_form_values');

function my_get_form_values($contact_form) {

    // get info about the form and current submission instance
    $formTitle = $contact_form->title();
    $submission = WPCF7_Submission::get_instance();
    // define which form you're looking for (if you have multiple) 
    // and if the submission is valid
    if ( $formTitle == "myFormName" && $submission ) {
        // get the actual data!
        $posted_data = $submission->get_posted_data();

        my_generate_xml( $posted_data );

        /* You don't need these two lines, so you can delete them
        $firstName = posted_data['firstname'];
        $lastName = posted_data['lastname'];
        */
    }
}