Is there a way to get start line & column number and end line & column number of element/tag ?
I am creating HTML editor that needs to highlight tag for speed optimization based on some scenario by given start and end line & column number .
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()
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.