PHP DomDocument生成的XML在xml头初始化之前留下一个尾随空格

I am creating an XML report which is generated by a PHP program. When someone sends a CURL request to a URL, the XML gets saved on a file and printed. When a user sends a CURL request, the generated XML file has got a trailing white space before

The one who requests data cannot strip this off as they use an importer and the program gets terminated automatically when it finds a white space.

The XML file that gets generated doesnt have a trailing white space but it is just the output that gives this white space.

<?php
    /* Template name: Webhits */
    header('Content-Type: application/xml');
    global $wpdb;
    $file_name = 'webhits.xml';
    $xmldoc = new DOMDocument('1.0', 'UTF-8');
    $xmldoc->preserveWhiteSpace = false;
    $xmldoc->formatOutput = true;
    $datefrom = $_POST['datefrom'];
    $dateto = $_POST['dateto'];

$xmldoc = new DOMDocument('1.0', 'UTF-8');
$xmldoc->preserveWhiteSpace = false;
$xmldoc->formatOutput = true;

Now this delivers the unformatted output however it still leaves a trailing white space for some reasons.