libxml-ruby 3.2.2-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (205) hide show
  1. checksums.yaml +7 -0
  2. data/HISTORY +848 -0
  3. data/LICENSE +21 -0
  4. data/MANIFEST +166 -0
  5. data/README.rdoc +217 -0
  6. data/Rakefile +99 -0
  7. data/ext/libxml/extconf.rb +61 -0
  8. data/ext/libxml/libxml.c +80 -0
  9. data/ext/libxml/libxml_ruby.def +35 -0
  10. data/ext/libxml/ruby_libxml.h +67 -0
  11. data/ext/libxml/ruby_xml.c +933 -0
  12. data/ext/libxml/ruby_xml.h +10 -0
  13. data/ext/libxml/ruby_xml_attr.c +333 -0
  14. data/ext/libxml/ruby_xml_attr.h +12 -0
  15. data/ext/libxml/ruby_xml_attr_decl.c +153 -0
  16. data/ext/libxml/ruby_xml_attr_decl.h +11 -0
  17. data/ext/libxml/ruby_xml_attributes.c +275 -0
  18. data/ext/libxml/ruby_xml_attributes.h +15 -0
  19. data/ext/libxml/ruby_xml_cbg.c +85 -0
  20. data/ext/libxml/ruby_xml_document.c +1123 -0
  21. data/ext/libxml/ruby_xml_document.h +11 -0
  22. data/ext/libxml/ruby_xml_dtd.c +248 -0
  23. data/ext/libxml/ruby_xml_dtd.h +9 -0
  24. data/ext/libxml/ruby_xml_encoding.c +250 -0
  25. data/ext/libxml/ruby_xml_encoding.h +16 -0
  26. data/ext/libxml/ruby_xml_error.c +996 -0
  27. data/ext/libxml/ruby_xml_error.h +12 -0
  28. data/ext/libxml/ruby_xml_html_parser.c +89 -0
  29. data/ext/libxml/ruby_xml_html_parser.h +10 -0
  30. data/ext/libxml/ruby_xml_html_parser_context.c +337 -0
  31. data/ext/libxml/ruby_xml_html_parser_context.h +10 -0
  32. data/ext/libxml/ruby_xml_html_parser_options.c +46 -0
  33. data/ext/libxml/ruby_xml_html_parser_options.h +10 -0
  34. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  35. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  36. data/ext/libxml/ruby_xml_io.c +47 -0
  37. data/ext/libxml/ruby_xml_io.h +10 -0
  38. data/ext/libxml/ruby_xml_namespace.c +153 -0
  39. data/ext/libxml/ruby_xml_namespace.h +10 -0
  40. data/ext/libxml/ruby_xml_namespaces.c +293 -0
  41. data/ext/libxml/ruby_xml_namespaces.h +9 -0
  42. data/ext/libxml/ruby_xml_node.c +1402 -0
  43. data/ext/libxml/ruby_xml_node.h +13 -0
  44. data/ext/libxml/ruby_xml_parser.c +91 -0
  45. data/ext/libxml/ruby_xml_parser.h +12 -0
  46. data/ext/libxml/ruby_xml_parser_context.c +999 -0
  47. data/ext/libxml/ruby_xml_parser_context.h +10 -0
  48. data/ext/libxml/ruby_xml_parser_options.c +66 -0
  49. data/ext/libxml/ruby_xml_parser_options.h +12 -0
  50. data/ext/libxml/ruby_xml_reader.c +1239 -0
  51. data/ext/libxml/ruby_xml_reader.h +17 -0
  52. data/ext/libxml/ruby_xml_relaxng.c +110 -0
  53. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  54. data/ext/libxml/ruby_xml_sax2_handler.c +326 -0
  55. data/ext/libxml/ruby_xml_sax2_handler.h +10 -0
  56. data/ext/libxml/ruby_xml_sax_parser.c +116 -0
  57. data/ext/libxml/ruby_xml_sax_parser.h +10 -0
  58. data/ext/libxml/ruby_xml_schema.c +278 -0
  59. data/ext/libxml/ruby_xml_schema.h +809 -0
  60. data/ext/libxml/ruby_xml_schema_attribute.c +109 -0
  61. data/ext/libxml/ruby_xml_schema_attribute.h +15 -0
  62. data/ext/libxml/ruby_xml_schema_element.c +95 -0
  63. data/ext/libxml/ruby_xml_schema_element.h +14 -0
  64. data/ext/libxml/ruby_xml_schema_facet.c +52 -0
  65. data/ext/libxml/ruby_xml_schema_facet.h +13 -0
  66. data/ext/libxml/ruby_xml_schema_type.c +232 -0
  67. data/ext/libxml/ruby_xml_schema_type.h +9 -0
  68. data/ext/libxml/ruby_xml_version.h +9 -0
  69. data/ext/libxml/ruby_xml_writer.c +1133 -0
  70. data/ext/libxml/ruby_xml_writer.h +10 -0
  71. data/ext/libxml/ruby_xml_xinclude.c +16 -0
  72. data/ext/libxml/ruby_xml_xinclude.h +11 -0
  73. data/ext/libxml/ruby_xml_xpath.c +194 -0
  74. data/ext/libxml/ruby_xml_xpath.h +13 -0
  75. data/ext/libxml/ruby_xml_xpath_context.c +360 -0
  76. data/ext/libxml/ruby_xml_xpath_context.h +9 -0
  77. data/ext/libxml/ruby_xml_xpath_expression.c +81 -0
  78. data/ext/libxml/ruby_xml_xpath_expression.h +10 -0
  79. data/ext/libxml/ruby_xml_xpath_object.c +338 -0
  80. data/ext/libxml/ruby_xml_xpath_object.h +17 -0
  81. data/ext/libxml/ruby_xml_xpointer.c +99 -0
  82. data/ext/libxml/ruby_xml_xpointer.h +11 -0
  83. data/ext/vc/libxml_ruby.sln +28 -0
  84. data/lib/3.1/libxml_ruby.so +0 -0
  85. data/lib/libxml/attr.rb +123 -0
  86. data/lib/libxml/attr_decl.rb +80 -0
  87. data/lib/libxml/attributes.rb +14 -0
  88. data/lib/libxml/document.rb +194 -0
  89. data/lib/libxml/error.rb +95 -0
  90. data/lib/libxml/hpricot.rb +78 -0
  91. data/lib/libxml/html_parser.rb +96 -0
  92. data/lib/libxml/namespace.rb +62 -0
  93. data/lib/libxml/namespaces.rb +38 -0
  94. data/lib/libxml/node.rb +323 -0
  95. data/lib/libxml/parser.rb +101 -0
  96. data/lib/libxml/sax_callbacks.rb +180 -0
  97. data/lib/libxml/sax_parser.rb +41 -0
  98. data/lib/libxml/schema/attribute.rb +19 -0
  99. data/lib/libxml/schema/element.rb +19 -0
  100. data/lib/libxml/schema/type.rb +21 -0
  101. data/lib/libxml/schema.rb +48 -0
  102. data/lib/libxml/tree.rb +29 -0
  103. data/lib/libxml-ruby.rb +30 -0
  104. data/lib/libxml.rb +5 -0
  105. data/lib/xml/libxml.rb +10 -0
  106. data/lib/xml.rb +14 -0
  107. data/libxml-ruby.gemspec +48 -0
  108. data/script/benchmark/depixelate +634 -0
  109. data/script/benchmark/hamlet.xml +9055 -0
  110. data/script/benchmark/parsecount +170 -0
  111. data/script/benchmark/sock_entries.xml +507 -0
  112. data/script/benchmark/throughput +41 -0
  113. data/script/test +6 -0
  114. data/setup.rb +1584 -0
  115. data/test/c14n/given/doc.dtd +1 -0
  116. data/test/c14n/given/example-1.xml +14 -0
  117. data/test/c14n/given/example-2.xml +11 -0
  118. data/test/c14n/given/example-3.xml +18 -0
  119. data/test/c14n/given/example-4.xml +9 -0
  120. data/test/c14n/given/example-5.xml +12 -0
  121. data/test/c14n/given/example-6.xml +2 -0
  122. data/test/c14n/given/example-7.xml +11 -0
  123. data/test/c14n/given/example-8.xml +11 -0
  124. data/test/c14n/given/example-8.xpath +10 -0
  125. data/test/c14n/given/world.txt +1 -0
  126. data/test/c14n/result/1-1-without-comments/example-1 +4 -0
  127. data/test/c14n/result/1-1-without-comments/example-2 +11 -0
  128. data/test/c14n/result/1-1-without-comments/example-3 +14 -0
  129. data/test/c14n/result/1-1-without-comments/example-4 +9 -0
  130. data/test/c14n/result/1-1-without-comments/example-5 +3 -0
  131. data/test/c14n/result/1-1-without-comments/example-6 +1 -0
  132. data/test/c14n/result/1-1-without-comments/example-7 +1 -0
  133. data/test/c14n/result/1-1-without-comments/example-8 +1 -0
  134. data/test/c14n/result/with-comments/example-1 +6 -0
  135. data/test/c14n/result/with-comments/example-2 +11 -0
  136. data/test/c14n/result/with-comments/example-3 +14 -0
  137. data/test/c14n/result/with-comments/example-4 +9 -0
  138. data/test/c14n/result/with-comments/example-5 +4 -0
  139. data/test/c14n/result/with-comments/example-6 +1 -0
  140. data/test/c14n/result/with-comments/example-7 +1 -0
  141. data/test/c14n/result/without-comments/example-1 +4 -0
  142. data/test/c14n/result/without-comments/example-2 +11 -0
  143. data/test/c14n/result/without-comments/example-3 +14 -0
  144. data/test/c14n/result/without-comments/example-4 +9 -0
  145. data/test/c14n/result/without-comments/example-5 +3 -0
  146. data/test/c14n/result/without-comments/example-6 +1 -0
  147. data/test/c14n/result/without-comments/example-7 +1 -0
  148. data/test/model/atom.xml +13 -0
  149. data/test/model/bands.iso-8859-1.xml +5 -0
  150. data/test/model/bands.utf-8.xml +5 -0
  151. data/test/model/bands.xml +5 -0
  152. data/test/model/books.xml +154 -0
  153. data/test/model/cwm_1_0.xml +11336 -0
  154. data/test/model/merge_bug_data.xml +58 -0
  155. data/test/model/ruby-lang.html +238 -0
  156. data/test/model/rubynet.xml +79 -0
  157. data/test/model/rubynet_project +1 -0
  158. data/test/model/shiporder.rnc +28 -0
  159. data/test/model/shiporder.rng +86 -0
  160. data/test/model/shiporder.xml +23 -0
  161. data/test/model/shiporder.xsd +40 -0
  162. data/test/model/soap.xml +27 -0
  163. data/test/model/xinclude.xml +5 -0
  164. data/test/test_attr.rb +181 -0
  165. data/test/test_attr_decl.rb +132 -0
  166. data/test/test_attributes.rb +136 -0
  167. data/test/test_canonicalize.rb +120 -0
  168. data/test/test_deprecated_require.rb +12 -0
  169. data/test/test_document.rb +132 -0
  170. data/test/test_document_write.rb +146 -0
  171. data/test/test_dtd.rb +129 -0
  172. data/test/test_encoding.rb +129 -0
  173. data/test/test_encoding_sax.rb +115 -0
  174. data/test/test_error.rb +178 -0
  175. data/test/test_helper.rb +9 -0
  176. data/test/test_html_parser.rb +162 -0
  177. data/test/test_html_parser_context.rb +23 -0
  178. data/test/test_namespace.rb +60 -0
  179. data/test/test_namespaces.rb +200 -0
  180. data/test/test_node.rb +237 -0
  181. data/test/test_node_cdata.rb +50 -0
  182. data/test/test_node_comment.rb +32 -0
  183. data/test/test_node_copy.rb +40 -0
  184. data/test/test_node_edit.rb +158 -0
  185. data/test/test_node_pi.rb +37 -0
  186. data/test/test_node_text.rb +69 -0
  187. data/test/test_node_write.rb +97 -0
  188. data/test/test_node_xlink.rb +28 -0
  189. data/test/test_parser.rb +324 -0
  190. data/test/test_parser_context.rb +198 -0
  191. data/test/test_properties.rb +38 -0
  192. data/test/test_reader.rb +364 -0
  193. data/test/test_relaxng.rb +53 -0
  194. data/test/test_sax_parser.rb +326 -0
  195. data/test/test_schema.rb +168 -0
  196. data/test/test_suite.rb +48 -0
  197. data/test/test_traversal.rb +152 -0
  198. data/test/test_writer.rb +468 -0
  199. data/test/test_xinclude.rb +20 -0
  200. data/test/test_xml.rb +263 -0
  201. data/test/test_xpath.rb +244 -0
  202. data/test/test_xpath_context.rb +88 -0
  203. data/test/test_xpath_expression.rb +37 -0
  204. data/test/test_xpointer.rb +72 -0
  205. metadata +325 -0
