Validating XML on XSD with the error line numbers

前端 未结 6 1080
盖世英雄少女心
盖世英雄少女心 2021-01-04 15:19

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

6条回答
  •  暖寄归人
    2021-01-04 15:47

    This example is the most complete I've found. It's slower than other validation methods, but it's the best for debugging: It writes validated element for each line and errors found.

    To have numbers of lines with errors just add this line in ValidationHandler method:

    Console.WriteLine(args.Exception.LineNumber);
    

    Pay attention that xsd file is specified in the root tag of the Xml doc.

提交回复
热议问题