xml2 icon indicating copy to clipboard operation
xml2 copied to clipboard

as_list() return element text as character, not list

Open StevenMMortimer opened this issue 6 years ago • 1 comments

Issue Description

as_list() will convert element text into a list of length 1 with a single character element. I would expect it to "simplify" or "unbox" the text so it is not a list. The XML package already has this type of behavior in using xmlToList().

Reproducible Example

In the example below the "bar" element text "Hello" is represented as a list. I would expect it to be a character string.

library(xml2)
as_list(read_xml("<bar>Hello</bar>")) 
#> $bar
#> $bar[[1]]
#> [1] "Hello"

# the desired result would be
#> $bar
#> [1] "Hello"

The XML package has similar style to the more desirable behavior.

library(XML)
xmlToList(newXMLNode("bar","Hello"))
#> [1] "Hello"

StevenMMortimer avatar Mar 29 '18 01:03 StevenMMortimer

Same problem for me!

Rathpete avatar May 29 '22 10:05 Rathpete