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
Try using a SAXLocator http://download.oracle.com/javase/1.5.0/docs/api/org/xml/sax/Locator.html Parsers are not required to supply one, but if they do it should report line numbers
I think your code should include:
// this will be called when XML-parser starts reading
// XML-data; here we save reference to current position in XML:
public void setDocumentLocator(Locator locator) {
this.locator = locator;
}
(see http://www.java-tips.org/java-se-tips/org.xml.sax/using-xml-locator-to-indicate-current-parser-pos.html)
The parser will give you a locator which you can then use to get the line number. It's probably worth printing/debugging when this happens to see if you have a valid locator