JSOUP HTML Parser

前端 未结 1 1978
灰色年华
灰色年华 2021-01-26 20:52

Is there a way to get start line & column number and end line & column number of element/tag ?

I am creating HTML editor that

相关标签:
1条回答
  • 2021-01-26 21:47

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

    0 讨论(0)
提交回复
热议问题