Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validating XML on XSD with the error line numbers

Tags:

c#

.net

Is there any way to validate an XML file on an XSD schema with the output of the error line numbers?

The XmlReader reader doesn't allow line numbers, it shows only the element name.

like image 817
Wachburn Avatar asked Oct 27 '11 10:10

Wachburn


1 Answers

Since @chris-watts suggested to post my comment again as answer. Here it is.

The document only has line number information if it was loaded with the appropriate flags:

var opts = LoadOptions.PreserveWhitespace 
         | LoadOptions.SetLineInfo;
XDocument doc = XDocument.Load(fileStream, opts); 
like image 159
schoetbi Avatar answered Sep 19 '22 16:09

schoetbi