Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Collate:
'xml_parse.R'
'as_xml_document.R'
'classes.R'
'cpp11.R'
'format.R'
'import-standalone-obj-type.R'
'import-standalone-purrr.R'
Expand Down Expand Up @@ -71,3 +72,5 @@ Collate:
'xml_write.R'
'zzz.R'
Config/testthat/edition: 3
LinkingTo:
cpp11
2 changes: 1 addition & 1 deletion R/as_xml_document.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ as_xml_document.list <- function(x, ...) {

add_node <- function(x, parent, tag = NULL) {
if (is.atomic(x)) {
return(.Call(node_new_text, parent$node, as.character(x)))
return(node_new_text(parent$node, as.character(x)))
}
if (!is.null(tag)) {
parent <- xml_add_child(parent, tag)
Expand Down
253 changes: 253 additions & 0 deletions R/cpp11.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,253 @@
# Generated by cpp11: do not edit by hand

read_connection_ <- function(con_sxp, read_size_sxp) {
.Call(`_xml2_read_connection_`, con_sxp, read_size_sxp)
}

xml_parse_options_ <- function() {
.Call(`_xml2_xml_parse_options_`)
}

doc_parse_file <- function(path_sxp, encoding_sxp, as_html_sxp, options_sxp) {
.Call(`_xml2_doc_parse_file`, path_sxp, encoding_sxp, as_html_sxp, options_sxp)
}

doc_parse_raw <- function(x, encoding_sxp, base_url_sxp, as_html_sxp, options_sxp) {
.Call(`_xml2_doc_parse_raw`, x, encoding_sxp, base_url_sxp, as_html_sxp, options_sxp)
}

doc_root <- function(x) {
.Call(`_xml2_doc_root`, x)
}

doc_has_root <- function(x_sxp) {
.Call(`_xml2_doc_has_root`, x_sxp)
}

doc_url <- function(doc_sxp) {
.Call(`_xml2_doc_url`, doc_sxp)
}

doc_new <- function(version_sxp, encoding_sxp) {
.Call(`_xml2_doc_new`, version_sxp, encoding_sxp)
}

doc_set_root <- function(doc_sxp, root_sxp) {
.Call(`_xml2_doc_set_root`, doc_sxp, root_sxp)
}

doc_is_html <- function(doc_sxp) {
.Call(`_xml2_doc_is_html`, doc_sxp)
}

init_libxml2 <- function() {
.Call(`_xml2_init_libxml2`)
}

libxml2_version_ <- function() {
.Call(`_xml2_libxml2_version_`)
}

unique_ns <- function(ns) {
.Call(`_xml2_unique_ns`, ns)
}

doc_namespaces <- function(doc_sxp) {
.Call(`_xml2_doc_namespaces`, doc_sxp)
}

ns_lookup_uri <- function(doc_sxp, node_sxp, uri_sxp) {
.Call(`_xml2_ns_lookup_uri`, doc_sxp, node_sxp, uri_sxp)
}

ns_lookup <- function(doc_sxp, node_sxp, prefix_sxp) {
.Call(`_xml2_ns_lookup`, doc_sxp, node_sxp, prefix_sxp)
}

node_name <- function(x, nsMap) {
.Call(`_xml2_node_name`, x, nsMap)
}

node_set_name <- function(node_sxp, value) {
.Call(`_xml2_node_set_name`, node_sxp, value)
}

node_text <- function(x) {
.Call(`_xml2_node_text`, x)
}

node_attr <- function(x, name_sxp, missing_sxp, nsMap_sxp) {
.Call(`_xml2_node_attr`, x, name_sxp, missing_sxp, nsMap_sxp)
}

node_attrs <- function(x, nsMap_sxp) {
.Call(`_xml2_node_attrs`, x, nsMap_sxp)
}

node_set_attr <- function(node_sxp, name_sxp, value, nsMap) {
.Call(`_xml2_node_set_attr`, node_sxp, name_sxp, value, nsMap)
}

node_remove_attr <- function(node_sxp, name_sxp, nsMap) {
.Call(`_xml2_node_remove_attr`, node_sxp, name_sxp, nsMap)
}

node_children <- function(node_sxp, only_node_sxp) {
.Call(`_xml2_node_children`, node_sxp, only_node_sxp)
}

node_length <- function(x, only_node_sxp) {
.Call(`_xml2_node_length`, x, only_node_sxp)
}

node_has_children <- function(node_sxp, only_node_sxp) {
.Call(`_xml2_node_has_children`, node_sxp, only_node_sxp)
}

node_parents <- function(node_sxp) {
.Call(`_xml2_node_parents`, node_sxp)
}

node_siblings <- function(node_sxp, only_node_sxp) {
.Call(`_xml2_node_siblings`, node_sxp, only_node_sxp)
}

node_parent <- function(node_sxp) {
.Call(`_xml2_node_parent`, node_sxp)
}

node_path <- function(x) {
.Call(`_xml2_node_path`, x)
}

nodes_duplicated <- function(nodes) {
.Call(`_xml2_nodes_duplicated`, nodes)
}

node_type <- function(x) {
.Call(`_xml2_node_type`, x)
}

node_copy <- function(node_sxp) {
.Call(`_xml2_node_copy`, node_sxp)
}

node_set_content <- function(node_sxp, content) {
.Call(`_xml2_node_set_content`, node_sxp, content)
}

node_append_content <- function(node_sxp, content) {
.Call(`_xml2_node_append_content`, node_sxp, content)
}

node_new_text <- function(node_sxp, content) {
.Call(`_xml2_node_new_text`, node_sxp, content)
}

node_append_child <- function(parent_sxp, cur_sxp) {
.Call(`_xml2_node_append_child`, parent_sxp, cur_sxp)
}

node_prepend_child <- function(parent_sxp, cur_sxp) {
.Call(`_xml2_node_prepend_child`, parent_sxp, cur_sxp)
}

node_prepend_sibling <- function(cur_sxp, elem_sxp) {
.Call(`_xml2_node_prepend_sibling`, cur_sxp, elem_sxp)
}

node_append_sibling <- function(cur_sxp, elem_sxp) {
.Call(`_xml2_node_append_sibling`, cur_sxp, elem_sxp)
}

node_replace <- function(old_sxp, cur_sxp) {
.Call(`_xml2_node_replace`, old_sxp, cur_sxp)
}

node_remove <- function(node_sxp, free_sxp) {
.Call(`_xml2_node_remove`, node_sxp, free_sxp)
}

node_new <- function(name) {
.Call(`_xml2_node_new`, name)
}

node_cdata_new <- function(doc_sxp, content_sxp) {
.Call(`_xml2_node_cdata_new`, doc_sxp, content_sxp)
}

node_comment_new <- function(content) {
.Call(`_xml2_node_comment_new`, content)
}

node_new_ns <- function(name, ns_sxp) {
.Call(`_xml2_node_new_ns`, name, ns_sxp)
}

node_set_namespace_uri <- function(doc_sxp, node_sxp, uri) {
.Call(`_xml2_node_set_namespace_uri`, doc_sxp, node_sxp, uri)
}

node_set_namespace_prefix <- function(doc_sxp, node_sxp, prefix_sxp) {
.Call(`_xml2_node_set_namespace_prefix`, doc_sxp, node_sxp, prefix_sxp)
}

node_new_dtd <- function(doc_sxp, name_sxp, eid_sxp, sid_sxp) {
.Call(`_xml2_node_new_dtd`, doc_sxp, name_sxp, eid_sxp, sid_sxp)
}

xml_save_options_ <- function() {
.Call(`_xml2_xml_save_options_`)
}

doc_write_file <- function(doc_sxp, path_sxp, encoding_sxp, options_sxp) {
.Call(`_xml2_doc_write_file`, doc_sxp, path_sxp, encoding_sxp, options_sxp)
}

doc_write_connection <- function(doc_sxp, connection, encoding_sxp, options_sxp) {
.Call(`_xml2_doc_write_connection`, doc_sxp, connection, encoding_sxp, options_sxp)
}

doc_write_character <- function(doc_sxp, encoding_sxp, options_sxp) {
.Call(`_xml2_doc_write_character`, doc_sxp, encoding_sxp, options_sxp)
}

node_write_file <- function(node_sxp, path_sxp, encoding_sxp, options_sxp) {
.Call(`_xml2_node_write_file`, node_sxp, path_sxp, encoding_sxp, options_sxp)
}

node_write_connection <- function(node_sxp, connection, encoding_sxp, options_sxp) {
.Call(`_xml2_node_write_connection`, node_sxp, connection, encoding_sxp, options_sxp)
}

node_write_character <- function(node_sxp, encoding_sxp, options_sxp) {
.Call(`_xml2_node_write_character`, node_sxp, encoding_sxp, options_sxp)
}

doc_validate <- function(doc_sxp, schema_sxp) {
.Call(`_xml2_doc_validate`, doc_sxp, schema_sxp)
}

url_absolute_ <- function(x_sxp, base_sxp) {
.Call(`_xml2_url_absolute_`, x_sxp, base_sxp)
}

url_relative_ <- function(x_sxp, base_sxp) {
.Call(`_xml2_url_relative_`, x_sxp, base_sxp)
}

url_parse_ <- function(x_sxp) {
.Call(`_xml2_url_parse_`, x_sxp)
}

url_escape_ <- function(x_sxp, reserved_sxp) {
.Call(`_xml2_url_escape_`, x_sxp, reserved_sxp)
}

url_unescape_ <- function(x_sxp) {
.Call(`_xml2_url_unescape_`, x_sxp)
}

xpath_search <- function(node_sxp, doc_sxp, xpath_sxp, nsMap_sxp, num_results_sxp) {
.Call(`_xml2_xpath_search`, node_sxp, doc_sxp, xpath_sxp, nsMap_sxp, num_results_sxp)
}
8 changes: 4 additions & 4 deletions R/init.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.onLoad <- function(lib, pkg) {
.Call(init_libxml2)
init_libxml2()
}

libxml2_version <- function() {
as.numeric_version(.Call(libxml2_version_))
as.numeric_version(libxml2_version_())
}

xml_parse_options <- function() {
.Call(xml_parse_options_)
xml_parse_options_()
}

xml_save_options <- function() {
.Call(xml_save_options_)
xml_save_options_()
}
1 change: 1 addition & 0 deletions R/xml2-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

## usethis namespace: start
#' @import rlang
#' @useDynLib xml2, .registration = TRUE
## usethis namespace: end
NULL
8 changes: 4 additions & 4 deletions R/xml_attr.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
#' xml_attrs(doc) <- c("b:id" = "one", "f:id" = "two", "id" = "three")
#' xml_set_attrs(doc, c("b:id" = "one", "f:id" = "two", "id" = "three"))
xml_attr <- function(x, attr, ns = character(), default = NA_character_) {
.Call(node_attr, x, attr, as.character(default), ns)
node_attr(x, attr, as.character(default), ns)
}

#' @export
Expand All @@ -72,7 +72,7 @@ xml_has_attr <- function(x, attr, ns = character()) {
#' @export
#' @rdname xml_attr
xml_attrs <- function(x, ns = character()) {
.Call(node_attrs, x, nsMap = ns)
node_attrs(x, nsMap_sxp = ns)
}

#' @param value character vector of new value.
Expand All @@ -85,10 +85,10 @@ xml_attrs <- function(x, ns = character()) {
#' @export
`xml_attr<-.xml_node` <- function(x, attr, ns = character(), value) {
if (is.null(value)) {
.Call(node_remove_attr, x$node, attr, ns)
node_remove_attr(x$node, attr, ns)
} else {
value <- as.character(value)
.Call(node_set_attr, x$node, attr, value, ns)
node_set_attr(x$node, attr, value, ns)
}
x
}
Expand Down
16 changes: 8 additions & 8 deletions R/xml_children.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
#' xml_child(x, 2)
#' xml_child(x, "baz")
xml_children <- function(x) {
nodeset_apply(x, function(x) .Call(node_children, x, TRUE))
nodeset_apply(x, function(x) node_children(x, TRUE))
}

#' @export
Expand All @@ -60,19 +60,19 @@ xml_child <- function(x, search = 1, ns = xml_ns(x)) {
#' @export
#' @rdname xml_children
xml_contents <- function(x) {
nodeset_apply(x, function(x) .Call(node_children, x, FALSE))
nodeset_apply(x, function(x) node_children(x, FALSE))
}

#' @export
#' @rdname xml_children
xml_parents <- function(x) {
nodeset_apply(x, function(x) .Call(node_parents, x))
nodeset_apply(x, function(x) node_parents(x))
}

#' @export
#' @rdname xml_children
xml_siblings <- function(x) {
nodeset_apply(x, function(x) .Call(node_siblings, x, TRUE))
nodeset_apply(x, function(x) node_siblings(x, TRUE))
}

#' @export
Expand All @@ -88,19 +88,19 @@ xml_parent.xml_missing <- function(x) {

#' @export
xml_parent.xml_node <- function(x) {
xml_node(.Call(node_parent, x$node), x$doc)
xml_node(node_parent(x$node), x$doc)
}

#' @export
xml_parent.xml_nodeset <- function(x) {
nodeset_apply(x, function(x) .Call(node_parent, x))
nodeset_apply(x, function(x) node_parent(x))
}


#' @export
#' @rdname xml_children
xml_length <- function(x, only_elements = TRUE) {
.Call(node_length, x, only_elements)
node_length(x, only_elements)
}

#' @export
Expand All @@ -115,7 +115,7 @@ xml_root <- function(x) {
return(xml_root(x[[1]]))
}
}
if (!.Call(doc_has_root, x$doc)) {
if (!doc_has_root(x$doc)) {
xml_missing()
} else {
xml_document(x$doc)
Expand Down
Loading