Read files correctly

This commit is contained in:
hodasemi 2018-11-12 20:53:11 +01:00
parent b63520e9fb
commit 8d65583ab7
2 changed files with 12 additions and 5 deletions

View file

@ -4,7 +4,7 @@
<html>
<body>
<h1>World Data Overview ...</h1>
<table border=1>
<table>
<tr>
<th>id</th>
<th>name</th>

View file

@ -55,16 +55,23 @@ class WorldDataParser {
return file_exists($file);
}
function read_file($path) {
$fh = fopen($path, "rb");
$data = fread($fh, filesize($path));
fclose($fh);
return $data;
}
function printXML($xml_file, $xslt_sheet) {
$xsl_doc = new DOMDocument();
$xsl_res = $xsl_doc->loadXML($xslt_sheet);
if ($xsl_res === false) {
echo "reading xsl sheet failed: {$xsl_res}";
if ($xsl_doc->loadXML($this->read_file($xslt_sheet)) === false) {
echo "reading xsl sheet failed";
return;
}
$xml_doc = new DOMDocument();
if ($xml_doc->loadXML($xml_file) === false) {
if ($xml_doc->loadXML($this->read_file($xml_file)) === false) {
echo "reading world data xml failed";
return;
}