Dear Monks,
I am using XML::Simple and trying to parse a file. Here is my sample code.
use XML::Simple; use strict; use warnings; $| += 1; opendir TMP,'/u1/tmptest'; my @files = grep /xml$/, grep { - r } readdir TMP; chdir '/u1/tmptest'; my $flag = 0; foreach my $file (@files){ my $tmp_xml = XMLin("./$file"); process($tmp_xml); } sub process { my $xml = shift; my $title = $xml->{head}->{title}; .... }
It gives me error:
Character reference & #133; refers to an illegal XML character (\205) 

When I checked the particular file, it has & #133; character inside.

What I like to do is either correct the problem and proceed or ignore the file. I don't have control over the source files. If I don't process this file it gives error for some other similar character .. ex: & #146;

In CB, podmaster pointed out that it XML::Simple which is based on XML::Parser dies upon invalid xml. I like to find some solution at this point.

Thanks,
artist

(Note: In the above examples & and # should not have space between them.. it's just that PM tries to interprete the character.)


In reply to XML::Simple exit problem by artist

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.