One of the users asked in the forum how to report validation error location by using XPath. The JAXB RI reports line numbers when available, but when you are validating the output from the marshalling, then line numbers don't mean much. Hence this user wanted to locate error in XPath.

When you are validating the marshalling output, what it is doing is that it produces SAX events that represent the XML, and then feed that to the validation API in JAXP 1.3. So one can keep track of the location in XPath by monitoring this SAX events.

So I wrote a code to do it. It's implemented as SAX'sXMLFilter, so you can use it anwhere outside JAXB to keep track of the "current" location by XPath.

See the test code for how to use this in conjunction with JAXB.