summaryrefslogtreecommitdiff
path: root/it_xml.class
diff options
context:
space:
mode:
authorChristian Helbling2012-04-04 09:25:06 +0000
committerChristian Helbling2012-04-04 09:25:06 +0000
commita0231e4df6f8bfa82451c05998bb349ece764610 (patch)
tree6c1d9e76e8a6388fdf7f1d2435f0da082bd7de62 /it_xml.class
parent1336ce6ac3baacd1cecbf776cfafa81f8d025272 (diff)
parent14f1c25b43628013507da706544d5c55cb1bc461 (diff)
downloaditools-a0231e4df6f8bfa82451c05998bb349ece764610.tar.gz
itools-a0231e4df6f8bfa82451c05998bb349ece764610.tar.bz2
itools-a0231e4df6f8bfa82451c05998bb349ece764610.zip
Merged devel-utf8 back into live
Diffstat (limited to 'it_xml.class')
-rw-r--r--it_xml.class11
1 files changed, 5 insertions, 6 deletions
diff --git a/it_xml.class b/it_xml.class
index 0679c69..f854682 100644
--- a/it_xml.class
+++ b/it_xml.class
@@ -29,7 +29,7 @@ class it_xml
* @param $p associative array
* @param $p['forcearray'] xml tags to ALWAYS return as array
* @param $p['safety'] 2 causes program abort with invalid xml, 1 (default) causes error report, 0 just returns false
- * @param $p['encoding'] Output character encoding (e.g. UTF-8, default: ISO-8859-1)
+ * @param $p['encoding'] Output character encoding (utf-8, iso-8859-1 or us-ascii, default: ini_get('default_charset')
* @param $p['prefix'] Optional prefix for class names
* @param $p['lowercase'] Lowercase all tag and attribute names
* @return XML object tree or null on failure
@@ -49,23 +49,22 @@ function it_xml($xmldata = "", $p = array())
function create($xmldata, $p = array())
{
$xml = new it_xml;
-
return $xml->from_xml($xmldata, array('factory' => true) + $p) ? $xml->_root : null;
}
function from_xml($xmldata, $p)
{
- $this->_p = $p + array('encoding' => "ISO-8859-1", 'safety' => 1);
+ $this->_p = $p + array('encoding' => ini_get('default_charset'), 'safety' => 1);
$this->_arrayforce = array_flip((array)$this->_p['forcearray']);
$this->_stack = array();
unset($this->error);
- $parser = xml_parser_create($this->_p['encoding']);
+ $parser = xml_parser_create();
xml_set_object($parser, $this);
xml_set_element_handler($parser, "start_element", "end_element");
xml_set_character_data_handler($parser, "character_data");
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, $this->_p['encoding']);
-
+
$result = true;
if (is_resource($xmldata))
@@ -123,7 +122,7 @@ function _sanitize($xmldata, $isutf8 = null)
if (!preg_match('/^(<\?xml|\xEF\xBB\xBF|\xFE\xFF|\xFF\xFE|\x00\x00\xFE\xFF|\x00\x00\xFF\xFE)/', $xmldata))
$xmldata = '<?xml version="1.0" encoding="' . $this->_p['encoding'] . '"?>' . $xmldata;
- $isutf8 = (!preg_match('/^<\?xml[^>]* encoding=/i', $xmldata) || preg_match('/^<\?xml[^>]* encoding=.UTF-8/i', $xmldata));
+ $isutf8 = (!preg_match('/^<\?xml[^>]* encoding=/i', $xmldata) || preg_match('/^<\?xml[^>]* encoding=.utf-8/i', $xmldata));
}
# Decode illegal entities but protect semantically important ones