Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion R/as_jsonlist.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ attributes_to_json <- function(x, ns = character(), prefix = "", out = list()){
out
}

unescape_xml <- function(str){
xml2::xml_text(xml2::read_xml(paste0("<x>", str, "</x>")))
}

## override xml2 method
#' @importFrom xml2 xml_contents xml_name xml_attrs xml_type xml_text
as_jsonlist.xml_node <- function(x, ns = character()) {
key <- xml_name(x)
## Treat <para> and <section> as literals
if(key %in% c("para", "section")){
return(paste(as.character(xml_contents(x)), collapse = ""))
return(paste(unescape_xml(as.character(xml_contents(x))), collapse = ""))
}

contents <- xml2::xml_contents(x)
Expand Down