It depends on what range of possibilities you might be facing in the data. The first (and easiest) thing to do would be to check for any non-ASCII content, and you can do that on the file as a whole before XML parsing, e.g. like this:
#!/usr/bin/perl use strict; my $non_ascii = 0; while (<>) { $non_ascii++ if ( /[^\x00-\x7f]/ ); } warn "input contains non-ASCII\n" if ( $non_ascii );
Beyond that, if there is non-ASCII content, the actual nature of such content (what character encoding, what language) might require some guessing... Encode::Guess could be helpful, depending on what language and character encoding are actually present.

People who are smart enough to use XML with non-ASCII data usually have the clue about using utf8 encoding, and if your data falls into this category, Encode::Guess will work fine to confirm that (byte patterns in utf8 are quite distinctive and unmistakable). But if its one or another single-byte encoding (any of the cp125* or iso-8859-* character sets), you'll need to know what the intended language is in order to help Encode::Guess come up with a right answer.


In reply to Re: How to check the encoding format of an XML by graff
in thread How to check the encoding format of an XML by rellaboyina

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.