xmlparser 0.6.81

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. data/MANIFEST +112 -0
  2. data/README +697 -0
  3. data/README.ja +789 -0
  4. data/Rakefile +34 -0
  5. data/ext/encoding.h +91 -0
  6. data/ext/xmlparser/mkrf_conf.rb +28 -0
  7. data/ext/xmlparser/xmlparser.c +2226 -0
  8. data/lib/sax.rb +1 -0
  9. data/lib/saxdriver.rb +1 -0
  10. data/lib/wget.rb +47 -0
  11. data/lib/xml/dom/builder-ja.rb +58 -0
  12. data/lib/xml/dom/builder.rb +310 -0
  13. data/lib/xml/dom/core.rb +3276 -0
  14. data/lib/xml/dom/digest.rb +94 -0
  15. data/lib/xml/dom/visitor.rb +182 -0
  16. data/lib/xml/dom2/attr.rb +213 -0
  17. data/lib/xml/dom2/cdatasection.rb +76 -0
  18. data/lib/xml/dom2/characterdata.rb +177 -0
  19. data/lib/xml/dom2/comment.rb +81 -0
  20. data/lib/xml/dom2/core.rb +19 -0
  21. data/lib/xml/dom2/document.rb +317 -0
  22. data/lib/xml/dom2/documentfragment.rb +82 -0
  23. data/lib/xml/dom2/documenttype.rb +102 -0
  24. data/lib/xml/dom2/dombuilder.rb +277 -0
  25. data/lib/xml/dom2/dombuilderfilter.rb +12 -0
  26. data/lib/xml/dom2/domentityresolver.rb +13 -0
  27. data/lib/xml/dom2/domentityresolverimpl.rb +37 -0
  28. data/lib/xml/dom2/domexception.rb +95 -0
  29. data/lib/xml/dom2/domimplementation.rb +61 -0
  30. data/lib/xml/dom2/dominputsource.rb +29 -0
  31. data/lib/xml/dom2/element.rb +533 -0
  32. data/lib/xml/dom2/entity.rb +110 -0
  33. data/lib/xml/dom2/entityreference.rb +107 -0
  34. data/lib/xml/dom2/namednodemap.rb +138 -0
  35. data/lib/xml/dom2/node.rb +587 -0
  36. data/lib/xml/dom2/nodelist.rb +231 -0
  37. data/lib/xml/dom2/notation.rb +86 -0
  38. data/lib/xml/dom2/processinginstruction.rb +155 -0
  39. data/lib/xml/dom2/text.rb +128 -0
  40. data/lib/xml/dom2/xpath.rb +398 -0
  41. data/lib/xml/encoding-ja.rb +42 -0
  42. data/lib/xml/parser.rb +13 -0
  43. data/lib/xml/parserns.rb +236 -0
  44. data/lib/xml/sax.rb +353 -0
  45. data/lib/xml/saxdriver.rb +370 -0
  46. data/lib/xml/xpath.rb +3284 -0
  47. data/lib/xml/xpath.ry +2352 -0
  48. data/lib/xmldigest.rb +1 -0
  49. data/lib/xmltree.rb +1 -0
  50. data/lib/xmltreebuilder.rb +1 -0
  51. data/lib/xmltreevisitor.rb +1 -0
  52. metadata +111 -0
