File: xml_type.R

package info (click to toggle)
r-cran-xml2 1.1.0-1~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 852 kB
  • sloc: cpp: 1,057; xml: 115; sh: 53; ansic: 12; makefile: 6
file content (51 lines) | stat: -rw-r--r-- 881 bytes parent folder | download | duplicates (3)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#' Determine the type of a node.
#'
#' @inheritParams xml_name
#' @export
#' @examples
#' x <- read_xml("<foo> a <b /> <![CDATA[ blah]]></foo>")
#' xml_type(x)
#' xml_type(xml_contents(x))
xml_type <- function(x) {
  UseMethod("xml_type")
}

#' @export
xml_type.xml_missing <- function(x) {
  NA_character_
}

#' @export
xml_type.xml_node <- function(x) {
  xmlElementType[node_type(x$node)]
}

#' @export
xml_type.xml_nodeset <- function(x) {
  types <- vapply(x, function(x) node_type(x$node), integer(1))
  xmlElementType[types]
}

xmlElementType <- c(
  "element",
  "attribute",
  "text",
  "cdata",
  "entity_ref",
  "entity",
  "pi",
  "comment",
  "document",
  "document_type",
  "document_frag",
  "notation",
  "html_document",
  "dtd",
  "element_decl",
  "attribute_decl",
  "entity_decl",
  "namespace_decl",
  "xinclude_start",
  "xinclude_end",
  "docb_document"
)