Learn R Programming

XiMpLe (version 0.11-3)

validXML: Validate S4 objects of XiMpLe XML classes

Description

Checks whether objects of class XiMpLe_doc or XiMpLe_node have valid child nodes.

Usage

validXML(
  obj,
  validity = XMLValidity(),
  parent = NULL,
  children = TRUE,
  attributes = TRUE,
  warn = FALSE,
  section = parent,
  caseSens = TRUE
)

# S4 method for XiMpLe.XML validXML( obj, validity = XMLValidity(), parent = NULL, children = TRUE, attributes = TRUE, warn = FALSE, section = parent, caseSens = TRUE )

Value

Returns TRUE if tests pass, and depending on the setting of warn either FALSE or an error if a test fails.

Arguments

obj

An object of class XiMpLe_doc or XiMpLe_node. If parent=NULL, this object will be checked for validity, including its child nodes. If parent is either a character string or another XiMpLe node, it will be checked whether obj is a valid child node of parent.

validity

An object of class XiMpLe.validity, see XMLValidity.

parent

Either a character string (name of the parent node) or a XiMpLe node, whose name will be used as name of the parent node.

children

Logical, whether child node names should be checked for validity.

attributes

Logical, whether attributes should be checked for validity.

warn

Logical, whether invalid objects should cause a warning or stop with an error.

section

Either a character string (name of the section) or a XiMpLe node, whose name will be used as name of the XML section this check refers to. This is only relevant for warnings and error messages, in case you want to use something different than the actual parent node name.

caseSens

Logical, whether checks should be case sensitive or not.

Details

XiMpLe can't handle DOM specifications yet, but this method can be used to construct validation schemes.

See Also

validXML, XMLValidity, XiMpLe_doc, and XiMpLe_node

Examples

Run this code
HTMLish <- XMLValidity(
   children=list(
     body=c("a", "p", "ol", "ul", "strong"),
     head=c("title"),
     html=c("head", "body"),
     li=c("a", "br", "strong"),
     ol=c("li"),
     p=c("a", "br", "ol", "ul", "strong"),
     ul=c("li")
   ),
   attrs=list(
     a=c("href", "name"),
     p=c("align")
   ),
   allChildren=c("!--"),
   allAttrs=c("id", "class"),
   empty=c("br")
)
# make XML object
validChildNodes <- XMLNode("html",
  XMLNode("head",
    XMLNode("!--", "comment always passes"),
    XMLNode("title", "test")
  ),
  XMLNode("body",
    XMLNode("p",
      XMLNode("a", "my link"),
      XMLNode("br"),
      "text goes on"
    )
  )
)
invalidChildNodes <- XMLNode("html",
  XMLNode("head",
    XMLNode("title", 
      XMLNode("body", "test")
    )
  )
)

# do validity checks
# the first should pass
validXML(
  validChildNodes,
  validity=HTMLish
)

# now this one should cause a warning and return FALSE
validXML(
  invalidChildNodes,
  validity=HTMLish,
  warn=TRUE
)

Run the code above in your browser using DataLab