Is there a way to get start line & column number and end line & column number of element/tag ?
I am creating HTML editor that
No, unfortunately this is not possible with jsoup at the current time.
At the moment Jsoup does not track line numbers / character positions when parsing, so it's not possible to extract them. As this is not a core use case, I don't want to extend the memory requirements of the DOM by retaining this data. I have thought about possibly adding an optional side-channel way to track it during the parse, in a similar way as how parse errors can be tracked, but haven't focused on implementing that yet.
Source: https://groups.google.com/forum/#!topic/jsoup/lnbYSIZApWw
Instead, you could try Jericho HTML Parser. In its list of features it says:
The row and column number of each position in the source document are easily accessible.
See the javadocs here and look into methods such as getRow()
, getColumn()
, and getRowColumnVector()
.