vcdom 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/lib/vcdom/attr.rb +70 -0
  2. data/lib/vcdom/attr_node_map.rb +30 -0
  3. data/lib/vcdom/attr_ns.rb +38 -0
  4. data/lib/vcdom/character_data.rb +22 -0
  5. data/lib/vcdom/child.rb +53 -0
  6. data/lib/vcdom/document.rb +126 -0
  7. data/lib/vcdom/element.rb +332 -0
  8. data/lib/vcdom/element_ns.rb +44 -0
  9. data/lib/vcdom/node.rb +278 -0
  10. data/lib/vcdom/node_list.rb +32 -0
  11. data/lib/vcdom/parent.rb +126 -0
  12. data/lib/vcdom/text.rb +23 -0
  13. data/lib/vcdom/xml_parser.rb +368 -0
  14. data/lib/vcdom/xml_serializer.rb +55 -0
  15. metadata +48 -81
  16. data/History.txt +0 -4
  17. data/Manifest.txt +0 -34
  18. data/PostInstall.txt +0 -7
  19. data/README.rdoc +0 -51
  20. data/Rakefile +0 -26
  21. data/lib/vcdom/minidom/attr.rb +0 -139
  22. data/lib/vcdom/minidom/attr_ns.rb +0 -47
  23. data/lib/vcdom/minidom/cdata_section.rb +0 -34
  24. data/lib/vcdom/minidom/character_data.rb +0 -263
  25. data/lib/vcdom/minidom/comment.rb +0 -34
  26. data/lib/vcdom/minidom/document.rb +0 -245
  27. data/lib/vcdom/minidom/dom_exception.rb +0 -51
  28. data/lib/vcdom/minidom/dom_implementation.rb +0 -214
  29. data/lib/vcdom/minidom/element.rb +0 -512
  30. data/lib/vcdom/minidom/element_ns.rb +0 -42
  31. data/lib/vcdom/minidom/mini_parser.rb +0 -9
  32. data/lib/vcdom/minidom/mini_serializer.rb +0 -118
  33. data/lib/vcdom/minidom/minidom_standard_error.rb +0 -9
  34. data/lib/vcdom/minidom/mod_child_node.rb +0 -51
  35. data/lib/vcdom/minidom/mod_elements_getter.rb +0 -49
  36. data/lib/vcdom/minidom/mod_namespaceuri_manageable.rb +0 -152
  37. data/lib/vcdom/minidom/mod_parent_node.rb +0 -307
  38. data/lib/vcdom/minidom/named_node_map_attr.rb +0 -277
  39. data/lib/vcdom/minidom/node.rb +0 -178
  40. data/lib/vcdom/minidom/node_list.rb +0 -41
  41. data/lib/vcdom/minidom/text.rb +0 -77
  42. data/lib/vcdom/minidom/xml_reg_exp.rb +0 -39
  43. data/lib/vcdom/minidom.rb +0 -9
  44. data/lib/vcdom.rb +0 -6
  45. data/script/console +0 -10
  46. data/script/destroy +0 -14
  47. data/script/generate +0 -14
  48. data/test/test_helper.rb +0 -3
  49. data/test/test_vcdom.rb +0 -11
