-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Milestone
Description
In XPath like //div/svg[2]
, only the first element of tag "svg" will be selected.
I checked code in Jsoup,
protected int calculatePosition(Element root, Element element) {
int pos = 0;
Elements family = element.parent().children();
for (int i = 0; i < family.size(); i++) {
if (family.get(i).tag() == element.tag()) pos++;
if (family.get(i) == element) break;
}
return pos;
}
The element is compared by Tag object. And the Tag object is create by Tag.valueOf().
For known tags, they will be got from the map Tag.tags. But for unknown tag (such as svg), it is created ever time when call , so the compare "if (family.get(i).tag() == element.tag()) pos++;" will return false.
I have sent a pull request to Jsoup jhy/jsoup#402.
Metadata
Metadata
Assignees
Labels
No labels