Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.21.0

Request #21173 XML unserializing with namespaced class names using tagmap
Submitted: 2017-01-30 05:06 UTC
From: archana_m Assigned:
Status: Open Package: XML_Serializer (version SVN)
PHP Version: 5.5.24 OS: Windows 7
Roadmaps: (Not assigned)    
Subscription  


 [2017-01-30 05:06 UTC] archana_m (Archana Mulye)
Description: ------------ I am trying to deserialize xml into object using namespaced classes. mentioning structure which is expected as below. Please help me with it if there is any possible solution or any option changes required in unserializing options. My current defined options are as follows: public $options_unserialize = array ( // Defines whether nested tags should be returned as associative arrays or objects. XML_UNSERIALIZER_OPTION_COMPLEXTYPE => 'object', // use the tagname as the classname XML_UNSERIALIZER_OPTION_TAG_AS_CLASSNAME => true, // specify the target encoding XML_UNSERIALIZER_OPTION_ENCODING_TARGET => "UTF-8", // unserialize() returns the result of the unserialization instead of true XML_UNSERIALIZER_OPTION_RETURN_RESULT => true, // remove whitespace around data XML_UNSERIALIZER_OPTION_WHITESPACE => XML_UNSERIALIZER_WHITESPACE_TRIM, XML_UNSERIALIZER_OPTION_ATTRIBUTES_PARSE => true ); Test script: --------------- $tagMapArray = array("Foo" => "MyNameSpace\Classes\Foo", "Bar"=>"MyNameSpace\Classes\Bar"); $this->options_unserialize['tagMap'] = $tagMapArray; $unserializer = new XML_Unserializer($this->options_unserialize); $result_unserialize = $unserializer->unserialize($xmlResponse,false); Expected result: ---------------- [Foo] => MyNameSpace\Classes\Foo Object ( [Bar] => MyNameSpace\Classes\Bar Object ( [Name] => "ABC" ) ) Actual result: -------------- [Foo]=> [MyNameSpace\Classes\Foo] => MyNameSpace\Classes\Foo Object ( [Bar] => [MyNameSpace\Classes\Bar] => MyNameSpace\Classes\Bar Object ( [Name] => "ABC" ) ) )

Comments

 [2017-01-30 05:42 UTC] archana_m (Archana Mulye)
For Example, $xmlResponse = '<Foo> <Bar> <Name>ABC</Name> </Bar> </Foo>';