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
In the
commonDomMainimplementation ofElement, thegetElementsByTagNamemethod (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