JSOUP HTML Parser

荒凉一梦 提交于 2019-12-20 04:04:19

问题


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.


回答1:


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().



来源:https://stackoverflow.com/questions/20215002/jsoup-html-parser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!