|The stupid question is the question not asked|
Is a file XML?by ajt (Prior)
|on Sep 25, 2001 at 15:10 UTC||Need Help??|
ajt has asked for the
wisdom of the Perl Monks concerning the following question:
I have a requirment to quickly check to see if a document uploaded to the server is an XML file. It should be, but you never know....
I would like my script (built round CGI) to give the user an error if the file isn't a well formed XML one. I've checked that the file is more than zero bytes already.
I don't want to check for validity (I can't anyway), I just want to quickly be able to emit an error message to the user's browser, and die.
I assume that if I simply open up the file in an XML parser, and it doesn't die when I parse it, then it's XML and well-formed, which should be enough to pass the file on to another process.
Q1 Is this a sensible approach?
Q2 If it is, which module is fastest and simplest? I don't plan to actually do anything with the file. Just do a HTTP POST to another server.
As ever, many thanks in advance.