@@ -0,0 +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
@@ -0,0 +1,101 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Parser
6
+ # call-seq:
7
+ # XML::Parser.document(document) -> XML::Parser
8
+ #
9
+ # Creates a new parser for the specified document.
10
+ #
11
+ # Parameters:
12
+ #
13
+ # document - A preparsed document.
14
+ def self.document(doc)
15
+ context = XML::Parser::Context.document(doc)
16
+ self.new(context)
17
+ end
18
+
19
+ # call-seq:
20
+ # XML::Parser.file(path) -> XML::Parser
21
+ # XML::Parser.file(path, :encoding => XML::Encoding::UTF_8,
22
+ # :options => XML::Parser::Options::NOENT) -> XML::Parser
23
+ #
24
+ # Creates a new parser for the specified file or uri.
25
+ #
26
+ # You may provide an optional hash table to control how the
27
+ # parsing is performed. Valid options are:
28
+ #
29
+ # encoding - The document encoding, defaults to nil. Valid values
30
+ # are the encoding constants defined on XML::Encoding.
31
+ # options - Parser options. Valid values are the constants defined on
32
+ # XML::Parser::Options. Mutliple options can be combined
33
+ # by using Bitwise OR (|).
34
+ def self.file(path, options = {})
35
+ context = XML::Parser::Context.file(path)
36
+ context.encoding = options[:encoding] if options[:encoding]
37
+ context.options = options[:options] if options[:options]
38
+ self.new(context)
39
+ end
40
+
41
+ # call-seq:
42
+ # XML::Parser.io(io) -> XML::Parser
43
+ # XML::Parser.io(io, :encoding => XML::Encoding::UTF_8,
44
+ # :options => XML::Parser::Options::NOENT
45
+ # :base_uri="http://libxml.org") -> XML::Parser
46
+ #
47
+ # Creates a new parser for the specified io object.
48
+ #
49
+ # Parameters:
50
+ #
51
+ # io - io object that contains the xml to parser
52
+ # base_uri - The base url for the parsed document.
53
+ # encoding - The document encoding, defaults to nil. Valid values
54
+ # are the encoding constants defined on XML::Encoding.
55
+ # options - Parser options. Valid values are the constants defined on
56
+ # XML::Parser::Options. Mutliple options can be combined
57
+ # by using Bitwise OR (|).
58
+ def self.io(io, options = {})
59
+ context = XML::Parser::Context.io(io)
60
+ context.base_uri = options[:base_uri] if options[:base_uri]
61
+ context.encoding = options[:encoding] if options[:encoding]
62
+ context.options = options[:options] if options[:options]
63
+ self.new(context)
64
+ end
65
+
66
+ # call-seq:
67
+ # XML::Parser.string(string)
68
+ # XML::Parser.string(string, :encoding => XML::Encoding::UTF_8,
69
+ # :options => XML::Parser::Options::NOENT
70
+ # :base_uri="http://libxml.org") -> XML::Parser
71
+ #
72
+ # Creates a new parser by parsing the specified string.
73
+ #
74
+ # You may provide an optional hash table to control how the
75
+ # parsing is performed. Valid options are:
76
+ #
77
+ # base_uri - The base url for the parsed document.
78
+ # encoding - The document encoding, defaults to nil. Valid values
79
+ # are the encoding constants defined on XML::Encoding.
80
+ # options - Parser options. Valid values are the constants defined on
81
+ # XML::Parser::Options. Mutliple options can be combined
82
+ # by using Bitwise OR (|).
83
+ def self.string(string, options = {})
84
+ context = XML::Parser::Context.string(string)
85
+ context.base_uri = options[:base_uri] if options[:base_uri]
86
+ context.encoding = options[:encoding] if options[:encoding]
87
+ context.options = options[:options] if options[:options]
88
+ self.new(context)
89
+ end
90
+
91
+ def self.register_error_handler(proc)
92
+ warn('Parser.register_error_handler is deprecated. Use Error.set_handler instead')
93
+ if proc.nil?
94
+ Error.reset_handler
95
+ else
96
+ Error.set_handler(&proc)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,180 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class SaxParser
6
+ module Callbacks
7
+ # Called for a CDATA block event.
8
+ def on_cdata_block(cdata)
9
+ end
10
+
11
+ # Called for a characters event.
12
+ def on_characters(chars)
13
+ end
14
+
15
+ # Called for a comment event.
16
+ def on_comment(msg)
17
+ end
18
+
19
+ # Called for a end document event.
20
+ def on_end_document
21
+ end
22
+
23
+ # Called for a end element event.
24
+ def on_end_element_ns(name, prefix, uri)
25
+ end
26
+
27
+ # Called for parser errors.
28
+ def on_error(msg)
29
+ end
30
+
31
+ # Called for an external subset event.
32
+ def on_external_subset(name, external_id, system_id)
33
+ end
34
+
35
+ # Called for an external subset notification event.
36
+ def on_has_external_subset
37
+ end
38
+
39
+ # Called for an internal subset notification event.
40
+ def on_has_internal_subset
41
+ end
42
+
43
+ # Called for an internal subset event.
44
+ def on_internal_subset(name, external_id, system_id)
45
+ end
46
+
47
+ # Called for 'is standalone' event.
48
+ def on_is_standalone
49
+ end
50
+
51
+ # Called for an processing instruction event.
52
+ def on_processing_instruction(target, data)
53
+ end
54
+
55
+ # Called for a reference event.
56
+ def on_reference(name)
57
+ end
58
+
59
+ # Called for a start document event.
60
+ def on_start_document
61
+ end
62
+
63
+ # Called for a start element event.
64
+ def on_start_element_ns(name, attributes, prefix, uri, namespaces)
65
+ end
66
+ end
67
+
68
+ module VerboseCallbacks
69
+ # Called for a CDATA block event.
70
+ def on_cdata_block(cdata)
71
+ STDOUT << "on_cdata_block" << "\n" <<
72
+ " cdata " << cdata << "\n"
73
+ STDOUT.flush
74
+ end
75
+
76
+ # Called for a characters event.
77
+ def on_characters(chars)
78
+ STDOUT << "on_characters" << "\n" <<
79
+ " chars " << chars << "\n"
80
+ STDOUT.flush
81
+ end
82
+
83
+ # Called for a comment event.
84
+ def on_comment(comment)
85
+ STDOUT << "on_comment" << "\n" <<
86
+ " comment: " << comment << "\n"
87
+ STDOUT.flush
88
+ end
89
+
90
+ # Called for a end document event.
91
+ def on_end_document
92
+ STDOUT << "on_end_document\n"
93
+ STDOUT.flush
94
+ end
95
+
96
+ # Called for a end element event.
97
+ def on_end_element_ns(name, prefix, uri)
98
+ STDOUT << "on_end_element_ns" << "\n" <<
99
+ " name: " << name << "\n" <<
100
+ " prefix: " << prefix << "\n" <<
101
+ " uri: " << uri << "\n"
102
+ STDOUT.flush
103
+ end
104
+
105
+ # Called for parser errors.
106
+ def on_error(error)
107
+ STDOUT << "on_error" << "\n"
108
+ " error " << error << "\n"
109
+ STDOUT.flush
110
+ end
111
+
112
+ # Called for an external subset event.
113
+ def on_external_subset(name, external_id, system_id)
114
+ STDOUT << "on_external_subset" << "\n"
115
+ " external_id " << external_id << "\n" <<
116
+ " system_id " << system_id << "\n"
117
+ STDOUT.flush
118
+ end
119
+
120
+ # Called for an external subset notification event.
121
+ def on_has_external_subset
122
+ STDOUT << "on_has_internal_subset\n"
123
+ STDOUT.flush
124
+ end
125
+
126
+ # Called for an internal subset notification event.
127
+ def on_has_internal_subset
128
+ STDOUT << "on_has_internal_subset\n"
129
+ STDOUT.flush
130
+ end
131
+
132
+ # Called for an internal subset event.
133
+ def on_internal_subset(name, external_id, system_id)
134
+ STDOUT << "on_internal_subset" << "\n"
135
+ " external_id " << external_id << "\n" <<
136
+ " system_id " << system_id << "\n"
137
+ STDOUT.flush
138
+ end
139
+
140
+ # Called for 'is standalone' event.
141
+ def on_is_standalone
142
+ STDOUT << "on_is_standalone\n"
143
+ STDOUT.flush
144
+ end
145
+
146
+ # Called for an processing instruction event.
147
+ def on_processing_instruction(target, data)
148
+ STDOUT << "on_characters" << "\n"
149
+ " target: " << target << "\n" <<
150
+ " data: " << data << "\n"
151
+ STDOUT.flush
152
+ end
153
+
154
+ # Called for a reference event.
155
+ def on_reference(name)
156
+ STDOUT << "on_reference:" << "\n" <<
157
+ " name:" << name << "\n"
158
+ STDOUT.flush
159
+ end
160
+
161
+ # Called for a start document event.
162
+ def on_start_document
163
+ STDOUT << "on_start_document\n"
164
+ STDOUT.flush
165
+ end
166
+
167
+ # Called for a start element event.
168
+ def on_start_element_ns(name, attributes, prefix, uri, namespaces)
169
+ STDOUT << "on_start_element_ns" << "\n" <<
170
+ " name: " << name << "\n" <<
171
+ " attr: " << (attributes || Hash.new).inspect << "\n" <<
172
+ " prefix: " << prefix << "\n" <<
173
+ " uri: " << uri << "\n" <<
174
+ " ns_defs: " << (namespaces || Hash.new).inspect << "\n"
175
+ STDOUT.flush
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class SaxParser
6
+ # call-seq:
7
+ # XML::SaxParser.file(path) -> XML::SaxParser
8
+ #
9
+ # Creates a new parser by parsing the specified file or uri.
10
+ def self.file(path)
11
+ context = XML::Parser::Context.file(path)
12
+ self.new(context)
13
+ end
14
+
15
+ # call-seq:
16
+ # XML::SaxParser.io(io) -> XML::SaxParser
17
+ # XML::SaxParser.io(io, :encoding => XML::Encoding::UTF_8) -> XML::SaxParser
18
+ #
19
+ # Creates a new reader by parsing the specified io object.
20
+ #
21
+ # Parameters:
22
+ #
23
+ # encoding - The document encoding, defaults to nil. Valid values
24
+ # are the encoding constants defined on XML::Encoding.
25
+ def self.io(io, options = {})
26
+ context = XML::Parser::Context.io(io)
27
+ context.encoding = options[:encoding] if options[:encoding]
28
+ self.new(context)
29
+ end
30
+
31
+ # call-seq:
32
+ # XML::SaxParser.string(string)
33
+ #
34
+ # Creates a new parser by parsing the specified string.
35
+ def self.string(string)
36
+ context = XML::Parser::Context.string(string)
37
+ self.new(context)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Schema::Attribute
6
+ REQUIRED = 1
7
+ OPTIONAL = 2
8
+
9
+ def default
10
+ node['default']
11
+ end
12
+
13
+ def required?
14
+ occurs == REQUIRED
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Schema::Element
6
+ def required?
7
+ !min_occurs.zero?
8
+ end
9
+
10
+ def array?
11
+ max_occurs > 1
12
+ end
13
+
14
+ def elements
15
+ type.elements
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ module LibXML
2
+ module XML
3
+ class Schema::Type
4
+ def kind_name
5
+ Schema::Types.constants.find { |k| Schema::Types.const_get(k) == kind }
6
+ end
7
+
8
+ def annonymus_subtypes
9
+ elements.select { |_, e| e.type.name.nil? }
10
+ end
11
+
12
+ def annonymus_subtypes_recursively(parent=nil)
13
+ annonymus_subtypes.map do |element_name, e|
14
+ [{[parent, element_name].compact.join('::') => e.type},
15
+ e.type.annonymus_subtypes_recursively(element_name)]
16
+ end.flatten
17
+ end
18
+
19
+ end
20
+ end
21
+ end