Is there anything built-in to determine if the XML file is valid. One way is to read all the content and check if the string matches the actual XML content. Even then, how to determine if a string contains valid XML data.
You can try loading XML into an XML document and catch the exception. Here is a sample code:
var doc = new XmlDocument(); try { doc.LoadXml(content); } catch (XmlException e) { // put code here that should be executed when the XML is not valid. }
Hope this helps.
Create XmlReaderaround StringReader with XML and read through the reader:
XmlReader
using (var reader = XmlReader.Create(something)) while(reader.Read()) ;
If you don't get any exceptions, XML is well formed.
XDocument XmlDocument, DOM , XML.
Take a look at this question:
How to check valid xml in string input before calling .LoadXml ()