我正在尝试使用此模块XML::Hash::LX将哈希转换为XML字符串,但我只获得第一个哈希键。有人能告诉我,如何获得整个哈希?
#!/usr/bin/env perl
use warnings;
use 5.012;
use XML::Hash::LX;
my $hash = { one => 1, two => 2, three => 3, four => 4 };
my $str = hash2xml( $hash );
print $str;
# Output:
# <?xml version="1.0" encoding="utf-8"?>
# <three>3</three>
答案 0 :(得分:5)
你缺少一个根元素。
hash2xml { numbers => { one => 1, two => 2, three => 3, four => 4 } }
<?xml version="1.0" encoding="utf-8"?>
<numbers><three>3</three><one>1</one><two>2</two><four>4</four></numbers>