xml2
xml2 copied to clipboard
as_list() return element text as character, not list
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"
Same problem for me!