diff options
author | Christian Schneider | 2007-02-09 13:44:31 +0000 |
---|---|---|
committer | Christian Schneider | 2007-02-09 13:44:31 +0000 |
commit | 05deab1128a4c7168f377e3f9a9e51a38f38d0e9 (patch) | |
tree | 1ea06d42a005d46d32284fc3bf7a01749e6b3a8d | |
parent | bbc8b31566fcae832081f1d890dfa6fd5c5c842a (diff) | |
download | itools-05deab1128a4c7168f377e3f9a9e51a38f38d0e9.tar.gz itools-05deab1128a4c7168f377e3f9a9e51a38f38d0e9.tar.bz2 itools-05deab1128a4c7168f377e3f9a9e51a38f38d0e9.zip |
Allow xml tags with special characters like date.taken (Flikr)
-rwxr-xr-x | tests/xml.t | 16 | ||||
-rw-r--r-- | xml.class | 15 |
2 files changed, 21 insertions, 10 deletions
diff --git a/tests/xml.t b/tests/xml.t index 85f16c8..d127fd8 100755 --- a/tests/xml.t +++ b/tests/xml.t @@ -26,11 +26,11 @@ match( 'empty tag' ); -#match( -# '<foo /><foo />', -# 'array ( 0 => class foo { }, 1 => class foo { }, )', -# 'multiple empty tags converted to array' -#); +match( + '<foo /><foo />', + 'array ( 0 => class foo { }, 1 => class foo { }, )', + 'multiple empty tags converted to array' +); match( '<foo title="Zürich">Stüssihofstadt</foo>', @@ -38,6 +38,12 @@ match( 'simple tag with latin1 content and attribute' ); +match( + '<foo><ns:a.b.-c ns2:d.e-f="value" /></foo>', + 'class foo { var $a_b__c = class a_b__c { var $attr = array( \'d_e_f\' => \'value\' ); }; }', + 'Tags and attributes with name space and special characters' +); + # Test inheritance class my_xml extends it_xml { @@ -119,10 +119,15 @@ function flatten($with_attr = false) return $result; } +# Strip namespace and convert extra characters to _ +function _make_identifier($name) +{ + return preg_replace(array('/^.*:/', '/\W/'), array('', '_'), $name); +} + function start_element($parser, $name, $attrs) { - $name = strtr($name, "-", "_"); - $name = preg_replace('/^.*:/', '', $name); + $name = it_xml::_make_identifier($name); $name = $this->_p['prefix'] . $name; if (!class_exists($name)) @@ -139,14 +144,14 @@ function start_element($parser, $name, $attrs) if ($attrs) { foreach ($attrs as $key => $val) - $this->_stack[0]->attr[preg_replace('/^.*:/', '', $key)] = $val; + $this->_stack[0]->attr[it_xml::_make_identifier($key)] = $val; } } function end_element($parser, $name) { - $name = preg_replace('/^.*:/', '', $name); - $name = strtr($name, "-", "_"); + $name = it_xml::_make_identifier($name); + if (!$this->_stack[0]->consume($this->_p)) { if (is_array($this->_stack[1]->$name)) |