1

Code:

my $test = {
    'a' => {
        'disabled' => 'false',
        'options' => '%build_options',
        'mailStatus' => {}, 
        'dependencies' =>{                                                                
            'test' => {                                                                                                              
                    'platforms' => {},                                                                                                 
                    'name' => 'nightly-regressions',                                                                                    
                    'preRequisitePlatforms' => {},                                                                                                             
                    'dependType' => 'pass'
                    },
        },                                                               
        'Above' => 'false',
        'options' => {},
        'critical' => 'true',
    }
};
print XMLout($test, noattr=>1, KeepRoot=>1, RootName=>undef, NoEscape => 1);

When I run above code to convert hash to xml, one level of "test" was missing, the output xml I got was:

Output:

<a>
  <Above>false</Above>
  <critical>true</critical>
  <dependencies>
    <name>nightly-regressions</name>
    <dependType>pass</dependType>
    <platforms></platforms>
    <preRequisitePlatforms></preRequisitePlatforms>
  </dependencies>
  <disabled>false</disabled>
  <mailStatus></mailStatus>
  <options></options>
</a>

Can anyone help me find what is wrong with my code?

3
  • 3
    Any good reason for using XML::Simple? The documentation yells at you PLEASE DO NOT USE THIS MODULE IN NEW CODE... Commented May 25, 2021 at 9:45
  • Does this answer: stackoverflow.com/a/60404484/3710053 your question? Commented May 25, 2021 at 10:05
  • 1
    Don't use XML::Simple. Just don't! It's a huge waste of time and source of problems. Why won't people believe a module's documentation that admonishes using the module because it's so broken? Commented May 25, 2021 at 21:30

1 Answer 1

1

Try importing XML::Simple with the strict option:

use XML::Simple qw(:strict);

You will find that you're missing a value for the KeyAttr option:

print XMLout($test, noattr=>1, KeepRoot=>1, RootName=>undef, NoEscape=>1, KeyAttr=>[]);
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.