R/xml_schema.R

Defines functions xml_validate.xml_document xml_validate

Documented in xml_validate

#' Validate XML schema
#'
#' Validate an XML document against an XML 1.0 schema.
#'
#' @inheritParams xml_name
#' @return TRUE or FALSE
#' @export
#' @param schema an XML document containing the schema
#' @examples # Example from https://msdn.microsoft.com/en-us/library/ms256129(v=vs.110).aspx
#' doc <- read_xml(system.file("extdata/order-doc.xml", package = "xml2"))
#' schema <- read_xml(system.file("extdata/order-schema.xml", package = "xml2"))
#' xml_validate(doc, schema)
xml_validate <- function(x, schema) {
  UseMethod("xml_validate")
}

#' @export
xml_validate.xml_document <- function(x, schema) {
  stopifnot(inherits(schema, "xml_document"))
  .Call(doc_validate, x$doc, schema$doc)
}

Try the xml2 package in your browser

Any scripts or data that you put into this service are public.

xml2 documentation built on July 9, 2023, 6:44 p.m.