validXML {XiMpLe} | R Documentation |
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 signature 'XiMpLe.XML'
validXML(
obj,
validity = XMLValidity(),
parent = NULL,
children = TRUE,
attributes = TRUE,
warn = FALSE,
section = parent,
caseSens = TRUE
)
Arguments
obj |
An object of class |
validity |
An object of class |
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.
Value
Returns TRUE
if tests pass,
and depending on the setting of warn
either FALSE
or
an error if a test fails.
Note
: If no parent
is specified, obj
will be checked recursively.
See Also
validXML
,
XMLValidity
,
XiMpLe_doc
, and
XiMpLe_node
Examples
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
)