· Jan 16, 2019

Any good way to find xpath from Line and offset.

I am validating a v3 document against one xsd and using %XML.SAX.ContentHandler class . My requirment is to find the xpath of the error location. There is no method which does it.

I can find the line and offset using LocatePosition method. 

Can someone help me on this.



Discussion (2)0
Log in or sign up to continue

You can't do that directly. SAX XML  parsing and XPATH are two completely different, unrelated, technologies. The best you could do would be to subclass the ContentHandler class and record the 'path'  as each element is reported. You would want to declare a transient property to hold the 'path' and then incrementally build it up as startElement() is called and pull it down when endElement() is called. When an error occurs, consult the value of the 'path' property. This won't give you an XPATH path but it will give you something similar to give you an idea of where you are in the document.