File: DTDClasses.R

package info (click to toggle)
r-cran-xml 3.99-0.19-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,688 kB
  • sloc: ansic: 6,659; xml: 2,890; asm: 486; sh: 12; makefile: 2
file content (135 lines) | stat: -rw-r--r-- 2,374 bytes parent folder | download | duplicates (9)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#
# Some methods for the DTD classes, similar in spirit
# to those in XMLClasses
#
#    print()
#
#
#
# XMLSystemEntity
# XMLEntity
# XMLElementDef
# XMLSequenceContent
# XMLOrContent
# XMLElementContent
# XMLAttributeDef
#


print.XMLElementDef <-
function(x, ...)
{
 cat("<!ELEMENT", x$name," ")
 print(x$contents)
 cat(">\n")
 if(length(x$attributes)) {

 cat("<!ATTLIST ", x$name,"\n")
  for(i in x$attributes) {
    cat("\t")
    print(i)
    cat("\n")
  }
  cat(">\n")
 }
}


print.XMLElementContent <-
function(x, ...)
{
 if(names(x$type)[1] == "PCData") {
   cat(" ( #PCDATA ) ")
   return()
 }
 cat("(")
 cat(x$elements)
 cat(")",switch(names(x$ocur)[1],Once="", "One or More"="+","Zero or One"="?","Mult"="*")) 
}


print.XMLOrContent <-
function(x, ...)
{
 n <- length(x$elements)
 cat("( ")
 for(i in 1:n) {
   print(x$elements[[i]])
   if(i < n)
    cat(" | ")
 }
 cat(" )")
}

print.XMLSequenceContent <-
function(x, ...)
{
 cat("( ")
 n <- length(x$elements)
 for(i in 1:n) {
    print(x$elements[[i]])
    if(i < n)
        cat(", ")
 }
 cat(" )")
}


print.XMLAttributeDef <-
function(x, ...)
{
 if(names(x$defaultType)[1] != "Implied")
   dflt <- paste("\"", x$defaultValue,"\"",collapse="",sep="")
 else
  dflt <- ""

 cat(x$name, xmlAttributeType(x), xmlAttributeType(x, TRUE), dflt)
}

xmlAttributeType <-
function(def, defaultType = FALSE)
{

 if(defaultType == FALSE & names(def$type)[1] == "Enumeration") {
   return( paste("(",paste(def$defaultValue,collapse=" | "),")", sep=" ", collapse="") )
 }

 switch(ifelse(defaultType, names(def$defaultType)[1], names(def$type)[1]),
         "Fixed" = "#FIXED",
         "CDATA" = "CDATA",
         "Implied" = "#IMPLIED",
         "Required" = "#REQUIRED",
         "Id" = "#ID",
         "IDRef" = "#IDREF",
         "IDRefs" = "#IDREFS",
         "Entity" = "#ENTITY",
         "Entities" = "ENTITIES",
         "NMToken" = "#NMTOKEN",
         "NMTokens" = "#NMTOKENS",
         "Enumeration" = "",
         "Notation" = "",
         "<BROKEN>"
       )
}


print.XMLEntity <-
function(x, ...)
{
 cat("<!ENTITY %", x$name,paste("\"", x$value,"\"",sep="",collapse=""), ">\n")
}




xmlAttrs.XMLElementDef <-
function(node, ...)
{
 node$attributes
}


if(useS4) {
  setGeneric("xmlAttrs", function(node, ...) standardGeneric("xmlAttrs"))
  setMethod("xmlAttrs", "XMLElementDef", xmlAttrs.XMLElementDef)
}