@@ -0,0 +1,12 @@
1
+ ## -*- Ruby -*-
2
+ ## XML::DOM::DOMBuilderFilter
3
+ ## 2001 by yoshidam
4
+ ##
5
+
6
+ module XML
7
+ module DOM
8
+ module DOMBuilderFilter
9
+ def endElement(element); end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ ## -*- Ruby -*-
2
+ ## XML::DOM::DOMEntityResolver
3
+ ## 2001 by yoshidam
4
+ ##
5
+
6
+ module XML
7
+ module DOM
8
+ module DOMEntityResolver
9
+ ## DOMInputSource resolveEntity(publicId, systemId)
10
+ def resolveEntity(publicId, systemId); end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ ## -*- Ruby -*-
2
+ ## XML::DOM::DOMEntityResolverImpl
3
+ ## 2001 by yoshidam
4
+ ##
5
+
6
+ require 'xml/dom2/domentityresolver'
7
+ require 'xml/dom2/dominputsource'
8
+
9
+ module XML
10
+ module DOM
11
+ class DOMEntityResolverImpl
12
+ include DOMEntityResolver
13
+
14
+ ## replace 'open' by WGET::open
15
+ begin
16
+ require 'wget'
17
+ ## include WGET
18
+ rescue
19
+ ## ignore
20
+ end
21
+
22
+ ## DOMInputSource resolveEntity(publicId, systemId)
23
+ def resolveEntity(publicId, systemId)
24
+ ret = DOMInputSource.new
25
+ ret.publicId = publicId
26
+ ret.systemId = systemId
27
+ if systemId =~ /file:/
28
+ ret.byteStream = open(systemId.sub('^file://', ''))
29
+ else
30
+ ret.byteStream = WGET::open(systemId)
31
+ end
32
+ ret
33
+ end
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,95 @@
1
+ ## -*- Ruby -*-
2
+ ## XML::DOM
3
+ ## 1998-2001 by yoshidam
4
+ ##
5
+
6
+ module XML
7
+ module DOM
8
+ =begin
9
+
10
+ == Class XML::DOM::DOMException
11
+
12
+ === superclass
13
+ Exception
14
+
15
+ DOM exception.
16
+ =end
17
+
18
+ class DOMException<Exception
19
+ INDEX_SIZE_ERR = 1
20
+ WSTRING_SIZE_ERR = 2
21
+ HIERARCHY_REQUEST_ERR = 3
22
+ WRONG_DOCUMENT_ERR = 4
23
+ INVALID_NAME_ERR = 5
24
+ NO_DATA_ALLOWED_ERR = 6
25
+ NO_MODIFICATION_ALLOWED_ERR = 7
26
+ NOT_FOUND_ERR = 8
27
+ NOT_SUPPORTED_ERR = 9
28
+ INUSE_ATTRIBUTE_ERR = 10
29
+
30
+ ## [DOM2]
31
+ INVALID_STATE_ERR = 11
32
+ SYNTAX_ERR = 12
33
+ INVALID_MODIFICATION_ERR = 13
34
+ NAMESPACE_ERR = 14
35
+ INVALIUD_ACCESS_ERR = 14
36
+
37
+ ERRMSG = [
38
+ "no error",
39
+
40
+ "index size",
41
+ "wstring size",
42
+ "hierarchy request",
43
+ "wrong document",
44
+ "invalid name",
45
+ "no data allowed",
46
+ "no modification allowed",
47
+ "not found",
48
+ "not supported",
49
+ "inuse attribute",
50
+
51
+ ## [DOM2]
52
+ "invalid state",
53
+ "syntax error",
54
+ "invalid modification",
55
+ "namescape erorr",
56
+ "invaliud access"
57
+ ]
58
+
59
+ =begin
60
+ === Class Methods
61
+
62
+ --- DOMException.new(code = 0)
63
+
64
+ generate DOM exception.
65
+ =end
66
+
67
+ def initialize(code = 0)
68
+ @code = code
69
+ end
70
+
71
+ =begin
72
+ === Methods
73
+
74
+ --- DOMException#code()
75
+
76
+ return code of exception.
77
+
78
+ =end
79
+ def code
80
+ @code
81
+ end
82
+
83
+ =begin
84
+
85
+ --- DOMException#to_s()
86
+
87
+ return the string representation of the error.
88
+
89
+ =end
90
+ def to_s
91
+ ERRMSG[@code].dup
92
+ end
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,61 @@
1
+ ## -*- Ruby -*-
2
+ ## XML::DOM
3
+ ## 1998-2001 by yoshidam
4
+ ##
5
+
6
+ require 'xml/dom2/domexception'
7
+ require 'xml/dom2/dombuilder'
8
+ require 'xml/dom2/documenttype'
9
+ require 'singleton'
10
+
11
+ module XML
12
+ module DOM
13
+
14
+ =begin
15
+ == Class XML::DOM::DOMImplementation
16
+
17
+ =end
18
+ class DOMImplementation
19
+ include Singleton
20
+
21
+ =begin
22
+ --- DOMImplementation#hasFeature(feature, version)
23
+
24
+ test if DOM implementation has correct feature and version.
25
+
26
+ =end
27
+ def hasFeature(feature, version)
28
+ if (feature =~ /^XML$/i || feature =~ /^Core$/i) &&
29
+ (version.nil? || version == "1.0" || version == "2.0")
30
+ return true
31
+ end
32
+ false
33
+ end
34
+
35
+ ## [DOM2]
36
+ def createDocumentType(qname, pubid, sysid)
37
+ DocumentType.new(qname, pubid, sysid)
38
+ end
39
+
40
+ ## [DOM2]
41
+ def createDocument(nsuri, qname, doctype)
42
+ raise DOMException.new(DOMException::WRONG_DOCUMENT_ERR) if
43
+ doctype && doctype.ownerDocument
44
+ doc = Document.new
45
+ if doctype
46
+ doc.appendChild(doctype)
47
+ doctype.ownerDocument = doc
48
+ end
49
+ elem = doc.createElementNS(nsuri, qname)
50
+ doc.appendChild(elem)
51
+ doc.implementation = self
52
+ doc
53
+ end
54
+
55
+ ## [DOM3?]
56
+ def createDOMBuilder
57
+ XML::DOM::DOMBuilder.new(Document.new)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,29 @@
1
+ ## -*- Ruby -*-
2
+ ## XML::DOM::DOMEntityResolver
3
+ ## 2001 by yoshidam
4
+ ##
5
+
6
+ module XML
7
+ module DOM
8
+ class DOMInputSource
9
+ def initialize
10
+ @bstream = nil
11
+ @cstream = nil
12
+ @encoding = nil
13
+ @pubid = nil
14
+ @sysid = nil
15
+ end
16
+
17
+ def byteStream; @bstream; end
18
+ def byteStream=(stream); @bstream = stream; end
19
+ def characterStream; @cstream; end
20
+ def characterStream=(stream); @cstream = stream; end
21
+ def encoding; @encoding; end
22
+ def encoding=(enc);@encoding = enc; end
23
+ def publicId; @pubid; end
24
+ def publicId=(pubid); @pubid = pubid; end
25
+ def systemId; @sysid; end
26
+ def systemId=(sysid); @sysid = sysid; end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,533 @@
1
+ ## -*- Ruby -*-
2
+ ## XML::DOM
3
+ ## 1998-2001 by yoshidam
4
+ ##
5
+
6
+ require 'xml/dom2/node'
7
+ require 'xml/dom2/domexception'
8
+ require 'xml/dom2/nodelist'
9
+ require 'xml/dom2/namednodemap'
10
+
11
+ module XML
12
+ module DOM
13
+
14
+ =begin
15
+ == Class XML::DOM::Element
16
+
17
+ === superclass
18
+ Node
19
+
20
+ =end
21
+ class Element<Node
22
+
23
+ =begin
24
+ === Class Methods
25
+
26
+ --- Element.new(tag = nil, attrs = nil, *children)
27
+
28
+ create a new Element.
29
+ =end
30
+ ## new(tag, attrs, [child1, child2, ...]) or
31
+ ## new(tag, attrs, child1, child2, ...)
32
+ ## tag: String
33
+ ## attrs: Hash, Attr or Array of Attr (or nil)
34
+ ## child?: String or Node
35
+ def initialize(tag = nil, attr = nil, *children)
36
+ super(*children)
37
+ raise "parameter error" if !tag
38
+ @name = nil
39
+ @prefix = nil
40
+ @localname = nil
41
+ @uri = nil
42
+ @idAttribute = nil
43
+ if tag.is_a?(Array)
44
+ ## namespaces
45
+ raise "parameter error" if tag.length != 2
46
+ @localname = tag[1]
47
+ if tag[1].index(':')
48
+ @prefix, @localname = tag[1].split(':')
49
+ end
50
+ @name = tag[1] ## qualified name
51
+ @uri = tag[0] ## namespace URI
52
+ else
53
+ @name = tag
54
+ end
55
+ @name.freeze
56
+ @localname.freeze
57
+ @uri.freeze
58
+ @prefix.freeze
59
+
60
+ if attr.nil?
61
+ @attr = NamedNodeMap.new([])
62
+ elsif attr.is_a?(Hash)
63
+ nodes = []
64
+ attr.each do |key, value|
65
+ nodes.push(Attr.new(key, value))
66
+ end
67
+ @attr = NamedNodeMap.new(nodes)
68
+ elsif attr.is_a?(Array)
69
+ @attr = NamedNodeMap.new(attr)
70
+ elsif attr.nodeType == ATTRIBUTE_NODE
71
+ @attr = NamedNodeMap.new([attr])
72
+ else
73
+ raise "parameter error: #{attr}"
74
+ end
75
+ @attr.each do |attr|
76
+ attr.ownerElement = self
77
+ end
78
+ end
79
+
80
+ =begin
81
+ === Methods
82
+
83
+ --- Element#nodeType()
84
+
85
+ [DOM]
86
+ returns the nodeType.
87
+ =end
88
+ ## [DOM]
89
+ def nodeType
90
+ ELEMENT_NODE
91
+ end
92
+
93
+ =begin
94
+ --- Element#nodeName()
95
+
96
+ [DOM]
97
+ returns the nodeName.
98
+ =end
99
+ ## [DOM]
100
+ def nodeName
101
+ @name
102
+ end
103
+
104
+ =begin
105
+ --- Element#attributes()
106
+
107
+ [DOM]
108
+ returns the attributes of this Element.
109
+ =end
110
+ ## [DOM]
111
+ def attributes
112
+ if iterator?
113
+ @attr.each do |key, value|
114
+ yield(value)
115
+ end if @attr
116
+ else
117
+ @attr
118
+ end
119
+ end
120
+
121
+ def _getNamespaces(parentNamespaces = {}, all = false)
122
+ if !parentNamespaces
123
+ parentNamespaces = parentNode._getNamespaces(nil, true)
124
+ end
125
+ namespaces = {}
126
+ attributes.each do |a|
127
+ namespaces[a.prefix] = a.namespaceURI if a.prefix
128
+ end
129
+ if @localname
130
+ namespaces[@prefix] = @uri
131
+ end
132
+ parentNamespaces.each do |prefix, uri|
133
+ if all
134
+ if !namespaces.include?(prefix)
135
+ namespaces[prefix] = uri
136
+ end
137
+ else
138
+ if namespaces[prefix] == parentNamespaces[prefix]
139
+ namespaces.delete(prefix)
140
+ end
141
+ end
142
+ end
143
+ namespaces
144
+ end
145
+
146
+ =begin
147
+ --- Element#to_s()
148
+
149
+ return the string representation of the Element.
150
+ =end
151
+ def to_s
152
+ attr = ''
153
+
154
+ namespaces = {}
155
+ attributes.each do |a|
156
+ namespaces[a.prefix] = a.namespaceURI if a.prefix
157
+ end
158
+ if @localname
159
+ namespaces[@prefix] = @uri
160
+ end
161
+
162
+ namespaces.each do |prefix, uri|
163
+ ## skip the namespace declaration of xml or xmlns.
164
+ next if prefix == 'xml' or
165
+ uri == 'http://www.w3.org/2000/xmlns/'
166
+ nsattrname = 'xmlns'
167
+ nsattrname << ':' + prefix if prefix
168
+ ## skip duplicated namespace declarations.
169
+ next if @attr.getNamedItem(nsattrname)
170
+ attr << " #{nsattrname}=\"#{uri}\""
171
+ end
172
+
173
+ @attr.each do |a|
174
+ attr << ' ' + a.to_s
175
+ end if @attr
176
+ content = super
177
+ if content != ''
178
+ ret = "<#{@name}#{attr}>#{content}</#{@name}>"
179
+ else
180
+ ret = "<#{@name}#{attr}/>"
181
+ end
182
+ ret << "\n" if parentNode.nodeType == DOCUMENT_NODE
183
+ ret
184
+ end
185
+
186
+ =begin
187
+ --- Element#dump(depth = 0)
188
+
189
+ dumps the Element.
190
+ =end
191
+ def dump(depth = 0)
192
+ attr = ''
193
+ @attr.each do |a| ## self.attributes do |a|
194
+ attr += a.to_s + ", "
195
+ end if @attr
196
+ attr.chop!
197
+ attr.chop!
198
+ print ' ' * depth * 2
199
+ print "#{@name}(#{attr})\n"
200
+ @children.each do |child|
201
+ child.dump(depth + 1)
202
+ end if @children
203
+ end
204
+
205
+ =begin
206
+ --- Element#tagName()
207
+
208
+ [DOM]
209
+ alias of nodeName.
210
+ =end
211
+ ## [DOM]
212
+ alias tagName nodeName
213
+
214
+ =begin
215
+ --- Element#getAttribute(name)
216
+
217
+ [DOM]
218
+ retrieves an attribute value by name.
219
+ =end
220
+ ## [DOM]
221
+ def getAttribute(name)
222
+ attr = getAttributeNode(name)
223
+ if attr.nil?
224
+ ''
225
+ else
226
+ attr.nodeValue
227
+ end
228
+ end
229
+
230
+ =begin
231
+ --- Element#setAttribute(name, value)
232
+
233
+ [DOM]
234
+ adds a new attribute.
235
+ =end
236
+ ## [DOM]
237
+ def setAttribute(name, value)
238
+ if @ownerElement
239
+ attr = @ownerDocument.createAttribute(name)
240
+ attr.appendChild(@ownerDocument.createTextNode(value))
241
+ else
242
+ attr = Attr.new(name)
243
+ attr.appendChild(Text.new(value))
244
+ end
245
+ setAttributeNode(attr)
246
+ end
247
+
248
+ =begin
249
+ --- Element#removeAttribute(name)
250
+
251
+ [DOM]
252
+ remove an attribute by name.
253
+ =end
254
+ ## [DOM]
255
+ def removeAttribute(name)
256
+ ret = getAttributeNode(name)
257
+ removeAttributeNode(ret) if ret
258
+ end
259
+
260
+ =begin
261
+ --- Element#getAttributeNode(name)
262
+
263
+ [DOM]
264
+ retrieves an Attr node by name.
265
+ =end
266
+ ## [DOM]
267
+ def getAttributeNode(name)
268
+ @attr.getNamedItem(name)
269
+ end
270
+
271
+ =begin
272
+ --- Element#setAttributeNode(newAttr)
273
+
274
+ [DOM]
275
+ adds a new attribute.
276
+ =end
277
+ ## [DOM]
278
+ def setAttributeNode(newAttr)
279
+ ret = getAttributeNode(newAttr.nodeName)
280
+ if ret == newAttr
281
+ raise DOMException.new(DOMException::INUSE_ATTRIBUTE_ERR)
282
+ end
283
+ ret.ownerElement = nil if ret
284
+ @attr.setNamedItem(newAttr)
285
+ newAttr.ownerElement = self
286
+ ret
287
+ end
288
+
289
+ =begin
290
+ --- Element#removeAttributeNode(oldAttr)
291
+
292
+ [DOM]
293
+ removes the specified attribute.
294
+ =end
295
+ ## [DOM]
296
+ def removeAttributeNode(oldAttr)
297
+ ret = getAttributeNode(oldAttr.nodeName)
298
+ if ret.nil? || ret != oldAttr
299
+ raise DOMException.new(DOMException::NOT_FOUND_ERR)
300
+ end
301
+ @attr.removeNamedItem(oldAttr.nodeName)
302
+ ret.ownerElement = nil
303
+ ret
304
+ end
305
+
306
+ =begin
307
+ --- Element#getElementsByTagName(tagname)
308
+
309
+ [DOM]
310
+ returns a NodeList of all descendant elements with given tag name.
311
+ =end
312
+ ## [DOM] (but this is not "live")
313
+ def getElementsByTagName(tagname)
314
+ ret = NodeList.new
315
+ @children.each do |node|
316
+ if node.nodeType == ELEMENT_NODE
317
+ if tagname == '*' || node.nodeName == tagname
318
+ ret << node
319
+ end
320
+ ret << node.getElementsByTagName(tagname)
321
+ end
322
+ end if @children
323
+ ret
324
+ end
325
+
326
+
327
+ =begin
328
+ --- Element#normalize
329
+
330
+ [DOM]
331
+ puts all Text nodes in the full depth of the sub-tree under this
332
+ Eelemnt.
333
+ =end
334
+ ## [DOM]
335
+ def normalize
336
+ return if @children.nil?
337
+ old = nil
338
+ children = @children.to_a.dup
339
+ children.each do |child|
340
+ if !old.nil? && old.nodeType == TEXT_NODE &&
341
+ child.nodeType == TEXT_NODE
342
+ old.appendData(child.nodeValue)
343
+ self.removeChild(child)
344
+ else
345
+ if child.nodeType == ELEMENT_NODE
346
+ child.normalize
347
+ end
348
+ old = child
349
+ end
350
+ end
351
+ end
352
+
353
+ =begin
354
+ --- Element#cloneNode(deep = true)
355
+
356
+ [DOM]
357
+ returns the copy of the Element.
358
+ =end
359
+ ## [DOM]
360
+ def cloneNode(deep = true)
361
+ attrs = []
362
+ @attr.each do |attr|
363
+ attrs.push(attr.cloneNode(true))
364
+ end
365
+ super(deep, @name, attrs)
366
+ end
367
+
368
+ ## get the list of nodeValues by IDs
369
+ ## [experimental implement]
370
+ def _getIDVals(ids = nil)
371
+ if ids.nil?
372
+ doc = ownerDocument
373
+ return [] if doc.nil?
374
+ ids = doc._getIDAttrs
375
+ end
376
+
377
+ idelem = []
378
+ if !ids[nodeName].nil?
379
+ return attributes._getValues(ids[nodeName])
380
+ elsif !ids['*'].nil?
381
+ return attributes._getValues(ids['*'])
382
+ end
383
+ return []
384
+ end
385
+
386
+ =begin
387
+ --- Element#trim(preserve = false)
388
+
389
+ trim extra whitespaces.
390
+ =end
391
+ ## trim extra whitespaces
392
+ ## if attribute 'xml:space' is 'preserve',
393
+ ## don't trim any white spaces
394
+ def trim(preserve = false)
395
+ if !attributes['xml:space'].nil?
396
+ value = attributes['xml:space'].nodeValue
397
+ if value == 'preserve'
398
+ preserve = true
399
+ elsif value == 'default'
400
+ preserve = false
401
+ end
402
+ end
403
+ return nil if @children.nil?
404
+ children = @children.to_a.dup
405
+ children.each do |child|
406
+ if !preserve && (child.nodeType == TEXT_NODE ||
407
+ child.nodeType == CDATA_SECTION_NODE)
408
+ if child.trim == ""
409
+ self.removeChild(child)
410
+ end
411
+ else
412
+ child.trim(preserve)
413
+ end
414
+ end
415
+ nil
416
+ end
417
+
418
+ ## [DOM2]
419
+ def namespaceURI; @uri; end
420
+
421
+ ## [DOM2]
422
+ def prefix; @prefix; end
423
+
424
+ ## [DOM2]
425
+ def prefix=(prefix);
426
+ ## to be checked
427
+ @prefix = prefix
428
+ @name = @prefix + ':' + @localname
429
+ @prefix.freeze
430
+ @name.freeze
431
+ end
432
+
433
+ ## [DOM2]
434
+ def localname; @localname; end
435
+
436
+ ## [DOM2]
437
+ def hasAttributes()
438
+ attributes.length > 0
439
+ end
440
+
441
+ ## [DOM2]
442
+ def getAttributeNS(nsuri, localname)
443
+ attr = getAttributeNodeNS(nsuri, localname)
444
+ if attr.nil?
445
+ ""
446
+ else
447
+ attr.nodeValue
448
+ end
449
+ end
450
+
451
+ ## [DOM2]
452
+ def setAttributeNS(nsuri, qname, value)
453
+ if qname.index(':')
454
+ prefix, localname = qname.split(':')
455
+ raise DOMException.new(DOMException::NAMESPACE_ERR) if
456
+ nsuri.nil? or
457
+ (prefix == 'xml' and
458
+ nsuri != 'http://www.w3.org/XML/1998/namespace')
459
+ else
460
+ raise DOMException.new(DOMException::NAMESPACE_ERR) if
461
+ qname == 'xmlns' and
462
+ nsuri != 'http://www.w3.org/2000/xmlns/'
463
+ end
464
+ attr = @ownerDocument.createAttributeNS(nsuri, qname)
465
+ attr.appendChild(@ownerDocument.createTextNode(value))
466
+ setAttributeNodeNS(attr)
467
+ end
468
+
469
+ ## [DOM2]
470
+ def removeAttributeNS(nsuri, localname)
471
+ ret = getAttributeNodeNS(nsuri, localname)
472
+ removeAttributeNode(ret) if ret
473
+ end
474
+
475
+ ## [DOM2]
476
+ def getAttributeNodeNS(nsuri, localname)
477
+ attributes.each do |attr|
478
+ return attr if
479
+ attr.namespaceURI == nsuri && attr.localname == localname
480
+ end
481
+ nil
482
+ end
483
+
484
+ ## [DOM2]
485
+ def setAttributeNodeNS(newAttr)
486
+ ret = getAttributeNodeNS(newAttr.namespaceURI, newAttr.localname)
487
+ removeAttributeNode(ret) if ret
488
+ setAttributeNode(newAttr)
489
+ ret
490
+ end
491
+
492
+ ## [DOM2]
493
+ def getElementsByTagNameNS(nsuri, localname)
494
+ ret = NodeList.new
495
+ @children.each do |node|
496
+ if node.nodeType == ELEMENT_NODE
497
+ if (localname == '*' || node.localname == localname) and
498
+ (nsuri == '*' || node.namespaceURI == nsuri)
499
+ ret << node
500
+ end
501
+ ret << node.getElementsByTagNameNS(nsuri, localname)
502
+ end
503
+ end if @children
504
+ ret
505
+ end
506
+
507
+ ## [DOM2]
508
+ def hasAttribute(name)
509
+ !getAttributeNode(name).nil?
510
+ end
511
+
512
+ ## [DOM2]
513
+ def hasAttributeNS(nsuri, localname)
514
+ !getAttributeNodeNS(nsuri, localname).nil?
515
+ end
516
+
517
+ def idAttribute; @idAttribute; end
518
+ def idAttribute=(name); @idAttribute = name; end
519
+
520
+ def _checkNode(node)
521
+ unless node.nodeType == ELEMENT_NODE ||
522
+ node.nodeType == TEXT_NODE ||
523
+ node.nodeType == COMMENT_NODE ||
524
+ node.nodeType == PROCESSING_INSTRUCTION_NODE ||
525
+ node.nodeType == CDATA_SECTION_NODE ||
526
+ node.nodeType == ENTITY_REFERENCE_NODE
527
+ raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
528
+ end
529
+ end
530
+
531
+ end
532
+ end
533
+ end