title: Perl XML::Simple Print to Excel File
body: <p>Question:
  I want to print the xml data to the excel file, but fail to print to the excel file.</p>
  
  <p>xml file: 
  data.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;ns1:BoardTestXMLExport numberOfIndictedComponents="11" testerTestStartTime=".00000:00" testTime=".00000:00" repairStationId="vvts03" testStatus="Reviewed Passed" testerTestEndTime=".00000:00" xmlns:ns1="http://tempuri.org/BoardTestXMLExport.xsd" numberOfIndictedPins="0" numberOfComponentsTested="113" numberOfJointsTested="0" numberOfDefects="11" repairStatus="Reviewed Passed"&gt;
            &lt;ns1:BoardXML imageId="0" serialNumber="R174842442 1P00232G01 R02 1C31228G01 R07 JH1711327" assemblyRevision="1P00232G01-LF-SS" boardType="1P00232G01-LF-SS" boardRevision="1511417735000"/&gt;
            &lt;ns1:StationXML testerName="huaemsaoi004" stage="V510"/&gt;
            &lt;ns1:RepairEventXML numberOfVariationOkDefects="0" numberOfFalseCalledPins="0" numberOfRepairedComponents="0" numberOfVariationOkPins="0" numberOfRepairedPins="0" numberOfRepairLaterPins="0" numberOfFalseCalledDefects="11" numberOfActiveDefects="0" numberOfVariationOkComponents="0" repairEndTime="2017-11-23T14:31:05.000+08:00" repairStartTime="2017-11-23T14:30:58.000+08:00" numberOfRepairLaterDefects="0" repairOperator="1066689" numberOfRepairLaterComponents="0" numberOfActiveComponents="0" numberOfActivePins="0" numberOfRepairedDefects="0" numberOfFalseCalledComponents="11"/&gt;
            &lt;ns1:TestXML name="r1"&gt;
                      &lt;ns1:IndictmentXML algorithm="rep-3a99979127l-lf" indictmentType="Left off, Right off"&gt;
                                &lt;ns1:RepairActionXML repairOperator="1066689" repairTime="2017-11-23T14:30:58.000+08:00" repairActionType="-" indictmentType="Left off, Right off" comment="-" repairStatus="False Call"/&gt;
                                &lt;ns1:ComponentXML packageId="EP-3A99979127L-LF" partId="EP-3A99979127L-LF" designator="r1"/&gt;
                      &lt;/ns1:IndictmentXML&gt;
            &lt;/ns1:TestXML&gt;
  &lt;/ns1:BoardTestXMLExport&gt;
  </code></pre>
  
  <p>my code as below:</p>
  
  <pre><code># use module
   use strict;
   use warnings;
   use XML::Simple;
   use Data::Dumper;
   use Excel::Writer::XLSX;
  
  # create object
   my $xml = XML::Simple-&gt;new;
  
  # create object
   my $xml = XML::Simple-&gt;new;
  
   #create excel object 
   my $OutFile = "Output". "\." . "xlsx";
   my $workbook  = Excel::Writer::XLSX-&gt;new($OutFile);
   my $worksheet = $workbook-&gt;add_worksheet('SotredProcedures');
  
   # Create a format for the column headings
   my $header = $workbook-&gt;add_format();
   $header-&gt;set_bold();
   $header-&gt;set_color('red');
  # Create a Text Wrap format
   my $format1 = $workbook-&gt;add_format();
   $format1-&gt;set_text_wrap();
   $worksheet-&gt;write(0, 0, "RepairStationID", $header);
   $worksheet-&gt;write(0, 1, "BoardType", $header);
   $worksheet-&gt;write(0, 2, "ComponentsTested", $header);
   $worksheet-&gt;write(0, 3, "NumberOfDefects", $header);
   $worksheet-&gt;set_column(0, 1, 12);
   $worksheet-&gt;set_column(1, 2, 20);
   $worksheet-&gt;set_column(1, 3, 20);
   $worksheet-&gt;set_column(1, 4, 20);
  # read XML file
   my $data = $xml-&gt;XMLin("data.xml",KeyAttr=&gt;"ns1");
  print  $data -&gt;{"ns1:BoardXML"}-&gt;{"boardType"}-&gt;{$worksheet};
  </code></pre>
  
  <p>Result: fail to print the boardtype to the excel file, output as below:</p>
  
  <p><a href="https://i.stack.imgur.com/YORdW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YORdW.png" alt="Error message"></a></p>
  
  <p>how can i do for it?</p>