Question
· Aug 30, 2016

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? 

Discussion (4)0
Log in or sign up to continue

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"