These functions can be used to control
how the C-level data structures associated with XML documents, nodes,
XPath queries, etc. are serialized to a a file or connection
and deserialized back into an R session.
Since these C-level data structures are represented
in R as external pointers, they would normally be serialized
and deserialized in a way that loses all the information about
the contents of the memory being referenced.
xmlSerializeHook arranges to serialize these pointers
by saving the corresponding XML content as a string
and also the class of the object.
The deserialize function converts such objects back to their
These functions are used in calls to
readRDS via the
saveRDS(obj, filename, refhook = xmlSerializeHook)
readRDS(filename, refhook = xmlDeserializeHook)
the object to be deserialized, and the character vector to be deserialized.
xmlSerializeHook returns a character version of the XML
document or node, along with the basic class.
If it is called with an object that is not an native/internal XML
object, it returns
xmlDeserializeHook returns the parsed XML object, either a
document or a node.
Duncan Temple Lang
The R Internals Manual.
1 2 3 4 5 6 7 8 9 10 11 12 13
z = newXMLNode("foo") f = system.file("exampleData", "tides.xml", package = "XML") doc = xmlParse(f) hdoc = as(doc, "XMLHashTree") nodes = getNodeSet(doc, "//pred") ff <- file.path(tempdir(), "tmp.rda") saveRDS(list(a = 1:10, z = z, doc = doc, hdoc = hdoc, nodes = nodes), ff, refhook = xmlSerializeHook) v = readRDS(ff, refhook = xmlDeserializeHook) unlink(ff)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.