I got an error recently after modifying a script I wrote to parse XML from juniper router commands. The change was to run a different show command that produces more information. The problem is that routers are apparently bad at XML and this caused the mal-formatted XML I'm used to to turn into invalid XML. Will post more code if required but It worked pretty well before the invalid characters. I put in a regex to remove the invalid character, but I was curious if there was a way to do this automatically. Or at least another module that provides better error handling. Here's the error: reference to invalid character number at line 1, column 1373, byte 1373 at /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/XML/Parser.pm line 187 Any advice would be helpful. Some clue as to how to zero in on line 1, column 1373, byte 1373 of a file would be helpful as well. Thanks

use XML::Simple; my $xml = new XML::Simple (KeyAttr=>[]); my $data = $xml->XMLin("cmd-out\/$hostname.xml");

In reply to Validating XML by networker2149

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.