R/misc.R

Defines functions BatchXmlText

Documented in BatchXmlText

##' Batch retrieve xml context
##'
##' Retrieve xml context by xPath.
##' @title Retrieve xml context
##' @param xmlObj xml object.
##' @param xPrefix xPath prefix.
##' @param xItems Node names.
##' @return A named list.
##' @author Yulong Niu \email{niuylscu@@gmail.com}
##' @importFrom xml2 xml_find_all xml_text
##' @importFrom magrittr %>%
##' @keywords internal
##'
##'
BatchXmlText <- function(xmlObj, xPrefix, xItems) {

  xPathBatch <- paste0(xPrefix, xItems)

  batchText <- lapply(xPathBatch, function(eachXPath) {
    xmlObj %>%
      xml_find_all(eachXPath) %>%
      xml_text
  })

  names(batchText) <- xItems

  return(batchText)
}
YulongNiu/NCBI_API documentation built on Nov. 22, 2021, 3:25 a.m.