File: serialize.R

package info (click to toggle)
r-cran-xml 3.99-0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,688 kB
  • sloc: ansic: 6,659; xml: 2,890; asm: 486; sh: 12; makefile: 2
file content (28 lines) | stat: -rw-r--r-- 748 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
xmlSerializeHook =
function(x)
{
   if(inherits(x, c("XMLInternalDocument", "XMLInternalElementNode")))
     c(as(x, "character"), class(x)[1])
   else if(is(x, "XMLNodeSet"))
     c(sapply(x, as, "character"), class(x)[1])   
   else
     NULL
}

xmlDeserializeHook =
function(x)
{
  if(length(x) == 2) {
    if(x[2] == "XMLInternalElementNode")
      xmlRoot(xmlParse(I(x[1])))
    else if(x[2] == "XMLNodeSet") {
        #XXX we should put these into the same document, but it is hard to make this sensible.
      structure(lapply(x, function(x) xmlRoot(xmlParse(I(x)))), "XMLNodeSet")
    } else if(x[2] == "XMLInternalDocument")
       xmlParse(I(x[1]))
    else
       stop("Not sure how to handle ", x[2])
  } else
    xmlParse(I(x))    
}