validXML: Validate S4 objects of XiMpLe XML classes

Description Usage Arguments Details Value Note See Also Examples

Description

Checks whether objects of class XiMpLe.doc or XiMpLe.node have valid child nodes.

Usage

1
2
3
4
5
6
7
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 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.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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
)

XiMpLe documentation built on Dec. 13, 2017, 1:04 a.m.