/usr/share/phoronix-test-suite/pts-core/objects/nye_Xml/nye_XmlWriter.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 | <?php
/*
Phoronix Test Suite
URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/
Copyright (C) 2010 - 2013, Phoronix Media
Copyright (C) 2010 - 2013, Michael Larabel
nye_XmlWriter.php: The XML writing object for the Phoronix Test Suite succeeding tandem_XmlWriter
Additional Notes: A very simple XML writer with a few extras... Does not support attributes on tags, etc.
A work in progress. This was originally designed for just some select needs in the past. It does support linking to an XSL as
well as whether to format the XML or not, etc. Also provides a MD5 checksum of the XML body.
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_XmlWriter
{
protected $items;
public $dom;
public function __construct($xsl_binding = null, $nice_formatting = true)
{
$this->dom = new DOMDocument('1.0');
$this->dom->formatOutput = PTS_IS_CLIENT && $nice_formatting;
//$this->dom->preserveWhiteSpace = false;
$this->items = array();
if(PTS_IS_CLIENT && stripos(PTS_PHP_VERSION, 'hiphop') === false)
{
$pts_comment = $this->dom->createComment(pts_title(true));
$this->dom->appendChild($pts_comment);
}
if($xsl_binding != null)
{
$xslt = $this->dom->createProcessingInstruction('xml-stylesheet', 'type="text/xsl" href="' . $xsl_binding . '"');
$this->dom->appendChild($xslt);
}
}
public function addXmlNodeWNE($xml_location, $xml_value = null)
{
// When Not Empty, add the XML node
return empty($xml_value) ? false : $this->addXmlNode($xml_location, $xml_value);
}
public function addXmlNode($xml_location, $xml_value = null)
{
$nodes = explode('/', $xml_location);
$pointer = &$this->items;
for($i = 0, $node_count = count($nodes); $i < $node_count; $i++)
{
if(!isset($pointer[$nodes[$i]]) || ($i == ($node_count - 2) && isset($pointer[$nodes[$i]][$nodes[($i + 1)]])))
{
$pointer[$nodes[$i]] = array();
$pointer[$nodes[$i]][0] = $this->dom->createElement($nodes[$i]);
if($i == 0)
{
$this->dom->appendChild($pointer[$nodes[$i]][0]);
}
else
{
$pointer[0]->appendChild($pointer[$nodes[$i]][0]);
if($i == ($node_count - 1))
{
$t = $this->dom->createTextNode($xml_value);
$pointer[$nodes[$i]][0]->appendChild($t);
}
}
}
$pointer = &$pointer[$nodes[$i]];
}
}
public function addXmlNodeFromReader($xml_location, &$xml, $default_value = null)
{
$value = $xml->getXmlValue($xml_location);
$this->addXmlNode($xml_location, (empty($value) ? $default_value : $value));
}
public function addXmlNodeFromReaderWNE($xml_location, &$xml)
{
$value = $xml->getXmlValue($xml_location);
$this->addXmlNodeWNE($xml_location, $value);
}
public function saveXMLFile($to_file)
{
return $this->dom->save($to_file);
}
public function getXML()
{
return $this->dom->saveXML();
}
}
?>
|