Sunday, 12 January 2014

C# : check whether input string data is XML or NOT



To check whether input string data is XML or NOT.


Simply copy and paste the following code. This code will throw an exception in case input string is not XML.

       if (!String.IsNullOrEmpty(sXMLMessage))
            {
                try
                {
                    System.Xml.Linq.XElement.Parse(sXMLMessage);
                   // Business Logic for XML string data here

                }
                catch (XmlException ex)
                {                  
                   // Business Logic for non-xml string data here
                }
            }

No comments:

Post a Comment