Skip to content

as_list.xml_node drops element names if any xml attributes exist #115

Closed
@peterfoley

Description

@peterfoley

Reproducible example:

txt <- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<level_0 xmlns=\"http://whatever.com\">
  <level_1a> 
    <item>item1a</item>
  </level_1a>
  <level_1b>
    <item>item1b</item>
  </level_1b>
</level_0>
"

packageVersion("xml2")
library(xml2)
parsed <- as_list(read_xml(gsub("\\n\\s*","",txt)))
names(parsed)

The issue appears to be line 58 in:
attributes(out) <- as.list(attr)
which overwrites the names that were previously stored by line 52.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions