Laravel / Lumen Error downloading XML File

Viewed 96

I am facing issue when trying to download xml file Through Response Facade. So here' what I am doing.

so when i created the xml file i saved it in storage as location.xml which looks like this

 <?xml version="1.0"?>
    <locations>
      <location>
        <name>Agent</name>
        <designation>Agent</designation>
        <date>2021-08-31</date>
        <time>05:18:42</time>
        <latitude>3.0647636</latitude>
        <longitude>101.66423359999999</longitude>
      </location>
      <location>
        <name>Agent</name>
        <designation>Agent</designation>
        <date>2021-08-31</date>
        <time>05:18:42</time>
        <latitude>3.0647636</latitude>
        <longitude>101.66423359999999</longitude>
      </location>
      <location>
        <name>Agent</name>
        <designation>Agent</designation>
        <date>2021-08-31</date>
        <time>05:18:42</time>
        <latitude>3.0647636</latitude>
        <longitude>101.66423359999999</longitude>
      </location>
      <location>
        <name>Agent</name>
        <designation>Agent</designation>
        <date>2021-08-31</date>
        <time>05:18:42</time>
        <latitude>3.0647636</latitude>
        <longitude>101.66423359999999</longitude>
      </location>
    </locations>

And the code to download the XML is like this

$file = base_path('storage/app/xml').'/locations.xml';
$headers = array(
    'Content-Type: text/xml'
);
return response()->download($file, 'LocationReport.xml', $headers);

And when the file downloads the file looks like following and i always get this error error on line 1 at column 8: XML declaration allowed only at the start of the document and my file looks like this

>    <?xml version="1.0"?>
>     <locations>
>       <location>
>         <name>Agent</name>
>         <designation>Agent</designation>
>         <date>2021-08-31</date>
>         <time>05:18:42</time>
>         <latitude>3.0647636</latitude>
>         <longitude>101.66423359999999</longitude>
>       </location>
>       <location>
>         <name>Agent</name>
>         <designation>Agent</designation>
>         <date>2021-08-31</date>
>         <time>05:18:42</time>
>         <latitude>3.0647636</latitude>
>         <longitude>101.66423359999999</longitude>
>       </location>
>       <location>
>         <name>Agent</name>
>         <designation>Agent</designation>
>         <date>2021-08-31</date>
>         <time>05:18:42</time>
>         <latitude>3.0647636</latitude>
>         <longitude>101.66423359999999</longitude>
>       </location>
>       <location>
>         <name>Agent</name>
>         <designation>Agent</designation>
>         <date>2021-08-31</date>
>         <time>05:18:42</time>
>         <latitude>3.0647636</latitude>
>         <longitude>101.66423359999999</longitude>
>       </location>
>     </locations

i dont understand why is closing tag missing the element whenever i download the xml file and if i fix i still get the same error till i remove the first xml tag please guys can someone help me here i am baffled here.

0 Answers
Related