diff --git a/DESCRIPTION b/DESCRIPTION index 2f5f8fa..3d0a34d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: marshal -Version: 0.0.0-9033 +Version: 0.0.0-9034 Title: Framework to Marshal Objects to be Used in Another R Process Depends: R (>= 3.2.0) diff --git a/R/marshal.xml2.R b/R/marshal.xml2.R index 35c1000..fb17c72 100644 --- a/R/marshal.xml2.R +++ b/R/marshal.xml2.R @@ -31,7 +31,10 @@ marshal.xml_nodeset <- function(xml2, ...) { marshal_xml2 <- function(xml2, ...) { res <- list( - marshalled = xml2::xml_serialize(xml2, connection = NULL) + marshalled = list( + doctype = xml2:::doc_type(xml2), + raw = xml2::xml_serialize(xml2, connection = NULL) + ) ) class(res) <- marshal_class(xml2) @@ -47,7 +50,9 @@ marshal_xml2 <- function(xml2, ...) { unmarshal_xml2 <- function(xml2, ...) { object <- xml2[["marshalled"]] - res <- xml2::xml_unserialize(object) + args <- list(object[["raw"]]) + if (object[["doctype"]] == "html") args$as_html <- TRUE + res <- do.call(xml2::xml_unserialize, args = args) stopifnot(identical(class(res), marshal_unclass(xml2))) res } diff --git a/tests/marshal.xml2.R b/tests/marshal.xml2.R index 7a9949d..7b36ee5 100644 --- a/tests/marshal.xml2.R +++ b/tests/marshal.xml2.R @@ -13,4 +13,18 @@ if (requireNamespace("xml2", quietly = TRUE)) { doc2 <- unmarshal(doc_) stopifnot(all.equal(doc2, doc)) + + file <- system.file("extdata", "r-project.html", package = "xml2") + doc <- xml2::read_html(file) + + ## Assert marshallability + stopifnot(marshallable(doc)) + + ## Marshal 'xml_document' object + doc_ <- marshal(doc) + + ## Unmarshal 'xml_document' object + doc2 <- unmarshal(doc_) + + stopifnot(all.equal(doc2, doc)) }