Skip to content

nth-of-type selector does not work with tag "SVG" #75

@code4craft

Description

@code4craft

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
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions