Get line number from xml node - java

前端 未结 4 582
逝去的感伤
逝去的感伤 2020-12-01 15:43

I have parsed an XML file and have gotten a Node that I am interested in. How can I now find the line number in the source XML file where this node occurs?

EDIT: Cur

4条回答
  •  天命终不由人
    2020-12-01 16:32

    Note that according to the spec (of Locator.getLineNumber()) the method returns the line number where the SAX-event ends!

    In the case of "startElement()" this means:

    Here the line number for Element is 1:

    
    

    Here the line number for Element is 3:

    
    
    

提交回复
热议问题