有没有办法获取元素/标签的起始行号和列号和结束行号和列号?
我正在创建 HTML 编辑器,需要根据给定的开始和结束行及列号根据某些场景突出显示标签以优化速度。
最佳答案
不,不幸的是,目前 jsoup 无法做到这一点。
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.
来源:https://groups.google.com/forum/#!topic/jsoup/lnbYSIZApWw
相反,您可以尝试 Jericho HTML Parser 。在其功能列表中写道:
The row and column number of each position in the source document are easily accessible.
请参阅 javadocs here并研究诸如 getRow()
、getColumn()
和 getRowColumnVector()
等方法。
关于java - JSOUP HTML 解析器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20215002/