Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: XML to Hash Truncating Keys Problem

by Lotus1 (Vicar)
on Mar 28, 2019 at 16:13 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1231817]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-03-29 09:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found