Skip to content

getElementsByTagName and similar methods only return immediate descendants #265

@JR-Mitchell

Description

@JR-Mitchell

In the commonDomMain implementation of Element, the getElementsByTagName method (and similar methods) simply iterate through the direct child nodes of the element.
This differs from the expected behaviour from DOM, which is that all of the descendants of the element are searched through.

A test such as:

@Test
test_getElementsByTagName_withGrandchildNode() {
    val xmlString = """
        <parent>
            <child>
                <grandchild />
            </child>
        </parent>
    """
    val parsed = XML().decodeFromString(Element.deserializer(), xmlString)
    val grandchildren = parsed.getElementsByTagName("grandchild")
    assertEquals(grandchildren.length, 1)
}

will succeed on the JVM, but fail on e.g iOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    indevThe issue is fixed/implemented in the dev branch

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions