Subversion Repositories Applications.gtt

Compare Revisions

Ignore whitespace Rev 186 → Rev 187

/trunk/bibliotheque/pear/PEAR/XMLParser.php
1,22 → 1,15
<?php
/**
* PEAR_FTP
* PEAR_XMLParser
*
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @author Stephan Schmidt (original XML_Unserializer code)
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: XMLParser.php,v 1.12 2006/03/27 04:39:03 cellog Exp $
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license New BSD License
* @link http://pear.php.net/package/PEAR
* @since File available since Release 1.4.0a1
*/
23,15 → 16,15
 
/**
* Parser for any xml file
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @author Stephan Schmidt (original XML_Unserializer code)
* @copyright 1997-2006 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: 1.5.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
* @category pear
* @package PEAR
* @author Greg Beaver <cellog@php.net>
* @author Stephan Schmidt (original XML_Unserializer code)
* @copyright 1997-2009 The Authors
* @license http://opensource.org/licenses/bsd-license New BSD License
* @version Release: 1.10.1
* @link http://pear.php.net/package/PEAR
* @since Class available since Release 1.4.0a1
*/
class PEAR_XMLParser
{
51,13 → 44,13
* stack for all data that is found
* @var array $_dataStack
*/
var $_dataStack = array();
var $_dataStack = array();
 
/**
* stack for all values that are generated
* @var array $_valStack
*/
var $_valStack = array();
var $_valStack = array();
 
/**
* current tag depth
66,6 → 59,12
var $_depth = 0;
 
/**
* The XML encoding to use
* @var string $encoding
*/
var $encoding = 'ISO-8859-1';
 
/**
* @return array
*/
function getData()
83,22 → 82,19
include_once 'PEAR.php';
return PEAR::raiseError("XML Extension not found", 1);
}
$this->_valStack = array();
$this->_dataStack = array();
$this->_dataStack = $this->_valStack = array();
$this->_depth = 0;
 
if (version_compare(phpversion(), '5.0.0', 'lt')) {
if (strpos($data, 'encoding="UTF-8"')) {
$data = utf8_decode($data);
}
$xp = xml_parser_create('ISO-8859-1');
} else {
if (strpos($data, 'encoding="UTF-8"')) {
$xp = xml_parser_create('UTF-8');
} else {
$xp = xml_parser_create('ISO-8859-1');
}
if (
strpos($data, 'encoding="UTF-8"')
|| strpos($data, 'encoding="utf-8"')
|| strpos($data, "encoding='UTF-8'")
|| strpos($data, "encoding='utf-8'")
) {
$this->encoding = 'UTF-8';
}
 
$xp = xml_parser_create($this->encoding);
xml_parser_set_option($xp, XML_OPTION_CASE_FOLDING, 0);
xml_set_object($xp, $this);
xml_set_element_handler($xp, 'startHandler', 'endHandler');
125,25 → 121,21
*/
function startHandler($parser, $element, $attribs)
{
$type = 'string';
 
$this->_depth++;
$this->_dataStack[$this->_depth] = null;
 
$val = array(
'name' => $element,
'value' => null,
'type' => $type,
'childrenKeys' => array(),
'aggregKeys' => array()
);
'name' => $element,
'value' => null,
'type' => 'string',
'childrenKeys' => array(),
'aggregKeys' => array()
);
 
if (count($attribs) > 0) {
$val['children'] = array();
$val['type'] = 'array';
 
$val['children']['attribs'] = $attribs;
 
}
 
array_push($this->_valStack, $val);
174,20 → 166,14
$data = $this->postProcess($this->_dataStack[$this->_depth], $element);
 
// adjust type of the value
switch(strtolower($value['type'])) {
 
/*
* unserialize an array
*/
switch (strtolower($value['type'])) {
// unserialize an array
case 'array':
if ($data !== '') {
$value['children']['_content'] = $data;
}
if (isset($value['children'])) {
$value['value'] = $value['children'];
} else {
$value['value'] = array();
}
 
$value['value'] = isset($value['children']) ? $value['children'] : array();
break;
 
/*
205,42 → 191,43
$value['value'] = $data;
break;
}
 
$parent = array_pop($this->_valStack);
if ($parent === null) {
$this->_unserializedData = &$value['value'];
$this->_root = &$value['name'];
return true;
} else {
// parent has to be an array
if (!isset($parent['children']) || !is_array($parent['children'])) {
$parent['children'] = array();
if ($parent['type'] != 'array') {
$parent['type'] = 'array';
}
}
 
// parent has to be an array
if (!isset($parent['children']) || !is_array($parent['children'])) {
$parent['children'] = array();
if ($parent['type'] != 'array') {
$parent['type'] = 'array';
}
}
 
if (!empty($value['name'])) {
// there already has been a tag with this name
if (in_array($value['name'], $parent['childrenKeys'])) {
// no aggregate has been created for this tag
if (!in_array($value['name'], $parent['aggregKeys'])) {
if (isset($parent['children'][$value['name']])) {
$parent['children'][$value['name']] = array($parent['children'][$value['name']]);
} else {
$parent['children'][$value['name']] = array();
}
array_push($parent['aggregKeys'], $value['name']);
if (!empty($value['name'])) {
// there already has been a tag with this name
if (in_array($value['name'], $parent['childrenKeys'])) {
// no aggregate has been created for this tag
if (!in_array($value['name'], $parent['aggregKeys'])) {
if (isset($parent['children'][$value['name']])) {
$parent['children'][$value['name']] = array($parent['children'][$value['name']]);
} else {
$parent['children'][$value['name']] = array();
}
array_push($parent['children'][$value['name']], $value['value']);
} else {
$parent['children'][$value['name']] = &$value['value'];
array_push($parent['childrenKeys'], $value['name']);
array_push($parent['aggregKeys'], $value['name']);
}
array_push($parent['children'][$value['name']], $value['value']);
} else {
array_push($parent['children'],$value['value']);
$parent['children'][$value['name']] = &$value['value'];
array_push($parent['childrenKeys'], $value['name']);
}
array_push($this->_valStack, $parent);
} else {
array_push($parent['children'],$value['value']);
}
array_push($this->_valStack, $parent);
 
$this->_depth--;
}
257,5 → 244,4
{
$this->_dataStack[$this->_depth] .= $cdata;
}
}
?>
}