Checking wether a file is XML or plain text?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I would like to know if there is any way to check if a file is an XML or a
plain text file?
Opening the file with a FileStream and checking the first character for '<'
seems not very clean and in case of performance not very fast either, as I
would have to open the file twice if it is an XML file. I can't use the file
extension as it is not shure, that every XML file will have the .xml
extension within the system I need this feature.

Hope you can help me with this problem...

Stampede
 
Not very smart solution, but if you think that the xml is expected
format, try to open file with XmlTextReader() and wait for XmlException
if it isn't well formated XML.
 
stic said:
Not very smart solution, but if you think that the xml is expected
format, try to open file with XmlTextReader() and wait for XmlException
if it isn't well formated XML.

I guess apart from this there is no clean way to differentiate XML file from
text file as XML files are also text files. So you have only option to check
for Well-Form XML.
 
Back
Top