Photius has asked for the wisdom of the Perl Monks concerning the following question:

What's a quick easy way to check whether an .xml file is "well formed"? I don't need to open the file or manipulate its contents, just loop thru a set of files decide whether each is well formed. I tried using XML::Parser. However $parser->parsefile just dies if the xml is not well formed. I don't want it to die.

Replies are listed 'Best First'.
Re: How to Check if XML Well Formed
by merlyn (Sage) on Jan 02, 2008 at 22:19 UTC
    Well, it throws an exception. If you don't catch that exception, it dies, sure. But to catch exceptions, put it inside an eval-block. Then you can do what you want once you notice that exception.
      Thanks! Duh.