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> <html>
<body> <body>
<h1>World Data Overview ...</h1> <h1>World Data Overview ...</h1>
<table border=1> <table>
<tr> <tr>
<th>id</th> <th>id</th>
<th>name</th> <th>name</th>

View file

@ -55,16 +55,23 @@ class WorldDataParser {
return file_exists($file); 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) { function printXML($xml_file, $xslt_sheet) {
$xsl_doc = new DOMDocument(); $xsl_doc = new DOMDocument();
$xsl_res = $xsl_doc->loadXML($xslt_sheet); if ($xsl_doc->loadXML($this->read_file($xslt_sheet)) === false) {
if ($xsl_res === false) { echo "reading xsl sheet failed";
echo "reading xsl sheet failed: {$xsl_res}";
return; return;
} }
$xml_doc = new DOMDocument(); $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"; echo "reading world data xml failed";
return; return;
} }