From aef580d6ad728afd945711ffa8264de25935803d Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 6 Dec 2007 13:33:35 -0500 Subject: [PATCH] Removing the XML class because we will now use SimpleXML for all our parsing needs * UnitTest/AllTests.php: do not include the XML tests anymore * UnitTest/XmlTest.php: Removed * Xml.php: Removed --- UnitTest/AllTests.php | 3 - UnitTest/XmlTest.php | 77 ------------- Xml.php | 252 ------------------------------------------ 3 files changed, 332 deletions(-) delete mode 100644 UnitTest/XmlTest.php delete mode 100644 Xml.php diff --git a/UnitTest/AllTests.php b/UnitTest/AllTests.php index f33cf73..3f25773 100644 --- a/UnitTest/AllTests.php +++ b/UnitTest/AllTests.php @@ -40,9 +40,6 @@ class AllTests require_once 'TemplateTest.php'; $suite->addTestSuite('TemplateTest'); - require_once 'XmlTest.php'; - $suite->addTestSuite('XmlTest'); - require_once 'DatabaseTests.php'; $suite->addTestSuite(DatabaseTests::suite()); diff --git a/UnitTest/XmlTest.php b/UnitTest/XmlTest.php deleted file mode 100644 index 3226a50..0000000 --- a/UnitTest/XmlTest.php +++ /dev/null @@ -1,77 +0,0 @@ - - elm1 Value - elm1 Value 2 - elm2 Value - '; - - $results = array('root' => - array( - 'elm1' => - array( - 0 => array('value' => 'elm1 Value'), - 1 => array('value' => 'elm1 Value 2') - ), - 'elm2' => array('value' => 'elm2 Value') - ) - ); - $this->assertEquals($results, BSXml::Parse($xml)); - } - - public function testInvalidXml() - { - $xml = 'soemValue'; - - try - { - BSXml::Parse($xml); - $this->fail('exception expcted'); - } - catch (Exception $e) - {} - } - - public function testUnifyNode() - { - $xml = ' - - elm1 Value - elm1 Value 2 - elm2 Value - '; - - $array = BSXml::Parse($xml); - BSXml::UnifyNode($array['root']['elm2']); - $this->assertEquals($array['root']['elm2'][0]['value'], 'elm2 Value'); - } - - public function testUtf8Xml() - { - $xml = 'test: π'; - $array = BSXml::Parse($xml, true); - $this->assertEquals($array['root']['utf8']['value'], 'test: π'); - } -} - -?> \ No newline at end of file diff --git a/Xml.php b/Xml.php deleted file mode 100644 index 5fbb590..0000000 --- a/Xml.php +++ /dev/null @@ -1,252 +0,0 @@ - function) - * @var array() - */ - private $taghandler = array(); - - /** - * Current CDATA value - * @var string - */ - private $cdata = ''; - - /** - * Tag stack of all open nodes - * @var array - */ - private $stack = array(); - - /** - * Node list for all open tag attributes - * @var array - */ - private $attribs = array(); - - /** - * Resulting parsed array - * @var array - */ - private $result = array(); - - // ################################################################### - /** - * Constructor - */ - private function __construct() {} - - // ################################################################### - /** - * Parse an XML file - * - * @param string XML file data - * @param bool Parse file as UTF-8 instead of ISSO-8859-1? - * - * @return array Array with all the XML data parsed - */ - public static function Parse($data, $utf8 = false) - { - $parser = new BSXml(); - - if ($utf8) - { - $parser->parser = xml_parser_create('UTF-8'); - } - else - { - $parser->parser = xml_parser_create('ISO-8859-1'); - } - - // create a new parser - xml_set_object($parser->parser, $parser); - xml_parser_set_option($parser->parser, XML_OPTION_CASE_FOLDING, 0); - xml_set_element_handler($parser->parser, '_handleStartTag', '_handleEndTag'); - xml_set_character_data_handler($parser->parser, '_handleCData'); - - $parser->_attachNode($parser->result); - - // parse the data and check for errors - if (!xml_parse($parser->parser, $data)) - { - $error['code'] = xml_get_error_code($parser->parser); - $error['string'] = xml_error_string($error['code']); - $error['line'] = xml_get_current_line_number($parser->parser); - $error['column'] = xml_get_current_column_number($parser->parser); - throw new Exception("XML Error: $error[string] at line $error[line] colunn $error[column]"); - } - - // destroy the parser - xml_parser_free($parser->parser); - - // done... send the results back - return $parser->result; - } - - // ################################################################### - /** - * Process the opening location of an XML tag - * - * @param integer XML parser - * @param string Tag name - * @param array Tag attributes - */ - private function _handleStartTag(&$parser, $name, $attrs) - { - // we need to keep track of indicies to monitor the last key in $this->attribs - static $index; - - // trim attributes - array_walk($attrs, 'trim'); - - // existing node set - if (isset($this->attribs["$name"])) - { - // node set has < 1 child nodes - if (!isset($this->attribs["$name"][0])) - { - $tmp = $this->attribs["$name"]; - unset($this->attribs["$name"]); - $this->attribs["$name"][0] = $tmp; - } - - // create a new child node - $this->attribs["$name"][ $index["$name"] ] = (array)$attrs; - $this->_attachNode($this->attribs["$name"][ $index["$name"] ]); - $index["$name"]++; - } - // node set doesn't exist, so create it - else - { - $this->attribs["$name"] = (array)$attrs; - $this->_attachNode($this->attribs["$name"]); - $index["$name"] = 1; - } - } - - // ################################################################### - /** - * Process XML CDATA - * - * @param integer XML parser - * @param string CDATA from tag - */ - private function _handleCData(&$parser, $data) - { - $this->cdata .= $data; - } - - // ################################################################### - /** - * Process the closing of an XML tag - * - * @param integer XML parser - * @param string Tag name - */ - private function _handleEndTag(&$parser, $name) - { - // attach data to the node - if (($this->cdata = trim($this->cdata)) != '') - { - $this->attribs['value'] = $this->cdata; - } - - $this->cdata = ''; - - // remove the node - $this->_detachNode(); - } - - // ################################################################### - /** - * Shifts the node tree - * - * @param array Node to place into the stack - */ - private function _attachNode(&$node) - { - // create a new node - $this->stack[ sizeof($this->stack) ] =& $node; - - // new attributes to work with - $this->attribs =& $node; - } - - // ################################################################### - /** - * Unshifts the node tree - */ - private function _detachNode() - { - // drop the newest node - unset($this->stack[ sizeof($this->stack) - 1 ]); - - // assign the attributes to the next newest node - $this->attribs =& $this->stack[ sizeof($this->stack) - 1 ]; - } - - // ################################################################### - /** - * Unless a node has multiple children, there will not be a numerical - * index for the child node. So this means that if you have variable - * XML structure with some of the same types of nodes having one children - * or multiple children, you'd have different things to parse. If - * you want the node unified (as in, all single-children would be indexed - * numerically, run this function on the node. It works on references. - * - * @param array The node to int-index - */ - public static function UnifyNode(&$node) - { - if (!isset($node[0])) - { - $node = array($node); - } - } -} - -?> \ No newline at end of file -- 2.22.5