/usr/share/phoronix-test-suite/pts-core/objects/nye_Xml/nye_XmlReader.php is in phoronix-test-suite 4.8.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | <?php
/*
Phoronix Test Suite
URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
Copyright (C) 2010 - 2011, Phoronix Media
Copyright (C) 2010 - 2011, Michael Larabel
nye_XmlReader.php: The XML reading object for the Phoronix Test Suite succeeding tandem_XmlReader
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
class nye_XmlReader
{
protected $tag_fallback = false; // Fallback value if tag is not present
protected $file_location = false;
public $dom; // The DOM
public function __construct($xml_file)
{
libxml_use_internal_errors(true);
$this->dom = new DOMDocument();
// TODO: investigate whether using the LIBXML_COMPACT option on loading actually increases performance
if(!isset($xml_file[1024]) && is_file($xml_file))
{
$this->dom->load($xml_file);
$this->file_location = $xml_file;
}
else if($xml_file != null)
{
$this->dom->loadXML($xml_file);
}
}
public function getFileLocation()
{
return $this->file_location;
}
public function getXMLValue($xml_tag, $fallback_value = -1)
{
$steps = explode('/', $xml_tag);
$narrow = $this->dom->getElementsByTagName(array_shift($steps));
foreach($steps as $step)
{
if($narrow->length == 0)
{
break;
}
$narrow = $narrow->item(0)->getElementsByTagName($step);
}
return $narrow->length == 1 ? $narrow->item(0)->nodeValue : $this->handleXmlZeroTagFallback($xml_tag, ($fallback_value === -1 ? $this->tag_fallback : $fallback_value));
}
public function getXMLArrayValues($xml_tag, $break_depth = -1)
{
$steps = explode('/', $xml_tag);
$narrow = $this->dom->getElementsByTagName(array_shift($steps));
$values = $this->processXMLArraySteps($steps, $narrow, 0, $break_depth);
return isset($values[0]) ? $values : $this->handleXmlZeroTagArrayFallback($xml_tag, $values, $break_depth);
}
protected function processXMLArraySteps($steps, $narrow, $steps_offset = 0, $break_depth = -1)
{
$values = array();
for($i = $steps_offset, $c = count($steps); $i < $c && $narrow->length > 0; $i++)
{
$narrow = $narrow->item(0)->getElementsByTagName($steps[$i]);
if($i == $break_depth)
{
for($x = 0; $x < $break_depth || $x == 0; $x++)
{
for($j = 0; $j < $narrow->length; $j++)
{
array_push($values, $this->processXMLArraySteps($steps, $narrow->item($j)->getElementsByTagName($steps[$i + 1]), $i + 2));
}
}
break;
}
else if($i == ($c - 2))
{
for($j = 0; $j < $narrow->length; $j++)
{
$extract = $narrow->item($j)->getElementsByTagName($steps[$i + 1]);
array_push($values, ($extract->length > 0 ? $extract->item(0)->nodeValue : null));
}
break;
}
}
return $values;
}
protected function handleXmlZeroTagFallback($xml_tag, $fallback_value)
{
return $fallback_value;
}
protected function handleXmlZeroTagArrayFallback($xml_tag, $fallback_value, $break_depth = -1)
{
return $fallback_value;
}
public function getXML()
{
return $this->dom->saveXML();
}
}
?>
|