Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: XML to Hash Truncating Keys Problem

by Lotus1 (Vicar)
on Mar 28, 2019 at 16:13 UTC ( #1231817=note: print w/replies, xml ) Need Help??


in reply to XML to Hash Truncating Keys Problem

It worked for me after I removed the '%' character from my test xml. With that character included in a text node as shown below the parse function would hang. Perhaps you have some other special character that the XML::Mini::Document module can't handle.

use warnings; use strict; #use 5.24.1; use Data::Dumper qw(Dumper); use XML::Mini::Document; $Data::Dumper::Terse=1; my $xml_input; { local $/; $xml_input = <DATA>; } print "1********************************************\n"; print $xml_input; my $xml_object =XML::Mini::Document->new(); $xml_object->parse($xml_input); #goto END; my $hash_ref = $xml_object->toHash(); print "2********************************************\n"; print Dumper($hash_ref); my $dumped_hash=Dumper($hash_ref); my $evalled_hashdata=eval($dumped_hash); print "3********************************************\n"; print Dumper($evalled_hashdata); END: #exit; ## This will cause ->parse() to hang. ## <BitmapPath>%TEST_ROOT%\bitmaps\</BitmapPath> __DATA__ <?xml version="1.0" encoding="utf-8"?> <NetConfig> <UseServerTimer>false</UseServerTimer> <PhoneNumberRegex /> <InitializeStatistics_Logging>false</InitializeStatistics_Logging> <InitializeStatistics_Logging>false_test</InitializeStatistics_Loggi +ng> <InitializeStatistics_Logging>false test</InitializeStatistics_Loggi +ng> <InitializeStatistics_Logging>false test </InitializeStatistics_Logg +ing> <ViewerConfigs> <TileNamePatern>{0}\{1}\{2}.tile</TileNamePatern> <ViewerConfigWrap> <File>viewerConfigx.xml</File> <Name>FI_RT</Name> </ViewerConfigWrap> </ViewerConfigs> </NetConfig>

Here is the output:

1******************************************** <?xml version="1.0" encoding="utf-8"?> <NetConfig> <UseServerTimer>false</UseServerTimer> <PhoneNumberRegex /> <InitializeStatistics_Logging>false</InitializeStatistics_Logging> <InitializeStatistics_Logging>false_test</InitializeStatistics_Loggi +ng> <InitializeStatistics_Logging>false test</InitializeStatistics_Loggi +ng> <InitializeStatistics_Logging>false test </InitializeStatistics_Logg +ing> <ViewerConfigs> <TileNamePatern>{0}\{1}\{2}.tile</TileNamePatern> <ViewerConfigWrap> <File>viewerConfigx.xml</File> <Name>FI_RT</Name> </ViewerConfigWrap> </ViewerConfigs> </NetConfig> 2******************************************** { 'NetConfig' => { 'PhoneNumberRegex' => '', 'ViewerConfigs' => { 'ViewerConfigWrap' => { 'File' + => 'viewerConfigx.xml', 'Name' + => 'FI_RT' }, 'TileNamePatern' => '{0}\\{1}\ +\{2}.tile' }, 'InitializeStatistics_Logging' => [ 'false', 'false_test', 'false test', 'false test' ], 'UseServerTimer' => 'false' }, 'xml' => { 'version' => '1.0', 'encoding' => 'utf-8' } } 3******************************************** { 'NetConfig' => { 'PhoneNumberRegex' => '', 'UseServerTimer' => 'false', 'InitializeStatistics_Logging' => [ 'false', 'false_test', 'false test', 'false test' ], 'ViewerConfigs' => { 'TileNamePatern' => '{0}\\{1}\ +\{2}.tile', 'ViewerConfigWrap' => { 'File' + => 'viewerConfigx.xml', 'Name' + => 'FI_RT' } } }, 'xml' => { 'version' => '1.0', 'encoding' => 'utf-8' } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1231817]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2021-06-23 06:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (114 votes). Check out past polls.

    Notices?