File: xml_schema.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 (21 lines) | stat: -rw-r--r-- 693 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
#' 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"))
  doc_validate(x$doc, schema$doc)
}