libxml-ruby 5.0.4 → 5.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/HISTORY +10 -6
- data/README.rdoc +1 -1
- data/ext/libxml/extconf.rb +5 -0
- data/ext/libxml/ruby_xml.c +556 -556
- data/ext/libxml/ruby_xml_attributes.h +17 -17
- data/ext/libxml/ruby_xml_document.c +1129 -1129
- data/ext/libxml/ruby_xml_dtd.c +257 -257
- data/ext/libxml/ruby_xml_encoding.c +250 -250
- data/ext/libxml/ruby_xml_error.c +1003 -1003
- data/ext/libxml/ruby_xml_error.h +14 -14
- data/ext/libxml/ruby_xml_html_parser_context.c +351 -351
- data/ext/libxml/ruby_xml_input_cbg.c +188 -188
- data/ext/libxml/ruby_xml_namespace.c +151 -151
- data/ext/libxml/ruby_xml_parser.h +10 -10
- data/ext/libxml/ruby_xml_parser_context.c +1009 -1009
- data/ext/libxml/ruby_xml_parser_options.c +74 -74
- data/ext/libxml/ruby_xml_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_sax2_handler.c +326 -326
- data/ext/libxml/ruby_xml_sax_parser.c +108 -108
- data/ext/libxml/ruby_xml_version.h +9 -9
- data/lib/libxml/attr.rb +122 -122
- data/lib/libxml/attr_decl.rb +80 -80
- data/lib/libxml/attributes.rb +13 -13
- data/lib/libxml/document.rb +194 -194
- data/lib/libxml/error.rb +95 -95
- data/lib/libxml/hpricot.rb +77 -77
- data/lib/libxml/html_parser.rb +96 -96
- data/lib/libxml/namespace.rb +61 -61
- data/lib/libxml/namespaces.rb +37 -37
- data/lib/libxml/node.rb +323 -323
- data/lib/libxml/parser.rb +102 -102
- data/lib/libxml/sax_callbacks.rb +179 -179
- data/lib/libxml/sax_parser.rb +40 -40
- data/lib/libxml/tree.rb +28 -28
- data/lib/libxml.rb +4 -4
- data/lib/xml/libxml.rb +10 -10
- data/lib/xml.rb +13 -13
- data/libxml-ruby.gemspec +50 -49
- data/test/test_document.rb +140 -140
- data/test/test_document_write.rb +142 -142
- data/test/test_dtd.rb +126 -126
- data/test/test_encoding.rb +126 -126
- data/test/test_error.rb +194 -194
- data/test/test_helper.rb +20 -20
- data/test/test_namespace.rb +58 -58
- data/test/test_node.rb +235 -235
- data/test/test_node_write.rb +93 -93
- data/test/test_parser.rb +333 -333
- data/test/test_reader.rb +364 -364
- data/test/test_xml.rb +168 -168
- metadata +5 -4
data/lib/libxml/node.rb
CHANGED
@@ -1,323 +1,323 @@
|
|
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 ? io.string : nil
|
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.doc)
|
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 doctype node
|
232
|
-
def doctype?
|
233
|
-
node_type == DOCUMENT_TYPE_NODE
|
234
|
-
end
|
235
|
-
|
236
|
-
# Specifies if this is an document 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
|
-
private
|
313
|
-
|
314
|
-
def create_string_io(xml)
|
315
|
-
result = StringIO.new("")
|
316
|
-
if defined?(::Encoding)
|
317
|
-
result.set_encoding(xml.encoding)
|
318
|
-
end
|
319
|
-
result
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|
323
|
-
end
|
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 ? io.string : nil
|
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.doc)
|
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 doctype node
|
232
|
+
def doctype?
|
233
|
+
node_type == DOCUMENT_TYPE_NODE
|
234
|
+
end
|
235
|
+
|
236
|
+
# Specifies if this is an document 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
|
+
private
|
313
|
+
|
314
|
+
def create_string_io(xml)
|
315
|
+
result = StringIO.new("")
|
316
|
+
if defined?(::Encoding)
|
317
|
+
result.set_encoding(xml.encoding)
|
318
|
+
end
|
319
|
+
result
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|