Validate XML Syntax Only in C#

c#, xml

Solution

Or if you're on .NET 3.5, you can use `XElement.Load()`.

LINQ to XML's loading functionality is built upon XmlReader. Therefore, you might catch any exceptions that are thrown by the XmlReader.Create overload methods and the XmlReader methods that read and parse the document.

Problem

There are a lot of tutorials that teach on how to validate XML against a schema. But now I want to validate XML syntax only, not against the schema. Meaning I just want to check whether the XML is well-form, that whether there are closing or opening tag that is not done properly. Is there anyway I can do that in .Net?

Original source