@@ -114,10 +114,10 @@ public function decode($data, $format, array $context = array())
114114 unset($ data ['@xmlns:xml ' ]);
115115
116116 if (empty ($ data )) {
117- return $ this ->parseXml ($ rootNode );
117+ return $ this ->parseXml ($ rootNode, $ context );
118118 }
119119
120- return array_merge ($ data , (array ) $ this ->parseXml ($ rootNode ));
120+ return array_merge ($ data , (array ) $ this ->parseXml ($ rootNode, $ context ));
121121 }
122122
123123 if (!$ rootNode ->hasAttributes ()) {
@@ -256,11 +256,11 @@ final protected function isElementNameValid($name)
256256 *
257257 * @return array|string
258258 */
259- private function parseXml (\DOMNode $ node )
259+ private function parseXml (\DOMNode $ node, array $ context = array () )
260260 {
261- $ data = $ this ->parseXmlAttributes ($ node );
261+ $ data = $ this ->parseXmlAttributes ($ node, $ context );
262262
263- $ value = $ this ->parseXmlValue ($ node );
263+ $ value = $ this ->parseXmlValue ($ node, $ context );
264264
265265 if (!count ($ data )) {
266266 return $ value ;
@@ -292,16 +292,17 @@ private function parseXml(\DOMNode $node)
292292 *
293293 * @return array
294294 */
295- private function parseXmlAttributes (\DOMNode $ node )
295+ private function parseXmlAttributes (\DOMNode $ node, array $ context = array () )
296296 {
297297 if (!$ node ->hasAttributes ()) {
298298 return array ();
299299 }
300300
301301 $ data = array ();
302+ $ typeCastAttributes = $ this ->resolveXmlTypeCastAttributes ($ context );
302303
303304 foreach ($ node ->attributes as $ attr ) {
304- if (!is_numeric ($ attr ->nodeValue )) {
305+ if (!is_numeric ($ attr ->nodeValue ) || ! $ typeCastAttributes ) {
305306 $ data ['@ ' .$ attr ->nodeName ] = $ attr ->nodeValue ;
306307
307308 continue ;
@@ -326,7 +327,7 @@ private function parseXmlAttributes(\DOMNode $node)
326327 *
327328 * @return array|string
328329 */
329- private function parseXmlValue (\DOMNode $ node )
330+ private function parseXmlValue (\DOMNode $ node, array $ context = array () )
330331 {
331332 if (!$ node ->hasChildNodes ()) {
332333 return $ node ->nodeValue ;
@@ -343,7 +344,7 @@ private function parseXmlValue(\DOMNode $node)
343344 continue ;
344345 }
345346
346- $ val = $ this ->parseXml ($ subnode );
347+ $ val = $ this ->parseXml ($ subnode, $ context );
347348
348349 if ('item ' === $ subnode ->nodeName && isset ($ val ['@key ' ])) {
349350 if (isset ($ val ['# ' ])) {
@@ -522,6 +523,20 @@ private function resolveXmlRootName(array $context = array())
522523 : $ this ->rootNodeName ;
523524 }
524525
526+ /**
527+ * Get XML option for type casting attributes Defaults to true.
528+ *
529+ * @param array $context
530+ *
531+ * @return bool
532+ */
533+ private function resolveXmlTypeCastAttributes (array $ context = array ())
534+ {
535+ return isset ($ context ['xml_type_cast_attributes ' ])
536+ ? (bool ) $ context ['xml_type_cast_attributes ' ]
537+ : true ;
538+ }
539+
525540 /**
526541 * Create a DOM document, taking serializer options into account.
527542 *
0 commit comments