libxml-ruby 1.1.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → HISTORY} +35 -0
- data/LICENSE +1 -0
- data/MANIFEST +165 -0
- data/{README → README.rdoc} +2 -2
- data/Rakefile +47 -147
- data/ext/libxml/libxml.c +17 -1
- data/ext/libxml/ruby_libxml.h +9 -1
- data/ext/libxml/ruby_xml_attr.c +3 -3
- data/ext/libxml/ruby_xml_attr_decl.c +32 -32
- data/ext/libxml/ruby_xml_attributes.c +1 -1
- data/ext/libxml/ruby_xml_cbg.c +1 -2
- data/ext/libxml/ruby_xml_document.c +26 -4
- data/ext/libxml/ruby_xml_dtd.c +3 -3
- data/ext/libxml/ruby_xml_encoding.c +92 -5
- data/ext/libxml/ruby_xml_encoding.h +4 -0
- data/ext/libxml/ruby_xml_namespace.c +2 -2
- data/ext/libxml/ruby_xml_node.c +14 -14
- data/ext/libxml/ruby_xml_parser_context.c +8 -8
- data/ext/libxml/ruby_xml_reader.c +98 -43
- data/ext/libxml/ruby_xml_sax2_handler.c +13 -1
- data/ext/libxml/ruby_xml_sax_parser.c +4 -5
- data/ext/libxml/ruby_xml_version.h +5 -5
- data/ext/libxml/ruby_xml_xpath_context.c +9 -6
- data/ext/libxml/ruby_xml_xpath_object.c +1 -1
- data/ext/vc/libxml_ruby.sln +4 -4
- data/lib/libxml.rb +29 -29
- data/lib/libxml/attr.rb +112 -110
- data/lib/libxml/attr_decl.rb +2 -0
- data/lib/libxml/attributes.rb +13 -11
- data/lib/libxml/document.rb +192 -190
- data/lib/libxml/error.rb +89 -87
- data/lib/libxml/hpricot.rb +77 -75
- data/lib/libxml/html_parser.rb +96 -94
- data/lib/libxml/namespace.rb +61 -59
- data/lib/libxml/namespaces.rb +37 -35
- data/lib/libxml/node.rb +398 -384
- data/lib/libxml/ns.rb +21 -19
- data/lib/libxml/parser.rb +366 -364
- data/lib/libxml/properties.rb +22 -20
- data/lib/libxml/reader.rb +2 -0
- data/lib/libxml/sax_callbacks.rb +179 -177
- data/lib/libxml/sax_parser.rb +57 -55
- data/lib/libxml/tree.rb +28 -26
- data/lib/libxml/xpath_object.rb +15 -13
- data/lib/xml.rb +16 -14
- data/lib/xml/libxml.rb +10 -8
- data/libxml-ruby.gemspec +50 -0
- data/script/benchmark/depixelate +634 -0
- data/script/benchmark/hamlet.xml +9055 -0
- data/script/benchmark/parsecount +170 -0
- data/script/benchmark/sock_entries.xml +507 -0
- data/script/benchmark/throughput +41 -0
- data/script/test +6 -0
- data/test/etc_doc_to_s.rb +21 -19
- data/test/ets_doc_file.rb +17 -15
- data/test/ets_doc_to_s.rb +23 -21
- data/test/ets_gpx.rb +28 -26
- data/test/ets_node_gc.rb +23 -21
- data/test/ets_tsr.rb +11 -9
- data/test/model/bands.iso-8859-1.xml +5 -0
- data/test/model/bands.utf-8.xml +5 -0
- data/test/rb-magic-comment.rb +33 -0
- data/test/tc_attr.rb +181 -170
- data/test/tc_attr_decl.rb +3 -1
- data/test/tc_attributes.rb +134 -132
- data/test/tc_deprecated_require.rb +13 -11
- data/test/tc_document.rb +119 -113
- data/test/tc_document_write.rb +186 -117
- data/test/tc_dtd.rb +125 -123
- data/test/tc_error.rb +3 -1
- data/test/tc_html_parser.rb +139 -137
- data/test/tc_namespace.rb +61 -58
- data/test/tc_namespaces.rb +176 -173
- data/test/tc_node.rb +257 -180
- data/test/tc_node_cdata.rb +51 -49
- data/test/tc_node_comment.rb +33 -30
- data/test/tc_node_copy.rb +42 -40
- data/test/tc_node_edit.rb +159 -157
- data/test/tc_node_text.rb +71 -69
- data/test/tc_node_write.rb +41 -16
- data/test/tc_node_xlink.rb +29 -26
- data/test/tc_parser.rb +335 -329
- data/test/tc_parser_context.rb +188 -185
- data/test/tc_properties.rb +39 -36
- data/test/tc_reader.rb +297 -283
- data/test/tc_relaxng.rb +54 -51
- data/test/tc_sax_parser.rb +275 -273
- data/test/tc_schema.rb +53 -51
- data/test/tc_traversal.rb +222 -220
- data/test/tc_xinclude.rb +21 -19
- data/test/tc_xml.rb +3 -1
- data/test/tc_xpath.rb +195 -193
- data/test/tc_xpath_context.rb +80 -78
- data/test/tc_xpath_expression.rb +38 -35
- data/test/tc_xpointer.rb +74 -72
- data/test/test_helper.rb +14 -0
- data/test/test_suite.rb +39 -33
- metadata +65 -105
- data/doc/css/normal.css +0 -182
- data/doc/img/raze-tiny.png +0 -0
- data/doc/img/red-cube.jpg +0 -0
- data/doc/img/xml-ruby.png +0 -0
- data/doc/index.xml +0 -43
- data/doc/install.xml +0 -77
- data/doc/layout.rhtml +0 -38
- data/doc/layout.xsl +0 -67
- data/doc/license.xml +0 -32
- data/doc/log/changelog.xml +0 -1324
- data/doc/log/changelog.xsl +0 -42
- data/ext/libxml/Makefile +0 -156
- data/ext/libxml/extconf.h +0 -5
- data/ext/libxml/libxml-ruby.so.a +0 -0
- data/ext/libxml/libxml.o +0 -0
- data/ext/libxml/libxml_ruby.so +0 -0
- data/ext/libxml/mkmf.log +0 -129
- data/ext/libxml/ruby_xml.o +0 -0
- data/ext/libxml/ruby_xml_attr.o +0 -0
- data/ext/libxml/ruby_xml_attr_decl.o +0 -0
- data/ext/libxml/ruby_xml_attributes.o +0 -0
- data/ext/libxml/ruby_xml_cbg.o +0 -0
- data/ext/libxml/ruby_xml_document.o +0 -0
- data/ext/libxml/ruby_xml_dtd.o +0 -0
- data/ext/libxml/ruby_xml_encoding.o +0 -0
- data/ext/libxml/ruby_xml_error.o +0 -0
- data/ext/libxml/ruby_xml_html_parser.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
- data/ext/libxml/ruby_xml_input_cbg.o +0 -0
- data/ext/libxml/ruby_xml_io.o +0 -0
- data/ext/libxml/ruby_xml_namespace.o +0 -0
- data/ext/libxml/ruby_xml_namespaces.o +0 -0
- data/ext/libxml/ruby_xml_node.o +0 -0
- data/ext/libxml/ruby_xml_parser.o +0 -0
- data/ext/libxml/ruby_xml_parser_context.o +0 -0
- data/ext/libxml/ruby_xml_parser_options.o +0 -0
- data/ext/libxml/ruby_xml_reader.o +0 -0
- data/ext/libxml/ruby_xml_relaxng.o +0 -0
- data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
- data/ext/libxml/ruby_xml_sax_parser.o +0 -0
- data/ext/libxml/ruby_xml_schema.o +0 -0
- data/ext/libxml/ruby_xml_xinclude.o +0 -0
- data/ext/libxml/ruby_xml_xpath.o +0 -0
- data/ext/libxml/ruby_xml_xpath_context.o +0 -0
- data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
- data/ext/libxml/ruby_xml_xpath_object.o +0 -0
- data/ext/libxml/ruby_xml_xpointer.o +0 -0
data/lib/libxml/namespace.rb
CHANGED
@@ -1,60 +1,62 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
elsif
|
18
|
-
1
|
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
|
-
self.href
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module LibXML
|
4
|
+
module XML
|
5
|
+
class Namespace
|
6
|
+
include Comparable
|
7
|
+
include Enumerable
|
8
|
+
|
9
|
+
# call-seq:
|
10
|
+
# namespace1 <=> namespace2
|
11
|
+
#
|
12
|
+
# Compares two namespace objects. Namespace objects are
|
13
|
+
# considered equal if their prefixes and hrefs are the same.
|
14
|
+
def <=>(other)
|
15
|
+
if self.prefix.nil? and other.prefix.nil?
|
16
|
+
self.href <=> other.href
|
17
|
+
elsif self.prefix.nil?
|
18
|
+
-1
|
19
|
+
elsif other.prefix.nil?
|
20
|
+
1
|
21
|
+
else
|
22
|
+
self.prefix <=> other.prefix
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# call-seq:
|
27
|
+
# namespace.each {|ns| .. }
|
28
|
+
#
|
29
|
+
# libxml stores namespaces in memory as a linked list.
|
30
|
+
# Use the each method to iterate over the list. Note
|
31
|
+
# the first namespace in the loop is the current namespace.
|
32
|
+
#
|
33
|
+
# Usage:
|
34
|
+
# namespace.each do |ns|
|
35
|
+
# ..
|
36
|
+
# end
|
37
|
+
def each
|
38
|
+
ns = self
|
39
|
+
|
40
|
+
while ns
|
41
|
+
yield ns
|
42
|
+
ns = ns.next
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# call-seq:
|
47
|
+
# namespace.to_s -> "string"
|
48
|
+
#
|
49
|
+
# Returns the string represenation of a namespace.
|
50
|
+
#
|
51
|
+
# Usage:
|
52
|
+
# namespace.to_s
|
53
|
+
def to_s
|
54
|
+
if self.prefix
|
55
|
+
"#{self.prefix}:#{self.href}"
|
56
|
+
else
|
57
|
+
self.href
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
60
62
|
end
|
data/lib/libxml/namespaces.rb
CHANGED
@@ -1,36 +1,38 @@
|
|
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
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module LibXML
|
4
|
+
module XML
|
5
|
+
class Namespaces
|
6
|
+
# call-seq:
|
7
|
+
# namespace.default -> XML::Namespace
|
8
|
+
#
|
9
|
+
# Returns the default namespace for this node or nil.
|
10
|
+
#
|
11
|
+
# Usage:
|
12
|
+
# doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
13
|
+
# ns = doc.root.namespaces.default_namespace
|
14
|
+
# assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
|
15
|
+
def default
|
16
|
+
find_by_prefix(nil)
|
17
|
+
end
|
18
|
+
|
19
|
+
# call-seq:
|
20
|
+
# namespace.default_prefix = "string"
|
21
|
+
#
|
22
|
+
# Assigns a name (prefix) to the default namespace.
|
23
|
+
# This makes it much easier to perform XML::XPath
|
24
|
+
# searches.
|
25
|
+
#
|
26
|
+
# Usage:
|
27
|
+
# doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
|
28
|
+
# doc.root.namespaces.default_prefix = 'soap'
|
29
|
+
# node = doc.root.find_first('soap:Envelope')
|
30
|
+
def default_prefix=(prefix)
|
31
|
+
# Find default prefix
|
32
|
+
ns = find_by_prefix(nil)
|
33
|
+
raise(ArgumentError, "No default namespace was found") unless ns
|
34
|
+
Namespace.new(self.node, prefix, ns.href)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
36
38
|
end
|
data/lib/libxml/node.rb
CHANGED
@@ -1,385 +1,399 @@
|
|
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
|
-
context.
|
59
|
-
context
|
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
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
when
|
158
|
-
'
|
159
|
-
when
|
160
|
-
'
|
161
|
-
|
162
|
-
|
163
|
-
when
|
164
|
-
'
|
165
|
-
|
166
|
-
|
167
|
-
when
|
168
|
-
'
|
169
|
-
when
|
170
|
-
'
|
171
|
-
when
|
172
|
-
'
|
173
|
-
when
|
174
|
-
'
|
175
|
-
when
|
176
|
-
'
|
177
|
-
when
|
178
|
-
'
|
179
|
-
when
|
180
|
-
'
|
181
|
-
when
|
182
|
-
'
|
183
|
-
when
|
184
|
-
'
|
185
|
-
when
|
186
|
-
'
|
187
|
-
when
|
188
|
-
'
|
189
|
-
when
|
190
|
-
'
|
191
|
-
when
|
192
|
-
'
|
193
|
-
when
|
194
|
-
'
|
195
|
-
when
|
196
|
-
'
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'stringio'
|
4
|
+
|
5
|
+
module LibXML
|
6
|
+
module XML
|
7
|
+
class Node
|
8
|
+
# Determines whether this node has attributes
|
9
|
+
def attributes?
|
10
|
+
attributes.length > 0
|
11
|
+
end
|
12
|
+
|
13
|
+
# Create a shallow copy of the node. To create
|
14
|
+
# a deep copy call Node#copy(true)
|
15
|
+
def clone
|
16
|
+
copy(false)
|
17
|
+
end
|
18
|
+
|
19
|
+
# call-seq:
|
20
|
+
# node.inner_xml -> "string"
|
21
|
+
# node.inner_xml(:indent => true, :encoding => 'UTF-8', :level => 0) -> "string"
|
22
|
+
#
|
23
|
+
# Converts a node's children, to a string representation. To include
|
24
|
+
# the node, use XML::Node#to_s. For more information about
|
25
|
+
# the supported options, see XML::Node#to_s.
|
26
|
+
def inner_xml(options = Hash.new)
|
27
|
+
io = nil
|
28
|
+
self.each do |node|
|
29
|
+
xml = node.to_s(options)
|
30
|
+
# Create the string IO here since we now know the encoding
|
31
|
+
io = create_string_io(xml) unless io
|
32
|
+
io << xml
|
33
|
+
end
|
34
|
+
|
35
|
+
io.string
|
36
|
+
end
|
37
|
+
|
38
|
+
# :call-seq:
|
39
|
+
# node.dup -> XML::Node
|
40
|
+
#
|
41
|
+
# Create a shallow copy of the node. To create
|
42
|
+
# a deep copy call Node#copy(true)
|
43
|
+
def dup
|
44
|
+
copy(false)
|
45
|
+
end
|
46
|
+
|
47
|
+
# call-seq:
|
48
|
+
# node.context(namespaces=nil) -> XPath::Context
|
49
|
+
#
|
50
|
+
# Returns a new XML::XPathContext for the current node.
|
51
|
+
#
|
52
|
+
# Namespaces is an optional array of XML::NS objects
|
53
|
+
def context(nslist = nil)
|
54
|
+
if not self.doc
|
55
|
+
raise(TypeError, "A node must belong to a document before a xpath context can be created")
|
56
|
+
end
|
57
|
+
|
58
|
+
context = XPath::Context.new(self)
|
59
|
+
context.node = self
|
60
|
+
context.register_namespaces_from_node(self)
|
61
|
+
context.register_namespaces_from_node(self.doc.root)
|
62
|
+
context.register_namespaces(nslist) if nslist
|
63
|
+
context
|
64
|
+
end
|
65
|
+
|
66
|
+
# call-seq:
|
67
|
+
# node.find(namespaces=nil) -> XPath::XPathObject
|
68
|
+
#
|
69
|
+
# Return nodes matching the specified xpath expression.
|
70
|
+
# For more information, please refer to the documentation
|
71
|
+
# for XML::Document#find.
|
72
|
+
#
|
73
|
+
# Namespaces is an optional array of XML::NS objects
|
74
|
+
def find(xpath, nslist = nil)
|
75
|
+
self.context(nslist).find(xpath)
|
76
|
+
end
|
77
|
+
|
78
|
+
# call-seq:
|
79
|
+
# node.find_first(namespaces=nil) -> XML::Node
|
80
|
+
#
|
81
|
+
# Return the first node matching the specified xpath expression.
|
82
|
+
# For more information, please refer to the documentation
|
83
|
+
# for the #find method.
|
84
|
+
def find_first(xpath, nslist = nil)
|
85
|
+
find(xpath, nslist).first
|
86
|
+
end
|
87
|
+
|
88
|
+
# call-seq:
|
89
|
+
# node.namespacess -> XML::Namespaces
|
90
|
+
#
|
91
|
+
# Returns this node's XML::Namespaces object,
|
92
|
+
# which is used to access the namespaces
|
93
|
+
# associated with this node.
|
94
|
+
def namespaces
|
95
|
+
@namespaces ||= XML::Namespaces.new(self)
|
96
|
+
end
|
97
|
+
|
98
|
+
# ------- Traversal ----------------
|
99
|
+
# Iterates over this node's attributes.
|
100
|
+
#
|
101
|
+
# doc = XML::Document.new('model/books.xml')
|
102
|
+
# doc.root.each_attr {|attr| puts attr}
|
103
|
+
def each_attr
|
104
|
+
attributes.each do |attr|
|
105
|
+
yield(attr)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
# Iterates over this node's child elements (nodes
|
110
|
+
# that have a node_type == ELEMENT_NODE).
|
111
|
+
#
|
112
|
+
# doc = XML::Document.new('model/books.xml')
|
113
|
+
# doc.root.each_element {|element| puts element}
|
114
|
+
def each_element
|
115
|
+
each do |node|
|
116
|
+
yield(node) if node.node_type == ELEMENT_NODE
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# Determines whether this node has a parent node
|
121
|
+
def parent?
|
122
|
+
not parent.nil?
|
123
|
+
end
|
124
|
+
|
125
|
+
# Determines whether this node has a first node
|
126
|
+
def first?
|
127
|
+
not first.nil?
|
128
|
+
end
|
129
|
+
|
130
|
+
# Returns this node's children as an array.
|
131
|
+
def children
|
132
|
+
entries
|
133
|
+
end
|
134
|
+
|
135
|
+
# Determines whether this node has a next node
|
136
|
+
def next?
|
137
|
+
not self.next.nil?
|
138
|
+
end
|
139
|
+
|
140
|
+
# Determines whether this node has a previous node
|
141
|
+
def prev?
|
142
|
+
not prev.nil?
|
143
|
+
end
|
144
|
+
|
145
|
+
# Determines whether this node has a last node
|
146
|
+
def last?
|
147
|
+
not last.nil?
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
# ------- Node Types ----------------
|
152
|
+
|
153
|
+
# Returns this node's type name
|
154
|
+
def node_type_name
|
155
|
+
case node_type
|
156
|
+
# Most common choices first
|
157
|
+
when ATTRIBUTE_NODE
|
158
|
+
'attribute'
|
159
|
+
when DOCUMENT_NODE
|
160
|
+
'document_xml'
|
161
|
+
when ELEMENT_NODE
|
162
|
+
'element'
|
163
|
+
when TEXT_NODE
|
164
|
+
'text'
|
165
|
+
|
166
|
+
# Now the rest
|
167
|
+
when ATTRIBUTE_DECL
|
168
|
+
'attribute_decl'
|
169
|
+
when CDATA_SECTION_NODE
|
170
|
+
'cdata'
|
171
|
+
when COMMENT_NODE
|
172
|
+
'comment'
|
173
|
+
when DOCB_DOCUMENT_NODE
|
174
|
+
'document_docbook'
|
175
|
+
when DOCUMENT_FRAG_NODE
|
176
|
+
'fragment'
|
177
|
+
when DOCUMENT_TYPE_NODE
|
178
|
+
'doctype'
|
179
|
+
when DTD_NODE
|
180
|
+
'dtd'
|
181
|
+
when ELEMENT_DECL
|
182
|
+
'elem_decl'
|
183
|
+
when ENTITY_DECL
|
184
|
+
'entity_decl'
|
185
|
+
when ENTITY_NODE
|
186
|
+
'entity'
|
187
|
+
when ENTITY_REF_NODE
|
188
|
+
'entity_ref'
|
189
|
+
when HTML_DOCUMENT_NODE
|
190
|
+
'document_html'
|
191
|
+
when NAMESPACE_DECL
|
192
|
+
'namespace'
|
193
|
+
when NOTATION_NODE
|
194
|
+
'notation'
|
195
|
+
when PI_NODE
|
196
|
+
'pi'
|
197
|
+
when XINCLUDE_START
|
198
|
+
'xinclude_start'
|
199
|
+
when XINCLUDE_END
|
200
|
+
'xinclude_end'
|
201
|
+
else
|
202
|
+
raise(UnknownType, "Unknown node type: %n", node.node_type);
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
# Specifies if this is an attribute node
|
207
|
+
def attribute?
|
208
|
+
node_type == ATTRIBUTE_NODE
|
209
|
+
end
|
210
|
+
|
211
|
+
# Specifies if this is an attribute declaration node
|
212
|
+
def attribute_decl?
|
213
|
+
node_type == ATTRIBUTE_DECL
|
214
|
+
end
|
215
|
+
|
216
|
+
# Specifies if this is an CDATA node
|
217
|
+
def cdata?
|
218
|
+
node_type == CDATA_SECTION_NODE
|
219
|
+
end
|
220
|
+
|
221
|
+
# Specifies if this is an comment node
|
222
|
+
def comment?
|
223
|
+
node_type == COMMENT_NODE
|
224
|
+
end
|
225
|
+
|
226
|
+
# Specifies if this is an docbook node
|
227
|
+
def docbook_doc?
|
228
|
+
node_type == DOCB_DOCUMENT_NODE
|
229
|
+
end
|
230
|
+
|
231
|
+
# Specifies if this is an docbook node
|
232
|
+
def doctype?
|
233
|
+
node_type == DOCUMENT_TYPE_NODE
|
234
|
+
end
|
235
|
+
|
236
|
+
# Specifies if this is an DOCTYPE node
|
237
|
+
def document?
|
238
|
+
node_type == DOCUMENT_NODE
|
239
|
+
end
|
240
|
+
|
241
|
+
# Specifies if this is an DTD node
|
242
|
+
def dtd?
|
243
|
+
node_type == DTD_NODE
|
244
|
+
end
|
245
|
+
|
246
|
+
# Specifies if this is an element node
|
247
|
+
def element?
|
248
|
+
node_type == ELEMENT_NODE
|
249
|
+
end
|
250
|
+
|
251
|
+
# Specifies if this is an entity node
|
252
|
+
def entity?
|
253
|
+
node_type == ENTITY_NODE
|
254
|
+
end
|
255
|
+
|
256
|
+
# Specifies if this is an element declaration node
|
257
|
+
def element_decl?
|
258
|
+
node_type == ELEMENT_DECL
|
259
|
+
end
|
260
|
+
|
261
|
+
# Specifies if this is an entity reference node
|
262
|
+
def entity_ref?
|
263
|
+
node_type == ENTITY_REF_NODE
|
264
|
+
end
|
265
|
+
|
266
|
+
# Specifies if this is a fragment node
|
267
|
+
def fragment?
|
268
|
+
node_type == DOCUMENT_FRAG_NODE
|
269
|
+
end
|
270
|
+
|
271
|
+
# Specifies if this is a html document node
|
272
|
+
def html_doc?
|
273
|
+
node_type == HTML_DOCUMENT_NODE
|
274
|
+
end
|
275
|
+
|
276
|
+
# Specifies if this is a namespace node (not if it
|
277
|
+
# has a namepsace)
|
278
|
+
def namespace?
|
279
|
+
node_type == NAMESPACE_DECL
|
280
|
+
end
|
281
|
+
|
282
|
+
# Specifies if this is a notation node
|
283
|
+
def notation?
|
284
|
+
node_type == NOTATION_NODE
|
285
|
+
end
|
286
|
+
|
287
|
+
# Specifies if this is a processiong instruction node
|
288
|
+
def pi?
|
289
|
+
node_type == PI_NODE
|
290
|
+
end
|
291
|
+
|
292
|
+
# Specifies if this is a text node
|
293
|
+
def text?
|
294
|
+
node_type == TEXT_NODE
|
295
|
+
end
|
296
|
+
|
297
|
+
# Specifies if this is an xinclude end node
|
298
|
+
def xinclude_end?
|
299
|
+
node_type == XINCLUDE_END
|
300
|
+
end
|
301
|
+
|
302
|
+
# Specifies if this is an xinclude start node
|
303
|
+
def xinclude_start?
|
304
|
+
node_type == XINCLUDE_START
|
305
|
+
end
|
306
|
+
|
307
|
+
alias :child? :first?
|
308
|
+
alias :children? :first?
|
309
|
+
alias :child :first
|
310
|
+
alias :each_child :each
|
311
|
+
|
312
|
+
# --- Deprecated Output ---
|
313
|
+
# :stopdoc:
|
314
|
+
def dump
|
315
|
+
warn('Node#dump is deprecated. Use Node#to_s instead.')
|
316
|
+
self.to_s
|
317
|
+
end
|
318
|
+
|
319
|
+
# --- Deprecated DOM Manipulation ---
|
320
|
+
def child_add(node)
|
321
|
+
warn('Node#child_add is deprecated. Use Node#<< instead.')
|
322
|
+
self << node
|
323
|
+
end
|
324
|
+
|
325
|
+
def child=(node)
|
326
|
+
warn('Node#child= is deprecated. Use Node#<< instead.')
|
327
|
+
self << node
|
328
|
+
end
|
329
|
+
|
330
|
+
# --- Deprecated Namespaces ---
|
331
|
+
def namespace
|
332
|
+
warn('Node#namespace is deprecated. Use Node#namespaces instead.')
|
333
|
+
self.namespaces.entries
|
334
|
+
end
|
335
|
+
|
336
|
+
def namespace=(value)
|
337
|
+
warn('Node#namespace= is deprecated. Use Node#namespaces.namespace= instead.')
|
338
|
+
self.namespaces.namespace = value
|
339
|
+
end
|
340
|
+
|
341
|
+
def namespace_node
|
342
|
+
warn('Node#namespace_node is deprecated. Use Node#namespaces.namespace instead.')
|
343
|
+
self.namespaces.namespace
|
344
|
+
end
|
345
|
+
|
346
|
+
def ns
|
347
|
+
warn('Node#ns is deprecated. Use Node#namespaces.namespace instead.')
|
348
|
+
self.namespaces.namespace
|
349
|
+
end
|
350
|
+
|
351
|
+
def ns?
|
352
|
+
warn('Node#ns? is deprecated. Use !Node#namespaces.namespace.nil? instead.')
|
353
|
+
!self.namespaces.namespace.nil?
|
354
|
+
end
|
355
|
+
|
356
|
+
def ns_def
|
357
|
+
warn('Node#ns_def is deprecated. Use Node#namespaces.definitions instead.')
|
358
|
+
self.namespaces.definitions
|
359
|
+
end
|
360
|
+
|
361
|
+
def ns_def?
|
362
|
+
warn('Node#ns_def? is deprecated. Use !Node#namespaces.definitions.nil? instead.')
|
363
|
+
!self.namespaces.definitions.nil?
|
364
|
+
end
|
365
|
+
|
366
|
+
def base
|
367
|
+
warn('Node#base is deprecated. Use Node#base_uri.')
|
368
|
+
self.base_uri
|
369
|
+
end
|
370
|
+
|
371
|
+
def base=(value)
|
372
|
+
warn('Node#base= is deprecated. Use Node#base_uri=.')
|
373
|
+
self.base_uri = value
|
374
|
+
end
|
375
|
+
|
376
|
+
def search_ns(prefix)
|
377
|
+
warn('Node#search_ns is deprecated. Use Node#namespaces.find_by_prefix instead.')
|
378
|
+
self.namespaces.find_by_prefix(prefix)
|
379
|
+
end
|
380
|
+
|
381
|
+
def search_href(href)
|
382
|
+
warn('Node#search_href is deprecated. Use Node#namespaces.find_by_href instead.')
|
383
|
+
self.namespaces.find_by_href(href)
|
384
|
+
end
|
385
|
+
|
386
|
+
# :startdoc:
|
387
|
+
|
388
|
+
private
|
389
|
+
|
390
|
+
def create_string_io(xml)
|
391
|
+
result = StringIO.new("")
|
392
|
+
if defined?(::Encoding)
|
393
|
+
result.set_encoding(xml.encoding)
|
394
|
+
end
|
395
|
+
result
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
385
399
|
end
|