How to get error's line number while validating a XML file against a XML schema

前端 未结 4 1854
清歌不尽
清歌不尽 2021-02-01 21:26

I\'m trying to validade a XML against a W3C XML Schema.

The following code does the job and reports when error occurs. But I\'m unable to get line number of the error. I

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 21:42

    Replace this line:

    validator.validate(new DOMSource(document));
    

    by

    validator.validate(new StreamSource(new File("myxml.xml")));
    

    will let the SAXParseException contain line number & column number

提交回复
热议问题