1

I'm looking for some code in .net to allow me to test an xml file to determine if it is well-formed. I am not validating the file against a schema at this point in my code, just testing that it conforms to xml specification for being well formed.

Any assistance is appreciated.

Dean
  • 3,336
  • 6
  • 36
  • 37
  • possible duplicate of [Check well-formed XML without a try/catch?](http://stackoverflow.com/questions/1026247/check-well-formed-xml-without-a-try-catch) – Matthew Whited Jun 24 '10 at 18:04

1 Answers1

5

Just try parsing the XML into an XMLDocument and see if it throws.

Pierreten
  • 9,917
  • 6
  • 37
  • 45
  • Thanks for your answer. After asking the above question, I found this stackoverflow question that didn't show up in my initial search: http://stackoverflow.com/questions/1026247/check-well-formed-xml-without-a-try-catch – Dean Jun 24 '10 at 18:02