title: How to correct error: not well-formed (invalid token) at line 6
body: <p>I am trying to convert an xml file into html file using perl code but getting this error that xml is not well formed and having an invalid token.
  Code:</p>
  
  <pre><code>#!/usr/bin/perl
  
  use strict;
  use warnings;
  use XML::Parser;
  use XML::LibXML;
  
  my $parser = XML::Parser-&gt;new();
  $parser-&gt;setHandlers(   Start   =&gt; \&amp;start,
                          End     =&gt; \&amp;end,
                          Char    =&gt; \&amp;char,
                          Proc    =&gt; \&amp;proc,
                  );
  my $header = &amp;getXHTMLHeader();
  print $header;
  $parser-&gt;parsefile('output.xml');
  
  my $currentTag = "";
  
  sub start() {
          my ($parser, $name, %attr) = @_;
          $currentTag = lc($name);
          if ($currentTag eq 'doc') {
                  print "&lt;head&gt;&lt;title&gt;". "Output of snmpwalk for cpeIP4" . "&lt;/title&gt;&lt;/head&gt;";
                  print "&lt;body&gt;&lt;h2&gt;" . "Output of snmpwalk for cpeIP4" . "&lt;/h2&gt;";
                  print '&lt;table summary="' . "Output of snmpwalk for cpeIP4" . '"&gt;&lt;tr&gt;&lt;th&gt;Tag Name&lt;/th&gt;&lt;th&gt;0&lt;/th&gt;&lt;th&gt;1&lt;/th&gt;&lt;th&gt;2&lt;/th&gt;&lt;th&gt;3&lt;/th&gt;&lt;th&gt;4&lt;/th&gt;&lt;th&gt;5&lt;/th&gt;&lt;th&gt;6&lt;/th&gt;&lt;th&gt;7&lt;/th&gt;&lt;th&gt;8&lt;/th&gt;&lt;th&gt;9&lt;/th&gt;&lt;th&gt;10&lt;/th&gt;&lt;th&gt;11&lt;/th&gt;&lt;th&gt;12&lt;/th&gt;&lt;th&gt;13&lt;/th&gt;&lt;th&gt;14&lt;/th&gt;&lt;th&gt;15&lt;/th&gt;&lt;th&gt;16&lt;/th&gt;&lt;/tr&gt;';
          }
          elsif ($currentTag eq 'GI-eSTB-MIB-NPH') {
                  print "&lt;tr&gt;";
          }
          #elsif ($currentTag !~ /^(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16)$/)
          elsif ($currentTag ne '0' || $currentTag ne '1' || $currentTag ne '2' || $currentTag ne '3' || $currentTag ne '4' || $currentTag ne '5' || $currentTag ne '6' || $currentTag ne '7' || $currentTag ne '8' || $currentTag ne '9' || $currentTag ne '10' || $currentTag ne '11' || $currentTag ne '12' || $currentTag ne '13' || $currentTag ne '14' || $currentTag ne '15' || $currentTag ne '16' ) {
                  print "&lt;tr&gt;";
          }
          else {
                  print "&lt;td&gt;";
          }
  }
  sub end() {
          my ($parser, $name, %attr) = @_;
          $currentTag = lc($name);
          if ($currentTag eq 'doc') {
                  print "&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;";
          }
          elsif ($currentTag eq 'GI-eSTB-MIB-NPH') {
                  print "&lt;/tr&gt;";
          }
          #elsif ($currentTag !~ /^(0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15|16)$/)
          elsif ($currentTag ne '0' || $currentTag ne '1' || $currentTag ne '2' || $currentTag ne '3' || $currentTag ne '4' || $currentTag ne '5' || $currentTag ne '6' || $currentTag ne '7' || $currentTag ne '8' || $currentTag ne '9' || $currentTag ne '10' || $currentTag ne '11' || $currentTag ne '12' || $currentTag ne '13' || $currentTag ne '14' || $currentTag ne '15' || $currentTag ne '16' ) {
                  print "&lt;/tr&gt;";
          }
          else {
                  print "&lt;/td&gt;";
          }
  }
  sub char() {
          my ($parser, $data) = @_;
          print $data;
  }
  sub proc() {
          my ($parser, $target, $data) = @_;
          if (lc($target) eq 'perl') {
                  $data = eval($data);
                  print $data;
          }
  }
  sub getXHTMLHeader() {
          my $header = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;
          &lt;!DOCTYPE html
            PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
            &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;';
          return $header;
  }
  </code></pre>
  
  <p>The contents of output.xml are(for example, actual file contains lot more details in similar format):</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;doc&gt;
      &lt;GI-eSTB-MIB-NPH&gt;
          &lt;eSTBGeneralErrorCode&gt;
              &lt;0&gt;INTEGER: 0&lt;/0&gt;
          &lt;/eSTBGeneralErrorCode&gt;
          &lt;eSTBGeneralConnectedState&gt;
              &lt;0&gt; INTEGER: true(1) &lt;/0&gt;
          &lt;/eSTBGeneralConnectedState&gt;
          &lt;eSTBGeneralPlatformID&gt;
              &lt;0&gt; INTEGER: 2076 &lt;/0&gt;
          &lt;/eSTBGeneralPlatformID&gt;
      &lt;/GI-eSTB-MIB-NPH&gt;
  &lt;/doc&gt;
  </code></pre>
  
  <p>Actual error is: </p>
  
  <pre><code>not well-formed (invalid token) at line 6, column 13, byte 112 at /usr/lib64/perl5/XML/Parser.pm line 187
  </code></pre>
  
  <p>I have searched for solution and found some posts where same issue was mentioned but didn't find solution that could help me here. Following are the things I tried that I had found from various online forums:</p>
  
  <ol>
  <li>Checked format of xml and compared at <a href="http://www.w3schools.com/xml/xml_server.asp" rel="nofollow">http://www.w3schools.com/xml/xml_server.asp</a></li>
  <li>Adding space &lt;0> INTEGER: 0 </li>
  <li>removed - encoding="UTF-8"</li>
  <li>changed "UTF-8" to "UTF-16" and "ISO-8859-1"</li>
  <li>perl -ne 'print $_ if not m/^output_1.xml and used output_1.xml</li>
  <li>perl -ne'print $_ if ! /^
  <li>strings output.xml > output_1.xml and used output_1.xml</li>
  </ol>
  
  <p>Please suggest if I can try something more. I am not sure if there's really something wrong in the xml or in my code somewhere.</p>