I have a bunch of XML files in the storage/xml
directory.
I want to get all the files from that directory and then parse each one. I am trying to use simple_xml to do this but I am getting various errors as seen below.
Attempt #1:
$files = Storage::files('xml'); //get all files in the dir
foreach($files as $file){
$xml = simplexml_load_file($file);
}
This gets us:
simplexml_load_file(): I/O warning : failed to load external entity "xml/srml-21-2010-f339048-matchresults.xml"
However, the file xml/srml-21-2010-f339048-matchresults.xml
does exist and is a valid XML file. I have parsed it successfully with plain PHP on a different server.
Attempt #2:
$files = Storage::files('xml'); //get all files in the dir
foreach($files as $file){
$file_contents = Storage::get($file);
$xml = simplexml_load_string($file_contents) or die("Error: Cannot create object");
logger()->debug($xml);
}
This doesn't throw any errors, but when I try to log the outcome, in the log file I find that logger()->debug($xml)
prints only 3 empty lines. Nothing more. However, if I try logger()->debug($file_contents) I get what looks like correct data:
[2019-04-24 14:50:31] local.DEBUG: <?xml version="1.0" encoding="UTF-8"?>
<!-- Copyright 2001-2019 Opta Sportsdata Ltd. All rights reserved. -->
<!-- PRODUCTION HEADER
produced on: valde-jobq-a01.nexus.opta.net
production time: 20190304T081850,751Z
production module: Opta::Feed::XML::Soccer::F7
-->
<SoccerFeed TimeStamp="20190304T081848+0000">
<SoccerDocument Type="Result" detail_id="1" uID="f339048">
<Competition uID="c21">
etc etc
I do not want to use a library like XmlParser (or any other library). I will have no problem with parsing the data, I just need help actually getting hold of it. What am I doing wrong?