cvs: pear /XML_Serializer Unserializer.php /XML_Serializer/examples unserializeWithTagMap.php
| From: | Stephan Schmidt | Date: | Mon, 11 Apr 2005 18:39:38 +0000 |
| Subject: | cvs: pear /XML_Serializer Unserializer.php /XML_Serializer/examples unserializeWithTagMap.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-31105@lists.php.net to get a copy of this message | ||
schst Mon Apr 11 14:39:38 2005 EDT
Added files:
/pear/XML_Serializer/examples unserializeWithTagMap.php
Modified files:
/pear/XML_Serializer Unserializer.php
Log:
allow tagMap option to influence any kind of value (fixes bug #4075)
http://cvs.php.net/diff.php/pear/XML_Serializer/Unserializer.php?r1=1.32&r2=1.33&ty=u
Index: pear/XML_Serializer/Unserializer.php
diff -u pear/XML_Serializer/Unserializer.php:1.32 pear/XML_Serializer/Unserializer.php:1.33
--- pear/XML_Serializer/Unserializer.php:1.32 Sat Mar 26 03:16:41 2005
+++ pear/XML_Serializer/Unserializer.php Mon Apr 11 14:39:36 2005
@@ -19,7 +19,7 @@
* @author Stephan Schmidt <schst@php.net>
* @copyright 1997-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: Unserializer.php,v 1.32 2005/03/26 08:16:41 schst Exp $
+ * @version CVS: $Id: Unserializer.php,v 1.33 2005/04/11 18:39:36 schst Exp $
* @link http://pear.php.net/package/XML_Serializer
* @see XML_Unserializer
*/
@@ -375,6 +375,10 @@
$this->_depth++;
$this->_dataStack[$this->_depth] = null;
+ if (is_array($this->options['tagMap']) &&
isset($this->options['tagMap'][$element])) {
+ $element = $this->options['tagMap'][$element];
+ }
+
$val = array(
'name' => $element,
'value' => null,
@@ -443,10 +447,6 @@
} else {
$classname = '';
}
- if (is_array($this->options['tagMap']) &&
isset($this->options['tagMap'][$classname])) {
- $classname = $this->options['tagMap'][$classname];
- }
-
// instantiate the class
if ($this->options['tagAsClass'] === true &&
class_exists($classname)) {
$value['value'] = &new $classname;
http://cvs.php.net/co.php/pear/XML_Serializer/examples/unserializeWithTagMap.php?r=1.1&p=1
Index: pear/XML_Serializer/examples/unserializeWithTagMap.php
+++ pear/XML_Serializer/examples/unserializeWithTagMap.php
<?PHP
/**
* This example shows how to use the tagMap option.
*
* @author Stephan Schmidt <schst@php.net>
*/
error_reporting(E_ALL);
// this is a simple XML document
$xml = '<root>' .
' <foo>FOO</foo>' .
' <bar>BAR</bar>' .
'</root>';
require_once 'XML/Unserializer.php';
// complex structures are arrays, the key is the attribute 'handle' or 'name',
if handle is not present
$options = array(
'complexType' => 'array',
'tagMap' => array(
'foo' => 'bar',
'bar' => 'foo'
)
);
// be careful to always use the ampersand in front of the new operator
$unserializer = &new XML_Unserializer($options);
// userialize the document
$status = $unserializer->unserialize($xml, false);
if (PEAR::isError($status)) {
echo 'Error: ' . $status->getMessage();
} else {
$data = $unserializer->getUnserializedData();
echo '<pre>';
print_r($data);
echo '</pre>';
}
// a tad more complex
$xml = '<root>' .
' <foo>'.
' <tomato>45</tomato>'.
' </foo>'.
' <bar>'.
' <tomato>31</tomato>'.
' </bar>'.
'</root>';
// userialize the document
$status = $unserializer->unserialize($xml, false);
if (PEAR::isError($status)) {
echo 'Error: ' . $status->getMessage();
} else {
$data = $unserializer->getUnserializedData();
echo '<pre>';
print_r($data);
echo '</pre>';
}
?>