Search code examples
perlxml-simple

Getting at XML tree data in perl


I need to parse an XML file using perl which I can load the file using the XML::Simple module but within the XML tree there is a tag that I can't see using the DataDumper module but I can see it's value instead.

    <testcase id="10">
        .
        .
        .
    </testcase>

Above is a Sample of the XML file with the testcase tag. It's the part that I have difficulty with. Using DataDumper to view the contents of the array I see something like this:

$VAR1 = {
          'testcases' => {
                         'file' => 'testcases.xml',
                         'testcase' => {
                                       '10' => {
                                                },

Since the XML is defined like why isn't it layed out in the VAR1 array with the id included? Instead of expecting testcases->testcase->id I get testcases->testcase->10. Which 10 is the id but what happened to the 'id' tag?


Solution

  • That's because the default config includes

    KeyAttr => [qw( name key id )]
    

    Specifying

    KeyAttr => []
    

    will cause id to be no different than any other attribute.