@@ -1,512 +0,0 @@
1
- require "vcdom/minidom/node"
2
- require "vcdom/minidom/attr"
3
- require "vcdom/minidom/dom_exception"
4
- require "vcdom/minidom/named_node_map_attr"
5
- require "vcdom/minidom/mod_child_node"
6
- require "vcdom/minidom/mod_parent_node"
7
- require "vcdom/minidom/mod_elements_getter"
8
-
9
- module VCDOM
10
- module MiniDOM
11
- class Element < Node
12
-
13
- include ModChildNode
14
- include ModParentNode
15
- include ModElementsGetter
16
- include Attr::OwnerElementManageable
17
-
18
- def node_type; return Node::ELEMENT_NODE end
19
-
20
- # tagName of type DOMString, readonly
21
- # The name of the element.
22
- # If Node.localName is different from null, this attribute is a qualified name. For example, in:
23
- # <elementExample id="demo">
24
- # ...
25
- # </elementExample> ,
26
- # tagName has the value "elementExample".
27
- # Note that this is case-preserving in XML, as are all of the operations of the DOM.
28
- # The HTML DOM returns the tagName of an HTML element in the canonical uppercase form, regardless of
29
- # the case in the source HTML document.
30
- def tagname; return @tagname end
31
- alias :node_name :tagname
32
-
33
- # Element でオーバーライド
34
- def attributes
35
- return @attributes_wrapper
36
- end
37
- def has_attributes()
38
- if @attributes.length != 0 then
39
- return true
40
- else
41
- return false
42
- end
43
- end
44
-
45
-
46
- # hasAttribute introduced in DOM Level 2
47
- #
48
- # Returns true when an attribute with a given name is specified on this element or has a default value,
49
- # false otherwise.
50
- #
51
- # Parameters
52
- # name of type DOMString
53
- # The name of the attribute to look for.
54
- # Return Value
55
- # boolean
56
- # true if an attribute with the given name is specified on this element or has a default value,
57
- # false otherwise.
58
- # No Exceptions
59
- def has_attribute( name )
60
- if get_index_of_attr( name ) then
61
- return true
62
- else
63
- return false
64
- end
65
- end
66
-
67
- # hasAttributeNS introduced in DOM Level 2
68
- #
69
- # Returns true when an attribute with a given local name and namespace URI is specified on this element or has a default value, false otherwise.
70
- # Per [XML Namespaces], applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.
71
- #
72
- # Parameters
73
- # namespaceURI of type DOMString
74
- # The namespace URI of the attribute to look for.
75
- # localName of type DOMString
76
- # The local name of the attribute to look for.
77
- # Return Value
78
- # boolean
79
- # true if an attribute with the given local name and namespace URI is specified or has a default value on this element, false otherwise.
80
- # Exceptions
81
- # DOMException
82
- # NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language exposed through the Document does not support XML Namespaces (such as [HTML 4.01]).
83
- def has_attribute_ns( namespace_uri, local_name )
84
- if get_index_of_attr_ns( namespace_uri, local_name ) then
85
- return true
86
- else
87
- return false
88
- end
89
- end
90
-
91
- # setAttribute
92
- #
93
- # Adds a new attribute.
94
- # If an attribute with that name is already present in the element, its value is changed to be
95
- # that of the value parameter. This value is a simple string; it is not parsed as it is being set.
96
- # So any markup (such as syntax to be recognized as an entity reference) is treated as literal text,
97
- # and needs to be appropriately escaped by the implementation when it is written out.
98
- # In order to assign an attribute value that contains entity references, the user must create
99
- # an Attr node plus any Text and EntityReference nodes, build the appropriate subtree, and use
100
- # setAttributeNode to assign it as the value of an attribute.
101
- # To set an attribute with a qualified name and namespace URI, use the setAttributeNS method.
102
- #
103
- # Parameters
104
- # name of type DOMString
105
- # The name of the attribute to create or alter.
106
- # value of type DOMString
107
- # Value to set in string form.
108
- # Exceptions
109
- # DOMException
110
- # INVALID_CHARACTER_ERR: Raised if the specified name is not an XML name according to the XML version
111
- # in use specified in the Document.xmlVersion attribute.
112
- # NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
113
- # No Return Value
114
- def set_attribute( name, value )
115
- if self.is_readonly then
116
- raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
117
- 'This node is readonly.' )
118
- end
119
- if index = get_index_of_attr( name ) then
120
- @attributes[index].node_value = value
121
- else
122
- new_attr = self.owner_document.create_attribute( name )
123
- new_attr.node_value = value
124
- @attributes << new_attr
125
- new_attr.owner_element = self
126
- end
127
- return nil
128
- end
129
-
130
- # setAttributeNS introduced in DOM Level 2
131
- #
132
- # Adds a new attribute.
133
- # If an attribute with the same local name and namespace URI is already present on the element,
134
- # its prefix is changed to be the prefix part of the qualifiedName, and its value is changed to be
135
- # the value parameter.
136
- # This value is a simple string; it is not parsed as it is being set.
137
- # So any markup (such as syntax to be recognized as an entity reference) is treated as literal text,
138
- # and needs to be appropriately escaped by the implementation when it is written out.
139
- # In order to assign an attribute value that contains entity references, the user must create
140
- # an Attr node plus any Text and EntityReference nodes, build the appropriate subtree,
141
- # and use setAttributeNodeNS or setAttributeNode to assign it as the value of an attribute.
142
- # Per [XML Namespaces], applications must use the value null as the namespaceURI parameter for methods
143
- # if they wish to have no namespace.
144
- #
145
- # Parameters
146
- # namespaceURI of type DOMString
147
- # The namespace URI of the attribute to create or alter.
148
- # qualifiedName of type DOMString
149
- # The qualified name of the attribute to create or alter.
150
- # value of type DOMString
151
- # The value to set in string form.
152
- # Exceptions
153
- # DOMException
154
- # INVALID_CHARACTER_ERR: Raised if the specified qualified name is not an XML name according to
155
- # the XML version in use specified in the Document.xmlVersion attribute.
156
- # NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
157
- # NAMESPACE_ERR: Raised if the qualifiedName is malformed per the Namespaces in XML specification,
158
- # if the qualifiedName has a prefix and the namespaceURI is null, if the qualifiedName
159
- # has a prefix that is "xml" and the namespaceURI is different from
160
- # "http://www.w3.org/XML/1998/namespace", if the qualifiedName or its prefix is "xmlns"
161
- # and the namespaceURI is different from "http://www.w3.org/2000/xmlns/", or if
162
- # the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the qualifiedName
163
- # nor its prefix is "xmlns".
164
- # NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML"
165
- # and the language exposed through the Document does not support XML Namespaces
166
- # (such as [HTML 4.01]).
167
- # No Return Value
168
- def set_attribute_ns( namespace_uri, qualified_name, value )
169
- if self.is_readonly then
170
- raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
171
- 'This node is readonly.' )
172
- end
173
- if index = get_index_of_attr_ns( namespace_uri, qualified_name ) then
174
- @attributes[index].node_value = value
175
- else
176
- new_attr = self.owner_document.create_attribute_ns( namespace_uri, qualified_name )
177
- new_attr.node_value = value
178
- @attributes << new_attr
179
- new_attr.owner_element = self
180
- end
181
- return nil
182
- end
183
-
184
- # setAttributeNode
185
- #
186
- # Adds a new attribute node.
187
- # #=> 新しい属性を追加する.
188
- # If an attribute with that name (nodeName) is already present in the element, it is replaced by the new one.
189
- # #=> nodeName が同じ属性が既に要素内にある場合, それは新しいものに置き換えられる.
190
- # Replacing an attribute node by itself has no effect.
191
- # #=> 自分自身との入れ替えは何の効果もない.
192
- # To add a new attribute node with a qualified name and namespace URI, use the setAttributeNodeNS method.
193
- # #=> qualified name と namespace URI を持つ新しい属性を追加するためには, setAttributeNodeNS メソッドを使用すること.
194
- #
195
- # Parameters
196
- # newAttr of type Attr
197
- # The Attr node to add to the attribute list.
198
- # Return Value
199
- # Attr
200
- # If the newAttr attribute replaces an existing attribute, the replaced Attr node is returned,
201
- # otherwise null is returned.
202
- # Exceptions
203
- # DOMException
204
- # WRONG_DOCUMENT_ERR: Raised if newAttr was created from a different document than the one
205
- # that created the element.
206
- # NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
207
- # INUSE_ATTRIBUTE_ERR: Raised if newAttr is already an attribute of another Element object.
208
- # The DOM user must explicitly clone Attr nodes to re-use them in other elements.
209
- def set_attribute_node( new_attr )
210
- if self.is_readonly then
211
- raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
212
- 'This node is readonly.' )
213
- elsif new_attr.owner_document != self.owner_document then
214
- raise DOMException.new( DOMException::WRONG_DOCUMENT_ERR,
215
- 'The argument new_attr was created from a different document than the one that created the element.' )
216
- elsif ! new_attr.owner_element.nil? then
217
- raise DOMException.new( DOMException::INUSE_ATTRIBUTE_ERR,
218
- 'The argument new_attr is already an attribute of another Element object.' )
219
- end
220
- return set_attribute_node_inner( new_attr, get_index_of_attr( new_attr.node_name ) )
221
- end
222
-
223
- # setAttributeNodeNS introduced in DOM Level 2
224
- #
225
- # Adds a new attribute.
226
- # #=> 新しい属性を追加する.
227
- # If an attribute with that local name and that namespace URI is already present in the element,
228
- # it is replaced by the new one.
229
- # #=> local name と namespace URI が同じ属性が既に要素内にある場合, それは新しいものに置き換えられる.
230
- # Replacing an attribute node by itself has no effect.
231
- # #=> 自分自身と置き換えられる場合は, 何の効果もない.
232
- # Per [XML Namespaces], applications must use the value null as the namespaceURI parameter for methods
233
- # if they wish to have no namespace.
234
- #
235
- # Parameters
236
- # newAttr of type Attr
237
- # The Attr node to add to the attribute list.
238
- # Return Value
239
- # Attr
240
- # If the newAttr attribute replaces an existing attribute with the same local name and namespace URI,
241
- # the replaced Attr node is returned, otherwise null is returned.
242
- # Exceptions
243
- # DOMException
244
- # WRONG_DOCUMENT_ERR: Raised if newAttr was created from a different document than the one
245
- # that created the element.
246
- # NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
247
- # INUSE_ATTRIBUTE_ERR: Raised if newAttr is already an attribute of another Element object.
248
- # The DOM user must explicitly clone Attr nodes to re-use them in other elements.
249
- # NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML"
250
- # and the language exposed through the Document does not support XML Namespaces
251
- # (such as [HTML 4.01]).
252
- def set_attribute_node_ns( new_attr )
253
- if self.is_readonly then
254
- raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
255
- 'This node is readonly.' )
256
- elsif new_attr.owner_document != self.owner_document then
257
- raise DOMException.new( DOMException::WRONG_DOCUMENT_ERR,
258
- 'The argument new_attr was created from a different document than the one that created the element.' )
259
- elsif ! new_attr.owner_element.nil? then
260
- raise DOMException.new( DOMException::INUSE_ATTRIBUTE_ERR,
261
- 'The argument new_attr is already an attribute of another Element object.' )
262
- end
263
- return set_attribute_node_inner( new_attr, get_index_of_attr_ns( new_attr.namespace_uri, new_attr.local_name ) )
264
- end
265
-
266
- # getAttribute
267
- #
268
- # Retrieves an attribute value by name.
269
- #
270
- # Parameters
271
- # name of type DOMString
272
- # The name of the attribute to retrieve.
273
- # Return Value
274
- # DOMString
275
- # The Attr value as a string, or the empty string if that attribute does not have a specified
276
- # or default value.
277
- # No Exceptions
278
- def get_attribute( name )
279
- index = get_index_of_attr( name )
280
- return ( index.nil? ? '' : @attributes[index].node_value )
281
- end
282
-
283
- # getAttributeNS introduced in DOM Level 2
284
- #
285
- # Retrieves an attribute value by local name and namespace URI.
286
- # Per [XML Namespaces], applications must use the value null as the namespaceURI parameter for methods
287
- # if they wish to have no namespace.
288
- #
289
- # Parameters
290
- # namespaceURI of type DOMString
291
- # The namespace URI of the attribute to retrieve.
292
- # localName of type DOMString
293
- # The local name of the attribute to retrieve.
294
- # Return Value
295
- # DOMString
296
- # The Attr value as a string, or the empty string if that attribute does not have a specified
297
- # or default value.
298
- # Exceptions
299
- # DOMException
300
- # NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML"
301
- # and the language exposed through the Document does not support XML Namespaces
302
- # (such as [HTML 4.01]).
303
- def get_attribute_ns( namespace_uri, local_name )
304
- index = get_index_of_attr_ns( namespace_uri, local_name )
305
- return ( index.nil? ? '' : @attributes[index].node_value )
306
- end
307
-
308
- # getAttributeNode
309
- #
310
- # Retrieves an attribute node by name.
311
- # To retrieve an attribute node by qualified name and namespace URI, use the getAttributeNodeNS method.
312
- #
313
- # Parameters
314
- # name of type DOMString
315
- # The name (nodeName) of the attribute to retrieve.
316
- # Return Value
317
- # Attr
318
- # The Attr node with the specified name (nodeName) or null if there is no such attribute.
319
- # No Exceptions
320
- def get_attribute_node( name )
321
- index = get_index_of_attr( name )
322
- return ( index.nil? ? nil : @attributes[index] )
323
- end
324
-
325
- # getAttributeNodeNS introduced in DOM Level 2
326
- #
327
- # Retrieves an Attr node by local name and namespace URI.
328
- # Per [XML Namespaces], applications must use the value null as the namespaceURI parameter
329
- # for methods if they wish to have no namespace.
330
- #
331
- # Parameters
332
- # namespaceURI of type DOMString
333
- # The namespace URI of the attribute to retrieve.
334
- # localName of type DOMString
335
- # The local name of the attribute to retrieve.
336
- # Return Value
337
- # Attr
338
- # The Attr node with the specified attribute local name and namespace URI or null
339
- # if there is no such attribute.
340
- # Exceptions
341
- # DOMException
342
- # NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML"
343
- # and the language exposed through the Document does not support XML Namespaces
344
- # (such as [HTML 4.01]).
345
- def get_attribute_node_ns( namespace_uri, local_name )
346
- index = get_index_of_attr_ns( namespace_uri, local_name )
347
- return ( index.nil? ? nil : @attributes[index] )
348
- end
349
-
350
- # removeAttribute
351
- #
352
- # Removes an attribute by name. If a default value for the removed attribute is defined in the DTD, a new attribute immediately appears with the default value as well as the corresponding namespace URI, local name, and prefix when applicable. The implementation may handle default values from other schemas similarly but applications should use Document.normalizeDocument() to guarantee this information is up-to-date.
353
- # If no attribute with this name is found, this method has no effect.
354
- # To remove an attribute by local name and namespace URI, use the removeAttributeNS method.
355
- #
356
- # Parameters
357
- # name of type DOMString
358
- # The name of the attribute to remove.
359
- # Exceptions
360
- # DOMException
361
- # NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
362
- # No Return Value
363
- def remove_attribute( name )
364
- if self.is_readonly then
365
- raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
366
- 'This node is readonly.' )
367
- end
368
- if index = get_index_of_attr( name ) then
369
- @attributes.delete_at( index ).owner_element = nil
370
- end
371
- return nil
372
- end
373
-
374
- # removeAttributeNS introduced in DOM Level 2
375
- #
376
- # Removes an attribute by local name and namespace URI. If a default value for the removed attribute is defined in the DTD, a new attribute immediately appears with the default value as well as the corresponding namespace URI, local name, and prefix when applicable. The implementation may handle default values from other schemas similarly but applications should use Document.normalizeDocument() to guarantee this information is up-to-date.
377
- # If no attribute with this local name and namespace URI is found, this method has no effect.
378
- # Per [XML Namespaces], applications must use the value null as the namespaceURI parameter for methods if they wish to have no namespace.
379
- #
380
- # Parameters
381
- # namespaceURI of type DOMString
382
- # The namespace URI of the attribute to remove.
383
- # localName of type DOMString
384
- # The local name of the attribute to remove.
385
- # Exceptions
386
- # DOMException
387
- # NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
388
- # NOT_SUPPORTED_ERR: May be raised if the implementation does not support the feature "XML" and the language exposed through the Document does not support XML Namespaces (such as [HTML 4.01]).
389
- # No Return Value
390
- def remove_attribute_ns( namespace_uri, local_name )
391
- if self.is_readonly then
392
- raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
393
- 'This node is readonly.' )
394
- end
395
- if index = get_index_of_attr_ns( namespace_uri, local_name ) then
396
- @attributes.delete_at( index ).owner_element = nil
397
- end
398
- return nil
399
- end
400
-
401
- # removeAttributeNode
402
- #
403
- # Removes the specified attribute node. If a default value for the removed Attr node is defined in the DTD, a new node immediately appears with the default value as well as the corresponding namespace URI, local name, and prefix when applicable. The implementation may handle default values from other schemas similarly but applications should use Document.normalizeDocument() to guarantee this information is up-to-date.
404
- #
405
- # Parameters
406
- # oldAttr of type Attr
407
- # The Attr node to remove from the attribute list.
408
- # Return Value
409
- # Attr
410
- # The Attr node that was removed.
411
- # Exceptions
412
- # DOMException
413
- # NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
414
- # NOT_FOUND_ERR: Raised if oldAttr is not an attribute of the element.
415
- def remove_attribute_node( old_attr )
416
- if self.is_readonly then
417
- raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR,
418
- 'This node is readonly.' )
419
- end
420
- if index = get_index_of_attr_node( old_attr ) then
421
- @attributes.delete_at( index ).owner_element = nil
422
- else
423
- raise DOMException.new( DOMException::NOT_FOUND_ERR,
424
- 'The argument oldAttr is not an attribute of the element.' )
425
- end
426
- return old_attr
427
- end
428
-
429
- # Exceptions
430
- # DOMException
431
- # INVALID_CHARACTER_ERR: Raised if the specified name is not an XML name according to
432
- # the XML version in use specified in the Document.xmlVersion attribute.
433
- def initialize( owner_document, tagname )
434
- if XMLRegExp::NAME !~ tagname then
435
- # the specified qualified name is not an XML name
436
- raise DOMException.new( DOMException::INVALID_CHARACTER_ERR,
437
- 'The specified name "' + tagname + '" is not an XML name.' )
438
- end
439
- super( owner_document )
440
- init_mod_child_node()
441
- init_mod_parent_node()
442
- @attributes = []
443
- @attributes_wrapper = NamedNodeMapAttr.new( @attributes, self )
444
- @tagname = tagname
445
- end
446
-
447
- protected
448
- def tagname=( tagname )
449
- @tagname = tagname
450
- end
451
-
452
- def check_hierarchy( new_child )
453
- # Element (maximum of one), ProcessingInstruction, Comment, DocumentType (maximum of one)
454
- super( new_child, true )
455
- case new_child.node_type
456
- when Node::ELEMENT_NODE, Node::TEXT_NODE, Node::COMMENT_NODE, Node::PROCESSING_INSTRUCTION_NODE,
457
- Node::CDATA_SECTION_NODE, Node::ENTITY_REFERENCE_NODE then
458
- return true
459
- else
460
- raise DOMException.new( DOMException::HIERARCHY_REQUEST_ERR,
461
- 'This node is of a type that does not allow children of the type of the newChild node.' )
462
- end
463
- end
464
-
465
- private
466
- def get_index_of_attr( name )
467
- index = nil
468
- @attributes.each_with_index do |item, i|
469
- if item.node_name == name then
470
- index = i
471
- break
472
- end
473
- end
474
- return index
475
- end
476
- def get_index_of_attr_ns( namespace_uri, local_name )
477
- index = nil
478
- @attributes.each_with_index do |item, i|
479
- if item.namespace_uri == namespace_uri and item.local_name == local_name then
480
- index = i
481
- break
482
- end
483
- end
484
- return index
485
- end
486
- def get_index_of_attr_node( node )
487
- index = nil
488
- @attributes.each_with_index do |item, i|
489
- if item.equal? node then
490
- index = i
491
- break
492
- end
493
- end
494
- return index
495
- end
496
- def set_attribute_node_inner( new_attr, index )
497
- old_attr = nil
498
- if index.nil? then
499
- @attributes << new_attr
500
- new_attr.owner_element = self
501
- else
502
- old_attr = @attributes[index]
503
- old_attr.owner_element = nil
504
- @attributes[index] = new_attr
505
- new_attr.owner_element = self
506
- end
507
- return old_attr
508
- end
509
-
510
- end
511
- end
512
- end
@@ -1,42 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- require "vcdom/minidom/element"
4
- require "vcdom/minidom/dom_exception"
5
- require "vcdom/minidom/mod_namespaceuri_manageable"
6
- require "vcdom/minidom/xml_reg_exp"
7
-
8
- module VCDOM
9
- module MiniDOM
10
- class ElementNS < Element
11
-
12
- include ModNamespaceURIManageable
13
-
14
- # INVALID_CHARACTER_ERR: Raised if the specified qualifiedName is not an
15
- # XML name according to the XML version in use specified in
16
- # the Document.xmlVersion attribute. ?
17
- # NAMESPACE_ERR: Raised if the qualifiedName is a malformed qualified name,
18
- # if the qualifiedName has a prefix and the namespaceURI is null,
19
- # or if the qualifiedName has a prefix that is "xml" and the
20
- # namespaceURI is different from
21
- # "http://www.w3.org/XML/1998/namespace" [XML Namespaces], or
22
- # if the qualifiedName or its prefix is "xmlns" and the
23
- # namespaceURI is different from "http://www.w3.org/2000/xmlns/",
24
- # or if the namespaceURI is "http://www.w3.org/2000/xmlns/" and
25
- # neither the qualifiedName nor its prefix is "xmlns".
26
- def initialize( owner_document, namespace_uri, qualified_name )
27
- begin
28
- super( owner_document, qualified_name )
29
- rescue DOMException => err
30
- if err.code == DOMException::INVALID_CHARACTER_ERR then
31
- raise DOMException.new( DOMException::INVALID_CHARACTER_ERR,
32
- 'The specified qualified name "' + qualified_name + '" is not an XML name.' )
33
- else
34
- raise err
35
- end
36
- end
37
- init_mod_namespaceuri_manageable( namespace_uri, qualified_name )
38
- end
39
-
40
- end
41
- end
42
- end
@@ -1,9 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module VCDOM
4
- module MiniDOM
5
- class MiniParser
6
-
7
- end
8
- end
9
- end
@@ -1,118 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- module VCDOM
4
- module MiniDOM
5
- class MiniSerializer
6
-
7
- def write_to_string( node, do_indent = false )
8
- return serialize_node( node, do_indent )
9
- end
10
-
11
- private
12
- def serialize_node( node, do_indent = false, indent_depth = 0 )
13
- case node.node_type
14
- when Node::DOCUMENT_NODE then
15
- return serialize_document( node, do_indent )
16
- when Node::ELEMENT_NODE then
17
- return serialize_element( node, do_indent, indent_depth )
18
- when Node::TEXT_NODE then
19
- return serialize_text( node, do_indent, indent_depth )
20
- when Node::COMMENT_NODE then
21
- return serialize_commnet( node, do_indent, indent_depth )
22
- when Node::CDATA_SECTION_NODE then
23
- return serialize_cdata_section( node, do_indent, indent_depth )
24
- end
25
- end
26
- def serialize_document( node, do_indent )
27
- str = String.new()
28
- node.child_nodes.each do |n|
29
- str << serialize_node( n, do_indent )
30
- end
31
- # 頭の改行を削除
32
- if do_indent then
33
- str = str[1..-1]
34
- end
35
- return str
36
- end
37
- def serialize_element( node, do_indent, indent_depth )
38
- str = String.new()
39
- if do_indent then
40
- str << "\n" << ' ' * ( indent_depth * 2 )
41
- end
42
- str << '<' << node.tagname
43
- # attributes
44
- node.attributes.each do |item|
45
- str << ' ' << item.node_name << '="'
46
- str << item.node_value.gsub( /<|&|"|[\x0-\x19]/u ) do |s|
47
- if s == '<' then
48
- s = '&lt;'
49
- elsif s == '&' then
50
- s = '&amp;'
51
- elsif s == '"' then
52
- s = '&quot;'
53
- elsif /[\x0-\x19]/u =~ s then
54
- s = '&#' + $&.unpack('U')[0].to_s() + ';'
55
- end
56
- s
57
- end
58
- str << '"'
59
- end
60
- if node.has_child_nodes then
61
- str << '>'
62
- node.child_nodes.each do |n|
63
- if n.node_type == Node::TEXT_NODE then
64
- do_indent = false
65
- end
66
- end
67
- node.child_nodes.each do |n|
68
- str << serialize_node( n, do_indent, indent_depth + 1 )
69
- end
70
- if do_indent then
71
- str << "\n" << ' ' * ( indent_depth * 2 )
72
- end
73
- str << '</' << node.tagname << '>'
74
- else
75
- str << ' />'
76
- end
77
- return str
78
- end
79
- def serialize_text( node, do_indent, indent_depth )
80
- str = String.new()
81
- str << node.data.gsub( /<|&/u ) do |s|
82
- if s == '<' then
83
- s = '&lt;'
84
- elsif s == '&' then
85
- s = '&amp;'
86
- end
87
- s
88
- end
89
- return str
90
- end
91
- def serialize_commnet( node, do_indent, indent_depth )
92
- # "--" が含まれていないかどうかのチェック
93
- if /--/u =~ node.data then
94
- raise MiniDOMStandardError.new( 'fatal error in serialization : The Comment node contains "--" (double-hyphen).' )
95
- end
96
- str = String.new()
97
- if do_indent then
98
- str << "\n" << ' ' * ( indent_depth * 2 )
99
- end
100
- str << '<!--' << node.data << '-->'
101
- return str
102
- end
103
- def serialize_cdata_section( node, do_indent, indent_depth )
104
- # "]]>" が含まれていないかどうかのチェック
105
- if /\]\]>/u =~ node.data then
106
- raise MiniDOMStandardError.new( 'fatal error in serialization : The CDATASection node contains "]]>".' )
107
- end
108
- str = String.new()
109
- if do_indent then
110
- str << "\n" << ' ' * ( indent_depth * 2 )
111
- end
112
- str << '<![CDATA[' << node.data << ']]>'
113
- return str
114
- end
115
-
116
- end
117
- end
118
- end