xmlparser 0.6.81
Sign up to get free protection for your applications and to get access to all the features.
- data/MANIFEST +112 -0
- data/README +697 -0
- data/README.ja +789 -0
- data/Rakefile +34 -0
- data/ext/encoding.h +91 -0
- data/ext/xmlparser/mkrf_conf.rb +28 -0
- data/ext/xmlparser/xmlparser.c +2226 -0
- data/lib/sax.rb +1 -0
- data/lib/saxdriver.rb +1 -0
- data/lib/wget.rb +47 -0
- data/lib/xml/dom/builder-ja.rb +58 -0
- data/lib/xml/dom/builder.rb +310 -0
- data/lib/xml/dom/core.rb +3276 -0
- data/lib/xml/dom/digest.rb +94 -0
- data/lib/xml/dom/visitor.rb +182 -0
- data/lib/xml/dom2/attr.rb +213 -0
- data/lib/xml/dom2/cdatasection.rb +76 -0
- data/lib/xml/dom2/characterdata.rb +177 -0
- data/lib/xml/dom2/comment.rb +81 -0
- data/lib/xml/dom2/core.rb +19 -0
- data/lib/xml/dom2/document.rb +317 -0
- data/lib/xml/dom2/documentfragment.rb +82 -0
- data/lib/xml/dom2/documenttype.rb +102 -0
- data/lib/xml/dom2/dombuilder.rb +277 -0
- data/lib/xml/dom2/dombuilderfilter.rb +12 -0
- data/lib/xml/dom2/domentityresolver.rb +13 -0
- data/lib/xml/dom2/domentityresolverimpl.rb +37 -0
- data/lib/xml/dom2/domexception.rb +95 -0
- data/lib/xml/dom2/domimplementation.rb +61 -0
- data/lib/xml/dom2/dominputsource.rb +29 -0
- data/lib/xml/dom2/element.rb +533 -0
- data/lib/xml/dom2/entity.rb +110 -0
- data/lib/xml/dom2/entityreference.rb +107 -0
- data/lib/xml/dom2/namednodemap.rb +138 -0
- data/lib/xml/dom2/node.rb +587 -0
- data/lib/xml/dom2/nodelist.rb +231 -0
- data/lib/xml/dom2/notation.rb +86 -0
- data/lib/xml/dom2/processinginstruction.rb +155 -0
- data/lib/xml/dom2/text.rb +128 -0
- data/lib/xml/dom2/xpath.rb +398 -0
- data/lib/xml/encoding-ja.rb +42 -0
- data/lib/xml/parser.rb +13 -0
- data/lib/xml/parserns.rb +236 -0
- data/lib/xml/sax.rb +353 -0
- data/lib/xml/saxdriver.rb +370 -0
- data/lib/xml/xpath.rb +3284 -0
- data/lib/xml/xpath.ry +2352 -0
- data/lib/xmldigest.rb +1 -0
- data/lib/xmltree.rb +1 -0
- data/lib/xmltreebuilder.rb +1 -0
- data/lib/xmltreevisitor.rb +1 -0
- metadata +111 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
## -*- Ruby -*-
|
2
|
+
## DOMHASH test implementation
|
3
|
+
## 1999 by yoshidam
|
4
|
+
##
|
5
|
+
## Apr 20, 1999 Change for draft-hiroshi-dom-hash-01.txt
|
6
|
+
##
|
7
|
+
|
8
|
+
require 'xml/dom/core'
|
9
|
+
require 'md5'
|
10
|
+
require 'uconv'
|
11
|
+
|
12
|
+
module XML
|
13
|
+
module DOM
|
14
|
+
|
15
|
+
def self.tou16(str)
|
16
|
+
Uconv.u16swap(Uconv.u8tou16(str))
|
17
|
+
end
|
18
|
+
|
19
|
+
class Node
|
20
|
+
def getDigest(force = false)
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Text
|
26
|
+
def getDigest(force = false)
|
27
|
+
(!force && @digest) ||
|
28
|
+
@digest = MD5.new([TEXT_NODE].pack("N") + DOM.tou16(nodeValue)).digest
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
## class Comment
|
33
|
+
## def getDigest(force = false)
|
34
|
+
## (!force && @digest) ||
|
35
|
+
## @digest = MD5.new([COMMENT_NODE].pack("N") + DOM.tou16(data)).digest
|
36
|
+
## end
|
37
|
+
## end
|
38
|
+
|
39
|
+
class ProcessingInstruction
|
40
|
+
def getDigest(force = false)
|
41
|
+
(!force && @digest) ||
|
42
|
+
@digest = MD5.new([PROCESSING_INSTRUCTION_NODE].pack("N") +
|
43
|
+
DOM.tou16(target) + "\0\0" + DOM.tou16(data)).digest
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class Attr
|
48
|
+
def getDigest(force = false)
|
49
|
+
(!force && @digest) ||
|
50
|
+
@digest = MD5.new([ATTRIBUTE_NODE].pack("N") +
|
51
|
+
DOM.tou16(nodeName) + "\0\0" + DOM.tou16(nodeValue)).digest
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class NamedNodeMap
|
56
|
+
include Enumerable
|
57
|
+
end
|
58
|
+
|
59
|
+
class NodeList
|
60
|
+
include Enumerable
|
61
|
+
end
|
62
|
+
|
63
|
+
class Element
|
64
|
+
def getDigest(force = false)
|
65
|
+
return @digest if (!force && @digest)
|
66
|
+
attr = attributes
|
67
|
+
children = childNodes
|
68
|
+
attr_digests = ""
|
69
|
+
children_digests = ""
|
70
|
+
if attr
|
71
|
+
attr_array = attr.sort {|a, b|
|
72
|
+
DOM.tou16(a.nodeName) <=> DOM.tou16(b.nodeName)}
|
73
|
+
attr_array.each {|a|
|
74
|
+
attr_digests << a.getDigest(force)
|
75
|
+
}
|
76
|
+
end
|
77
|
+
children_num = 0
|
78
|
+
children.each {|c|
|
79
|
+
next if c.nodeType == COMMENT_NODE
|
80
|
+
children_num += 1
|
81
|
+
children_digests << c.getDigest(force)
|
82
|
+
}
|
83
|
+
@digest = MD5.new([ELEMENT_NODE].pack("N") +
|
84
|
+
DOM.tou16(nodeName) +
|
85
|
+
"\0\0" +
|
86
|
+
[attr.length].pack("N") +
|
87
|
+
attr_digests +
|
88
|
+
[children_num].pack("N") +
|
89
|
+
children_digests).digest
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,182 @@
|
|
1
|
+
## -*- Ruby -*-
|
2
|
+
## XML::DOM::Visitor
|
3
|
+
## 1998 by yoshidam
|
4
|
+
##
|
5
|
+
## Oct 23, 1998 yoshidam Fix each
|
6
|
+
##
|
7
|
+
|
8
|
+
|
9
|
+
=begin
|
10
|
+
= XML::DOM::Visitor
|
11
|
+
|
12
|
+
== Module XML
|
13
|
+
|
14
|
+
=end
|
15
|
+
module XML
|
16
|
+
|
17
|
+
=begin
|
18
|
+
== Module XML::DOM (XML::SimpleTree)
|
19
|
+
|
20
|
+
=end
|
21
|
+
module DOM
|
22
|
+
|
23
|
+
=begin
|
24
|
+
== Class XML::DOM::Visitor
|
25
|
+
|
26
|
+
Skelton class of Visitor.
|
27
|
+
|
28
|
+
You can override the following methods and implement the other
|
29
|
+
"visit_TYPE" methods.
|
30
|
+
|
31
|
+
You should implement some "visit_name_NAME" methods and
|
32
|
+
"method_missing" method for accept_name.
|
33
|
+
|
34
|
+
=end
|
35
|
+
## Skeleton visitor
|
36
|
+
class Visitor
|
37
|
+
## You can override the following methods and implement the other
|
38
|
+
## "visit_TYPE" methods.
|
39
|
+
## You should implement some "visit_name_NAME" methods and
|
40
|
+
## "method_missing" method for accept_name.
|
41
|
+
|
42
|
+
=begin
|
43
|
+
=== Methods
|
44
|
+
|
45
|
+
--- Visitor#visit_Document(grove, *rest)
|
46
|
+
|
47
|
+
callback method.
|
48
|
+
=end
|
49
|
+
def visit_Document(grove, *rest)
|
50
|
+
grove.children_accept(self, *rest)
|
51
|
+
end
|
52
|
+
|
53
|
+
=begin
|
54
|
+
--- Visitor#visit_Element(element, *rest)
|
55
|
+
|
56
|
+
callback method.
|
57
|
+
=end
|
58
|
+
def visit_Element(element, *rest)
|
59
|
+
element.children_accept(self, *rest)
|
60
|
+
end
|
61
|
+
|
62
|
+
=begin
|
63
|
+
--- Visitor#visit_Text(text, *rest)
|
64
|
+
|
65
|
+
callback method.
|
66
|
+
=end
|
67
|
+
def visit_Text(text, *rest)
|
68
|
+
end
|
69
|
+
|
70
|
+
=begin
|
71
|
+
--- Visitor#visit_CDATASection(text, *rest)
|
72
|
+
|
73
|
+
callback method.
|
74
|
+
=end
|
75
|
+
def visit_CDATASection(text, *rest)
|
76
|
+
end
|
77
|
+
|
78
|
+
=begin
|
79
|
+
--- Visitor#visit_Comment(comment, *rest)
|
80
|
+
|
81
|
+
callback method.
|
82
|
+
=end
|
83
|
+
def visit_Comment(comment, *rest)
|
84
|
+
end
|
85
|
+
|
86
|
+
=begin
|
87
|
+
--- Visitor#visit_ProcessingInstruction(pi, *rest)
|
88
|
+
|
89
|
+
callback method.
|
90
|
+
=end
|
91
|
+
def visit_ProcessingInstruction(pi, *rest)
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
=begin
|
97
|
+
|
98
|
+
== Class XML::DOM::Node
|
99
|
+
|
100
|
+
XML::Grove::Visitor like interfaces.
|
101
|
+
=end
|
102
|
+
class Node
|
103
|
+
|
104
|
+
=begin
|
105
|
+
--- Node#accept(visitor, *rest)
|
106
|
+
|
107
|
+
call back visit_* method.
|
108
|
+
=end
|
109
|
+
## XML::Grove::Visitor like interfaces
|
110
|
+
def accept(visitor, *rest)
|
111
|
+
typename = self.class.to_s.sub(/.*?([^:]+)$/, '\1')
|
112
|
+
visitor.send("visit_" + typename, self, *rest)
|
113
|
+
end
|
114
|
+
|
115
|
+
=begin
|
116
|
+
--- Node#accept_name(visitor, *rest)
|
117
|
+
|
118
|
+
call back visit_name_* method.
|
119
|
+
=end
|
120
|
+
def accept_name(visitor, *rest)
|
121
|
+
if nodeType == ELEMENT_NODE
|
122
|
+
name_method = "visit_name_" + nodeName
|
123
|
+
visitor.send(name_method, self, *rest)
|
124
|
+
else
|
125
|
+
self.accept(visitor, *rest)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
=begin
|
130
|
+
--- Node#children_accept(visitor, *rest)
|
131
|
+
|
132
|
+
for each children, call back visit_* methods.
|
133
|
+
=end
|
134
|
+
def children_accept(visitor, *rest)
|
135
|
+
ret = []
|
136
|
+
@children && @children.each { |node|
|
137
|
+
ret.push(node.accept(visitor, *rest))
|
138
|
+
}
|
139
|
+
ret
|
140
|
+
end
|
141
|
+
|
142
|
+
=begin
|
143
|
+
--- Node#children_accept_name(visitor, *rest)
|
144
|
+
|
145
|
+
for each children, call back visit_name_* method.
|
146
|
+
=end
|
147
|
+
def children_accept_name(visitor, *rest)
|
148
|
+
ret = []
|
149
|
+
@children && @children.each { |node|
|
150
|
+
ret.push(node.accept_name(visitor, *rest))
|
151
|
+
}
|
152
|
+
ret
|
153
|
+
end
|
154
|
+
|
155
|
+
=begin
|
156
|
+
--- Node#each
|
157
|
+
|
158
|
+
iterator interface.
|
159
|
+
=end
|
160
|
+
## Iterator interface
|
161
|
+
include Enumerable
|
162
|
+
def each
|
163
|
+
sibstack = []
|
164
|
+
siblings = [ self ]
|
165
|
+
while true
|
166
|
+
if siblings.length == 0
|
167
|
+
break if sibstack.length == 0
|
168
|
+
siblings = sibstack.pop
|
169
|
+
next
|
170
|
+
end
|
171
|
+
node = siblings.shift
|
172
|
+
yield(node)
|
173
|
+
children = node.childNodes
|
174
|
+
if !children.nil?
|
175
|
+
sibstack.push(siblings)
|
176
|
+
siblings = children.to_a.dup
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
## -*- Ruby -*-
|
2
|
+
## XML::DOM
|
3
|
+
## 1998-2001 by yoshidam
|
4
|
+
##
|
5
|
+
|
6
|
+
require 'xml/dom2/node'
|
7
|
+
require 'xml/dom2/domexception'
|
8
|
+
|
9
|
+
module XML
|
10
|
+
module DOM
|
11
|
+
|
12
|
+
=begin
|
13
|
+
== Class XML::DOM::Attr
|
14
|
+
|
15
|
+
=== superclass
|
16
|
+
Node
|
17
|
+
|
18
|
+
=end
|
19
|
+
class Attr<Node
|
20
|
+
## new(name, [text1, text2, ...]) or
|
21
|
+
## new(name, text1, text2, ...)
|
22
|
+
## name: String
|
23
|
+
## text?: String or Node
|
24
|
+
|
25
|
+
=begin
|
26
|
+
=== Class Methods
|
27
|
+
|
28
|
+
--- Attr.new(name = nil, *text)
|
29
|
+
|
30
|
+
create a new Attr.
|
31
|
+
=end
|
32
|
+
def initialize(name, *text)
|
33
|
+
super(text)
|
34
|
+
raise "parameter error" if !name
|
35
|
+
@name = nil
|
36
|
+
@prefix = nil
|
37
|
+
@localname = nil
|
38
|
+
@uri = nil
|
39
|
+
@ownerElement = nil
|
40
|
+
if name.is_a?(Array)
|
41
|
+
## namespaces
|
42
|
+
raise "parameter error" if name.length != 2
|
43
|
+
@localname = name[1]
|
44
|
+
if name[1].index(':')
|
45
|
+
@prefix, @localname = name[1].split(':')
|
46
|
+
end
|
47
|
+
@name = name[1] ## qualified name
|
48
|
+
@uri = name[0] ## namespace URI
|
49
|
+
else
|
50
|
+
@name = name
|
51
|
+
end
|
52
|
+
@name.freeze
|
53
|
+
@prefix.freeze
|
54
|
+
@localname.freeze
|
55
|
+
@uri.freeze
|
56
|
+
end
|
57
|
+
|
58
|
+
=begin
|
59
|
+
=== Methods
|
60
|
+
|
61
|
+
--- Attr#nodeType()
|
62
|
+
|
63
|
+
[DOM]
|
64
|
+
returns the nodeType.
|
65
|
+
=end
|
66
|
+
## [DOM]
|
67
|
+
def nodeType
|
68
|
+
ATTRIBUTE_NODE
|
69
|
+
end
|
70
|
+
|
71
|
+
=begin
|
72
|
+
--- Attr#nodeName()
|
73
|
+
|
74
|
+
[DOM]
|
75
|
+
returns the nodeName.
|
76
|
+
=end
|
77
|
+
## [DOM]
|
78
|
+
def nodeName
|
79
|
+
@name
|
80
|
+
end
|
81
|
+
|
82
|
+
=begin
|
83
|
+
--- Attr#nodeValue()
|
84
|
+
|
85
|
+
[DOM]
|
86
|
+
returns the nodeValue.
|
87
|
+
=end
|
88
|
+
## [DOM]
|
89
|
+
def nodeValue
|
90
|
+
ret = ""
|
91
|
+
@children.each do |child|
|
92
|
+
ret << child.nodeValue
|
93
|
+
end if @children
|
94
|
+
ret
|
95
|
+
end
|
96
|
+
|
97
|
+
=begin
|
98
|
+
--- Attr#nodeValue=(text)
|
99
|
+
|
100
|
+
[DOM]
|
101
|
+
returns the value of this node.
|
102
|
+
=end
|
103
|
+
## [DOM]
|
104
|
+
def nodeValue=(text)
|
105
|
+
self.childNodes = [text]
|
106
|
+
end
|
107
|
+
|
108
|
+
=begin
|
109
|
+
--- Attr#to_s()
|
110
|
+
|
111
|
+
return the string representation of the Attr.
|
112
|
+
=end
|
113
|
+
def to_s
|
114
|
+
value = ""
|
115
|
+
nodeValue.scan(/./um) do |c|
|
116
|
+
code = c.unpack("U")[0]
|
117
|
+
if code == 9 || code == 10 || code == 13
|
118
|
+
value << sprintf("&#x%X;", code)
|
119
|
+
elsif c == "&"
|
120
|
+
value << "&"
|
121
|
+
elsif c == "\""
|
122
|
+
value << """
|
123
|
+
elsif c == "<"
|
124
|
+
value << "<"
|
125
|
+
else
|
126
|
+
value << c
|
127
|
+
end
|
128
|
+
end
|
129
|
+
"#{@name}=\"#{value}\""
|
130
|
+
end
|
131
|
+
|
132
|
+
=begin
|
133
|
+
--- Attr#dump(depth = 0)
|
134
|
+
|
135
|
+
dump the Attr.
|
136
|
+
=end
|
137
|
+
def dump(depth = 0)
|
138
|
+
print ' ' * depth * 2
|
139
|
+
print "// #{self.to_s}\n"
|
140
|
+
end
|
141
|
+
|
142
|
+
=begin
|
143
|
+
--- Attr#cloneNode(deep = true)
|
144
|
+
|
145
|
+
[DOM]
|
146
|
+
returns the copy of the Attr.
|
147
|
+
=end
|
148
|
+
## [DOM]
|
149
|
+
def cloneNode(deep = true)
|
150
|
+
super(deep, @name)
|
151
|
+
end
|
152
|
+
|
153
|
+
=begin
|
154
|
+
--- Attr#name()
|
155
|
+
|
156
|
+
[DOM]
|
157
|
+
alias of nodeName.
|
158
|
+
=end
|
159
|
+
## [DOM]
|
160
|
+
alias name nodeName
|
161
|
+
|
162
|
+
=begin
|
163
|
+
--- Attr#value()
|
164
|
+
|
165
|
+
alias of nodeValue.
|
166
|
+
|
167
|
+
--- Attr#value=(value)
|
168
|
+
|
169
|
+
[DOM]
|
170
|
+
alias of nodeValue=.
|
171
|
+
=end
|
172
|
+
## [DOM]
|
173
|
+
alias value nodeValue
|
174
|
+
alias value= nodeValue= ##
|
175
|
+
|
176
|
+
## [DOM]
|
177
|
+
def specified; @specified; end
|
178
|
+
def specified=(is_specified); @specified = is_specified; end
|
179
|
+
|
180
|
+
## [DOM2]
|
181
|
+
def namespaceURI; @uri; end
|
182
|
+
|
183
|
+
## [DOM2]
|
184
|
+
def prefix; @prefix; end
|
185
|
+
|
186
|
+
## [DOM2]
|
187
|
+
def prefix=(prefix);
|
188
|
+
## to be checked
|
189
|
+
|
190
|
+
@ownerElement.removeAttributeNode(self) if @ownerElement
|
191
|
+
@prefix = prefix
|
192
|
+
@name = @prefix + ':' + @localname
|
193
|
+
@ownerElement.setAttributeNode(self) if @ownerElement
|
194
|
+
@prefix.freeze
|
195
|
+
@name.freeze
|
196
|
+
end
|
197
|
+
|
198
|
+
## [DOM2]
|
199
|
+
def localname; @localname; end
|
200
|
+
|
201
|
+
## [DOM2]
|
202
|
+
def ownerElement; @ownerElement; end
|
203
|
+
def ownerElement=(elem); @ownerElement = elem; end
|
204
|
+
|
205
|
+
def _checkNode(node)
|
206
|
+
unless node.nodeType == TEXT_NODE ||
|
207
|
+
node.nodeType == ENTITY_REFERENCE_NODE
|
208
|
+
raise DOMException.new(DOMException::HIERARCHY_REQUEST_ERR)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|