1

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.

hiddenuser
  • 525
  • 2
  • 7
  • 19
  • 1
    I forked Jsoup and track the start and end position of all elements in the source document. I don't have column numbers and line numbers, but maybe this could be a start for you. You can find the code [here](https://github.com/tvogels/jsoup). – Thijs Oct 22 '15 at 11:34

1 Answers1

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

ashatte
  • 5,442
  • 8
  • 39
  • 50
  • Is there any other Java HTML Parser that track line numbers ? – hiddenuser Nov 26 '13 at 11:48
  • @user2998596 Have you looked into [Jericho HTML Parser](http://jericho.htmlparser.net/docs/index.html)? In the features list is says `The row and column number of each position in the source document are easily accessible.` It has methods such as `getRow()`, `getColumn()`, and `getRowColumnVector()`. – ashatte Nov 26 '13 at 12:57