2

I'm trying to convert a hash to a XML-string with this module XML::Hash::LX but I get only the first hash-key. Can someone tell me, how to get the whole hash?

#!/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>

1 Answer 1

5

You lack a root element.

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.