Skip to content

Duplicated names for elements in list after calling as_list #436

@pepijn-devries

Description

@pepijn-devries

Thanks for your work on xml2!

Consider the following reprex where I have an xml document with multiple nodes of the same element (item):

a <- xml2::as_xml_document("<collection><item>foo</item><item>bar</item></collection>")
b <- xml2::as_list(a)

## This will only show "foo" but not "bar"
b$collection$item
#> [[1]]
#> [1] "foo"

## However both elements are there:
names(b$collection)
#> [1] "item" "item"
b$collection[[1]]
#> [[1]]
#> [1] "foo"
b$collection[[2]]
#> [[1]]
#> [1] "bar"

Created on 2023-12-30 with reprex v2.0.2

When the xml document in the reprex is converted to a list, the list elements will have duplicated names. Which I think is undesirable in R, and will cause all sorts of problems. Would it be possible to either:

  1. Throw a warning when as_list produces duplicated element names; or
  2. Repair the names such that they become unique.

Thanks for considering.

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions