Woocommerce order to a XML file saving each product

I am creating a plugin that creates a XML file with a structure for each order. But I am not able to get the product info in to the order. I dont really know what I am doing wrong.

My current code that saves the file and puts the data in it but not the product.

function export_order_to_xml($order_id) {
    $order = wc_get_order($order_id);
    $xml_data = generate_xml_data($order);

    $filename = generate_filename($order);
    $plugin_dir = plugin_dir_path(__FILE__);
    $xml_directory = $plugin_dir . 'xml_files/';
    if (!file_exists($xml_directory)) {
        mkdir($xml_directory, 0755, true);
    }
    $filepath = $xml_directory . $filename;
    file_put_contents($filepath, $xml_data);
}

function generate_xml_data($order) {
    $order_data = $order->get_data();
    // Generate XML structure
    $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><order></order>');
    $xml->addChild('ordernumber', $order_data['id']); // Order ID
    $xml->addChild('name', $order_data['billing']['first_name']);
    $xml->addChild('lastname', $order_data['billing']['last_name']);
    // Add order items
    $order_items_element = $xml->addChild('orderitems');
    foreach ($order->get_items() as $item_id => $item) {
        $product = $item->get_product();
        $item_element = $order_items_element->addChild('item');
        $item_element->addChild('product_id', $product->get_id());
        $item_element->addChild('name', $product->get_name());
        $item_element->addChild('price', $order->get_item_total($item, false));
        $item_element->addChild('qty', $item->get_quantity());
    }
    return $xml->asXML();
}

function generate_filename($order) {
    $order_data = $order->get_data();
    $order_number = $order_data['id'];
    $pickup_date = date('Ymd', strtotime($order_data['date_created']));
    $location = '1';
    $customer_id = $order->get_user_id();
    $filename = "{$pickup_date}{$order_number}_{$location}_{$customer_id}.xml";
    return $filename;
}

This should be the strucute:

<?xml version="1.0" encoding="UTF-8"?>
<order>
 <ordernumber></ordernumber>
 <lastname></lastname>
 <adress></adress>
 <zipcode></zipcode>
 <city></city>
 <phone></phone>
 <email></email>
 <date></date>
 <location>1</location>
 <customer_id/>
 <payd>nee</payd>
 <method>cash</method>
 <orderitems>
 <item>
 <product_id>252</product_id>
 <name>Item</name>
 <price>2.30</price>
 <qty>3</qty>
 </item>
 </orderitems>
</order>