Module: TDPXML::XMLParser
- Defined in:
- lib/tdp/xml.rb
Defined Under Namespace
Classes: XArray, XHash, XMLTokenGenerator
Instance Method Summary
collapse
Instance Method Details
#any_node(&b) ⇒ Object
161
162
163
164
165
|
# File 'lib/tdp/xml.rb', line 161
def any_node(&b)
(element(&b) | doctype(&b) | text() | pi() | cdata() |
() | xmldecl() | externalentity() | elementdecl() |
entitydecl() | attlistdecl() | notationdecl()) >> Proc.new{|x| x[2]}
end
|
#attlistdecl(decl = String) ⇒ Object
149
150
151
152
153
|
# File 'lib/tdp/xml.rb', line 149
def attlistdecl(decl=String)
token(XArray[:attlistdecl]) >> Proc.new{|x|
REXML::AttlistDecl.new(x[0][1..-1])
}
end
|
#cdata(match = String) ⇒ Object
93
94
95
96
97
|
# File 'lib/tdp/xml.rb', line 93
def cdata(match=String)
token(XArray[:cdata, match]) >> Proc.new{|x|
REXML::CData.new(x[0][1])
}
end
|
99
100
101
102
103
|
# File 'lib/tdp/xml.rb', line 99
def (match=String)
token(XArray[:comment, match]) >> Proc.new{|x|
REXML::Comment.new(x[0][1])
}
end
|
#doctype(name = String, &inner) ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/tdp/xml.rb', line 119
def doctype(name=String, &inner)
if (inner)
crule = inner.call()|empty()
else
crule = empty()
end
start_doctype(name) - crule - end_doctype() >> Proc.new{|x|
node = REXML::DocType.new(x[0][1..-1])
[node, x[1]]
}
end
|
#dom_constructor(&act) ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/tdp/xml.rb', line 167
def dom_constructor(&act)
Proc.new{|x|
node = x[0][0]
child = x[0][1]
if (child.is_a?(Array))
child.each{|c| node.add(c) }
else
node.add(child)
end
if (act)
act[node]
else
node
end
}
end
|
#element(elem = String, &inner) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/tdp/xml.rb', line 65
def element(elem=String, &inner)
if inner
crule = inner.call()|empty()
else
crule = empty()
end
start_element(elem) - crule - end_element(elem) >> Proc.new{|x|
name = x[0][1]
attrs = x[0][2]
node = REXML::Element.new()
node.name = name
node.attributes.merge!(attrs)
[node,x[1]]
}
end
|
#elementdecl(elem = String) ⇒ Object
137
138
139
140
141
|
# File 'lib/tdp/xml.rb', line 137
def elementdecl(elem=String)
token(XArray[:elementdecl, elem]) >> Proc.new{|x|
REXML::ElementDecl.new(x[0][1])
}
end
|
#end_doctype ⇒ Object
115
116
117
|
# File 'lib/tdp/xml.rb', line 115
def end_doctype()
token(XArray[:end_doctype])
end
|
#end_element(name = String) ⇒ Object
61
62
63
|
# File 'lib/tdp/xml.rb', line 61
def end_element(name=String)
token(XArray[:end_element, name])
end
|
#entitydecl(entity = String) ⇒ Object
143
144
145
146
147
|
# File 'lib/tdp/xml.rb', line 143
def entitydecl(entity=String)
token(XArray[:entitydecl, elem]) >> Proc.new{|x|
REXML::Entity.new(x[0])
}
end
|
#externalentity(entity = String) ⇒ Object
131
132
133
134
135
|
# File 'lib/tdp/xml.rb', line 131
def externalentity(entity=String)
token(XArray[:externalentity, entity]) >> Proc.new{|x|
REXML::ExternalEntity.new(x[0][1])
}
end
|
#notationdecl(decl = String) ⇒ Object
155
156
157
158
159
|
# File 'lib/tdp/xml.rb', line 155
def notationdecl(decl=String)
token(XArray[:notationdecl]) >> Proc.new{|x|
REXML::NotationDecl.new(*x[0][1..-1])
}
end
|
#pi ⇒ Object
87
88
89
90
91
|
# File 'lib/tdp/xml.rb', line 87
def pi()
token(XArray[:processing_instruction, String, String]) >> Proc.new{|x|
REXML::Instruction.new(x[0][1],x[0][2])
}
end
|
#start_doctype(name = String) ⇒ Object
111
112
113
|
# File 'lib/tdp/xml.rb', line 111
def start_doctype(name=String)
token(XArray[:start_doctype, name])
end
|
#start_element(name = String) ⇒ Object
57
58
59
|
# File 'lib/tdp/xml.rb', line 57
def start_element(name=String)
token(XArray[:start_element, name, Hash])
end
|
#text(match = String) ⇒ Object
81
82
83
84
85
|
# File 'lib/tdp/xml.rb', line 81
def text(match=String)
token(XArray[:text, match]) >> Proc.new{|x|
REXML::Text.new(x[0][1])
}
end
|
#xmldecl ⇒ Object
105
106
107
108
109
|
# File 'lib/tdp/xml.rb', line 105
def xmldecl()
token(XArray[:xmldecl]) >> Proc.new{|x|
REXML::XMLDecl.new(x[0][1],x[0][2], x[0][3])
}
end
|