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?
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.
Just open it in an XmlReader and read to the end. If it makes it without throwing an exception, it's well formed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With