How to distinguish whether the data from database text field is an XML or Text file ?


Hi,

I have a column in  SQL-Server 2000 database as (Text) field. I can store any type of file (Possibilly two Text & XML). Now with VB.NET code, i want to know whether the data is XML file or Text file !!

Can you suggest me the way to do it ?

Thanks,
Kishore
kishore_peddiAsked:
Who is Participating?
 
wyoung76Connect With a Mentor Commented:
Assuming that it's text XML, then my suggestion is to run an XML validation on the field to test for "XML-ness" or not.  This could be as naive as doing:

    Dim xd As System.Xml.XmlDocument
    Try
        ' succeeds if it's validating XML
        xd = New System.Xml.XmlDocument.LoadXml(loadedText)
    Catch e As XmlException
        ' it isn't validating XML
    End Try

Of course, this abuses the exception handling system  ;o)
0
All Courses

From novice to tech pro — start learning today.