Get to know the format
I know that Cache files can be stored as XML and UDL based files. Is there any way to determine in which format the file(class, routine, dfi and so on) is stored? Because you can easily name your XML based file as class.cls and it will be perfectly valid.
I know that one way to check whether this file is in XML format is just try to parse it like
Set st = ##class(%XML.TextReader).ParseStream(contentStream)
if $$$ISERR(st) return $$$NO
else return $$$YES
However, is there a better way?
Well you could check if the first character is "<" or not. I am not sure you can write a valid Caché construct that begins with a less-than, while XML must, necessarily begin with one. So something like:
s strm=##class(%Stream.FileCharacter).%New()
d strm.LinkToFile(<file location>)
if strm.Read(1)="<" return "XML"
return "UDL"
Thank you. Didn't think of that
Well you kind of did - they are functionally very similar :-)
Just now I realized that dfi files are in XML format even though you export it in UDL. The only difference is that I don't have several tags such as <Export> and <Document> in UDL. So I think better way would be to search for <Export> tag.