You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello
I want to parse my doc and read the attribute range, I had read the doc and the issue https://github.com/jhy/jsoup/pull/1114.I found some time, the org.jsoup.nodes.Attribute#sourceRange return null. After test, I found if body tag is preceded by some tags, like p, span the org.jsoup.nodes.Attribute#sourceRange will return null,otherwise, it works normally. I don't know if this is a bug, is there some way to recognize it and get the range of attr?
my code:
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;
import java.io.FileInputStream;
public class TestMain {
public static void main(String[] args) throws Exception{
FileInputStream fis = new FileInputStream("tmp.html");
String text = new String(fis.readAllBytes());
Parser parser = org.jsoup.parser.Parser.htmlParser();
parser.setTrackPosition(true);
Document doc = Jsoup.parse(text,parser);
for (Element element : doc.getAllElements()){
Attribute targetAttr = element.attribute("target");
if (targetAttr != null){
System.out.println(targetAttr.sourceRange());
}
}
}
}
Hello
I want to parse my doc and read the attribute range, I had read the doc and the issue https://github.com/jhy/jsoup/pull/1114.I found some time, the
org.jsoup.nodes.Attribute#sourceRange
return null. After test, I found if body tag is preceded by some tags, like p, span theorg.jsoup.nodes.Attribute#sourceRange
will return null,otherwise, it works normally. I don't know if this is a bug, is there some way to recognize it and get the range of attr?The text was updated successfully, but these errors were encountered: