javaparsingjsoupelement

How can I get the LineNumber of the element when using Jsoup?


such as:

Document doc = Jsoup.parse(file,"UTF-8");

Elements eles = doc.getElementsByTag("style");

How can I get the lineNumber of eles[0] in the file?


Solution

  • There is no way for you to do it with Jsoup API. I have checked on their source code: org.jsoup.parser.Parser maintains no position information of the element in the original input.

    Please, refer to sources on Grep Code

    Provided that Jsoup is build for extracting and manipulating data I don't believe that they will have such feature in future as it is ambigous what element position is after manipulation and costly to maintain actual references.