Currently I'm trying to differentiate between different serialized text formats. Mainly between XBRL, XML, CSV, and JSON.
I would like to assume that, checking by steps, if we use a parser to parse an XBRL/XML and returns without any exception thrown, then it's a valid XML document and needs further checking to see if the document is a regular xml or an xbrl.
If the first check fails, try parsing the csv. If parsing the csv returns an exception, try parsing as a JSON. If none of the above works, it's an invalid document.
Would this be an exceptional way of identifying the type of text format the document is? Or is there a better way? (i.e reading the first few bytes of the document etc...).
thanks