Closed
Description
When I create XML de novo, the encoding is not explicitly set to UTF-8 when I send the document through as.character()
or write_xml()
, even thought the text I'm putting into the nodes is. Am I missing a way to do that? This happens automatically when XML is created by read_xml()
.
library(xml2)
xml <- xml_new_document() %>%
xml_add_child("root", name = "people") %>%
xml_root()
Encoding(gabor <- "Gábor Csárdi")
#> [1] "UTF-8"
Encoding(maelle <- "Maëlle Salmon")
#> [1] "UTF-8"
xml_add_child(xml, "person", "Gábor Csárdi")
#> {xml_node}
#> <person>
y <- xml_add_child(xml, "person")
xml_text(y) <- maelle
xml
#> {xml_document}
#> <root name="people">
#> [1] <person>Gábor Csárdi</person>
#> [2] <person>Maëlle Salmon</person>
as.character(xml)
#> [1] "<?xml version=\"1.0\"?>\n<root name=\"people\"><person>Gábor Csárdi</person><person>Maëlle Salmon</person></root>\n"
xml3 <- read_xml("<root name = 'people'><person>Gábor Csárdi</person><person>Maëlle Salmon</person></root>")
as.character(xml3)
#> [1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root name=\"people\"><person>Gábor Csárdi</person><person>Maëlle Salmon</person></root>\n"
Metadata
Metadata
Assignees
Labels
No labels