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
|
#' The URL of an XML document
#'
#' This is useful for interpreting relative urls with \code{\link{url_relative}}.
#'
#' @param x A node or document.
#' @return A character vector of length 1. Returns \code{NA} if the name is
#' not set.
#' @export
#' @examples
#' catalog <- read_xml("http://www.xmlfiles.com/examples/cd_catalog.xml")
#' xml_url(catalog)
#'
#' x <- read_xml("<foo/>")
#' xml_url(x)
xml_url <- function(x) {
UseMethod("xml_url")
}
#' @export
xml_url.xml_missing <- function(x) {
NA_character_
}
#' @export
xml_url.xml_node <- function(x) {
doc_url(x$doc)
}
#' @export
xml_url.xml_nodeset <- function(x) {
vapply(x, doc_url, character(1))
}
|