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,14 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Attributes
6
+ def to_h
7
+ inject({}) do |hash, attr|
8
+ hash[attr.name] = attr.value
9
+ hash
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,194 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Document
6
+ # call-seq:
7
+ # XML::Document.document(document) -> XML::Document
8
+ #
9
+ # Creates a new document based on the specified document.
10
+ #
11
+ # Parameters:
12
+ #
13
+ # document - A preparsed document.
14
+ def self.document(value)
15
+ Parser.document(value).parse
16
+ end
17
+
18
+ # call-seq:
19
+ # XML::Document.file(path) -> XML::Document
20
+ # XML::Document.file(path, :encoding => XML::Encoding::UTF_8,
21
+ # :options => XML::Parser::Options::NOENT) -> XML::Document
22
+ #
23
+ # Creates a new document from the specified file or uri.
24
+ #
25
+ # You may provide an optional hash table to control how the
26
+ # parsing is performed. Valid options are:
27
+ #
28
+ # encoding - The document encoding, defaults to nil. Valid values
29
+ # are the encoding constants defined on XML::Encoding.
30
+ # options - Parser options. Valid values are the constants defined on
31
+ # XML::Parser::Options. Mutliple options can be combined
32
+ # by using Bitwise OR (|).
33
+ def self.file(value, options = {})
34
+ Parser.file(value, options).parse
35
+ end
36
+
37
+ # call-seq:
38
+ # XML::Document.io(io) -> XML::Document
39
+ # XML::Document.io(io, :encoding => XML::Encoding::UTF_8,
40
+ # :options => XML::Parser::Options::NOENT
41
+ # :base_uri="http://libxml.org") -> XML::Document
42
+ #
43
+ # Creates a new document from the specified io object.
44
+ #
45
+ # Parameters:
46
+ #
47
+ # io - io object that contains the xml to parser
48
+ # base_uri - The base url for the parsed document.
49
+ # encoding - The document encoding, defaults to nil. Valid values
50
+ # are the encoding constants defined on XML::Encoding.
51
+ # options - Parser options. Valid values are the constants defined on
52
+ # XML::Parser::Options. Mutliple options can be combined
53
+ # by using Bitwise OR (|).
54
+ def self.io(value, options = {})
55
+ Parser.io(value, options).parse
56
+ end
57
+
58
+ # call-seq:
59
+ # XML::Document.string(string) -> XML::Document
60
+ # XML::Document.string(string, :encoding => XML::Encoding::UTF_8,
61
+ # :options => XML::Parser::Options::NOENT
62
+ # :base_uri="http://libxml.org") -> XML::Document
63
+ #
64
+ # Creates a new document from the specified string.
65
+ #
66
+ # You may provide an optional hash table to control how the
67
+ # parsing is performed. Valid options are:
68
+ #
69
+ # base_uri - The base url for the parsed document.
70
+ # encoding - The document encoding, defaults to nil. Valid values
71
+ # are the encoding constants defined on XML::Encoding.
72
+ # options - Parser options. Valid values are the constants defined on
73
+ # XML::Parser::Options. Mutliple options can be combined
74
+ # by using Bitwise OR (|).
75
+ def self.string(value, options = {})
76
+ Parser.string(value, options).parse
77
+ end
78
+
79
+ # Returns a new XML::XPathContext for the document.
80
+ #
81
+ # call-seq:
82
+ # document.context(namespaces=nil) -> XPath::Context
83
+ #
84
+ # Namespaces is an optional array of XML::NS objects
85
+ def context(nslist = nil)
86
+ context = XPath::Context.new(self)
87
+ context.node = self.root
88
+ context.register_namespaces_from_node(self.root)
89
+ context.register_namespaces(nslist) if nslist
90
+ context
91
+ end
92
+
93
+ # Return the nodes matching the specified xpath expression,
94
+ # optionally using the specified namespace. For more
95
+ # information about working with namespaces, please refer
96
+ # to the XML::XPath documentation.
97
+ #
98
+ # call-seq:
99
+ # document.find(xpath, nslist=nil) -> XML::XPath::Object
100
+ #
101
+ # Parameters:
102
+ # * xpath - The xpath expression as a string
103
+ # * namespaces - An optional list of namespaces (see XML::XPath for information).
104
+ #
105
+ # document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
106
+ #
107
+ # IMPORTANT - The returned XML::Node::Set must be freed before
108
+ # its associated document. In a running Ruby program this will
109
+ # happen automatically via Ruby's mark and sweep garbage collector.
110
+ # However, if the program exits, Ruby does not guarantee the order
111
+ # in which objects are freed
112
+ # (see http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/17700).
113
+ # As a result, the associated document may be freed before the node
114
+ # list, which will cause a segmentation fault.
115
+ # To avoid this, use the following (non-ruby like) coding style:
116
+ #
117
+ # nodes = doc.find('/header')
118
+ # nodes.each do |node|
119
+ # ... do stuff ...
120
+ # end
121
+ # # nodes = nil # GC.start
122
+ def find(xpath, nslist = nil)
123
+ self.context(nslist).find(xpath)
124
+ end
125
+
126
+ # Return the first node matching the specified xpath expression.
127
+ # For more information, please refer to the documentation
128
+ # for XML::Document#find.
129
+ def find_first(xpath, nslist = nil)
130
+ find(xpath, nslist).first
131
+ end
132
+
133
+ # Returns this node's type name
134
+ def node_type_name
135
+ case node_type
136
+ when XML::Node::DOCUMENT_NODE
137
+ 'document_xml'
138
+ when XML::Node::DOCB_DOCUMENT_NODE
139
+ 'document_docbook'
140
+ when XML::Node::HTML_DOCUMENT_NODE
141
+ 'document_html'
142
+ else
143
+ raise(UnknownType, "Unknown node type: %n", node.node_type);
144
+ end
145
+ end
146
+ # :enddoc:
147
+
148
+ # Specifies if this is an document node
149
+ def document?
150
+ node_type == XML::Node::DOCUMENT_NODE
151
+ end
152
+
153
+ # Specifies if this is an docbook node
154
+ def docbook_doc?
155
+ node_type == XML::Node::DOCB_DOCUMENT_NODE
156
+ end
157
+
158
+ # Specifies if this is an html node
159
+ def html_doc?
160
+ node_type == XML::Node::HTML_DOCUMENT_NODE
161
+ end
162
+
163
+ def dump
164
+ warn('Document#dump is deprecated. Use Document#to_s instead.')
165
+ self.to_s
166
+ end
167
+
168
+ def format_dump
169
+ warn('Document#format_dump is deprecated. Use Document#to_s instead.')
170
+ self.to_s
171
+ end
172
+
173
+ def debug_dump
174
+ warn('Document#debug_dump is deprecated. Use Document#debug instead.')
175
+ self.debug
176
+ end
177
+
178
+ def debug_dump_head
179
+ warn('Document#debug_dump_head is deprecated. Use Document#debug instead.')
180
+ self.debug
181
+ end
182
+
183
+ def debug_format_dump
184
+ warn('Document#debug_format_dump is deprecated. Use Document#to_s instead.')
185
+ self.to_s
186
+ end
187
+
188
+ def reader
189
+ warn('Document#reader is deprecated. Use XML::Reader.document(self) instead.')
190
+ XML::Reader.document(self)
191
+ end
192
+ end
193
+ end
194
+ end
@@ -0,0 +1,95 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Error
6
+ # Create mapping from domain constant value to keys
7
+ DOMAIN_CODE_MAP = [:NO_ERROR, :PARSER, :TREE, :NAMESPACE, :DTD, :HTML, :MEMORY,
8
+ :OUTPUT, :IO, :FTP, :HTTP, :XINCLUDE, :XPATH, :XPOINTER, :REGEXP,
9
+ :DATATYPE, :SCHEMASP, :SCHEMASV, :RELAXNGP, :RELAXNGV, :CATALOG,
10
+ :C14N, :XSLT, :VALID, :CHECK, :WRITER, :MODULE, :I18N, :SCHEMATRONV].inject(Hash.new) do |hash, code|
11
+ if const_defined?(code)
12
+ hash[const_get(code)] = code.to_s
13
+ end
14
+ hash
15
+ end
16
+
17
+ # Create mapping from domain constant value to keys
18
+ ERROR_CODE_MAP = Hash.new.tap do |map|
19
+ (constants -
20
+ DOMAIN_CODE_MAP.values - #Domains
21
+ [:NONE, :WARNING, :ERROR, :FATAL] # Levels
22
+ ).each do |code|
23
+ map[const_get(code)] = code.to_s
24
+ end
25
+ end
26
+
27
+ # Verbose error handler
28
+ VERBOSE_HANDLER = lambda do |error|
29
+ STDERR << error.to_s << "\n"
30
+ STDERR.flush
31
+ end
32
+
33
+ # Quiet error handler
34
+ QUIET_HANDLER = lambda do |error|
35
+ end
36
+
37
+ def ==(other)
38
+ eql?(other)
39
+ end
40
+
41
+ def eql?(other)
42
+ self.code == other.code and
43
+ self.domain == other.domain and
44
+ self.message == other.message and
45
+ self.level == other.level and
46
+ self.file == other.file and
47
+ self.line == other.line and
48
+ self.str1 == other.str1 and
49
+ self.str2 == other.str2 and
50
+ self.str3 == other.str3 and
51
+ self.int1 == other.int1 and
52
+ self.int2 == other.int2 and
53
+ self.ctxt == other.ctxt and
54
+ self.node == other.node
55
+ rescue
56
+ false
57
+ end
58
+
59
+ def level_to_s
60
+ case self.level
61
+ when NONE
62
+ ''
63
+ when WARNING
64
+ 'Warning:'
65
+ when ERROR
66
+ 'Error:'
67
+ when FATAL
68
+ 'Fatal error:'
69
+ end
70
+ end
71
+
72
+ def domain_to_s
73
+ DOMAIN_CODE_MAP[self.domain]
74
+ end
75
+
76
+ def code_to_s
77
+ ERROR_CODE_MAP[self.code]
78
+ end
79
+
80
+ def to_s
81
+ msg = super
82
+ msg = msg ? msg.strip: ''
83
+
84
+ if self.line
85
+ sprintf("%s %s at %s:%d.", self.level_to_s, msg,
86
+ self.file, self.line)
87
+ else
88
+ sprintf("%s %s.", self.level_to_s, msg)
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+
95
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::VERBOSE_HANDLER)
@@ -0,0 +1,78 @@
1
+ # encoding: UTF-8
2
+
3
+ ## Provide hpricot API for libxml. Provided by Michael Guterl,
4
+ ## inspired by http://thebogles.com/blog/an-hpricot-style-interface-to-libxml
5
+ #
6
+ #class String
7
+ # def to_libxml_doc
8
+ # xp = XML::Parser.new
9
+ # xp.string = self
10
+ # xp.parse
11
+ # end
12
+ #end
13
+ #
14
+ #module LibXML
15
+ # module XML
16
+ # class Document
17
+ # alias :search :find
18
+ # end
19
+ #
20
+ # class Node
21
+ # # find the child node with the given xpath
22
+ # def at(xpath)
23
+ # self.find_first(xpath)
24
+ # end
25
+ #
26
+ # # find the array of child nodes matching the given xpath
27
+ # def search(xpath)
28
+ # results = self.find(xpath).to_a
29
+ # if block_given?
30
+ # results.each do |result|
31
+ # yield result
32
+ # end
33
+ # end
34
+ # return results
35
+ # end
36
+ #
37
+ # def /(xpath)
38
+ # search(xpath)
39
+ # end
40
+ #
41
+ # # return the inner contents of this node as a string
42
+ # def inner_xml
43
+ # child.to_s
44
+ # end
45
+ #
46
+ # # alias for inner_xml
47
+ # def inner_html
48
+ # inner_xml
49
+ # end
50
+ #
51
+ # # return this node and its contents as an xml string
52
+ # def to_xml
53
+ # self.to_s
54
+ # end
55
+ #
56
+ # # alias for path
57
+ # def xpath
58
+ # self.path
59
+ # end
60
+ #
61
+ # def find_with_default_ns(xpath_expr, namespace=nil)
62
+ # find_base(xpath_expr, namespace || default_namespaces)
63
+ # end
64
+ #
65
+ # def find_first_with_default_ns(xpath_expr, namespace=nil)
66
+ # find_first_base(xpath_expr, namespace || default_namespaces)
67
+ # end
68
+ #
69
+ ## alias_method :find_base, :find unless method_defined?(:find_base)
70
+ ## alias_method :find, :find_with_default_ns
71
+ ## alias_method :find_first_base, :find_first unless method_defined?(:find_first_base)
72
+ ## alias_method :find_first, :find_first_with_default_ns
73
+ ## alias :child? :first?
74
+ ## alias :children? :first?
75
+ ## alias :child :first
76
+ # end
77
+ # end
78
+ #end
@@ -0,0 +1,96 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class HTMLParser
6
+ # call-seq:
7
+ # XML::HTMLParser.file(path) -> XML::HTMLParser
8
+ # XML::HTMLParser.file(path, :encoding => XML::Encoding::UTF_8,
9
+ # :options => XML::HTMLParser::Options::NOENT) -> XML::HTMLParser
10
+ #
11
+ # Creates a new parser by parsing the specified file or uri.
12
+ #
13
+ # You may provide an optional hash table to control how the
14
+ # parsing is performed. Valid options are:
15
+ #
16
+ # encoding - The document encoding, defaults to nil. Valid values
17
+ # are the encoding constants defined on XML::Encoding.
18
+ # options - Parser options. Valid values are the constants defined on
19
+ # XML::HTMLParser::Options. Mutliple options can be combined
20
+ # by using Bitwise OR (|).
21
+ def self.file(path, options = {})
22
+ context = XML::HTMLParser::Context.file(path)
23
+ context.encoding = options[:encoding] if options[:encoding]
24
+ context.options = options[:options] if options[:options]
25
+ self.new(context)
26
+ end
27
+
28
+ # call-seq:
29
+ # XML::HTMLParser.io(io) -> XML::HTMLParser
30
+ # XML::HTMLParser.io(io, :encoding => XML::Encoding::UTF_8,
31
+ # :options => XML::HTMLParser::Options::NOENT
32
+ # :base_uri="http://libxml.org") -> XML::HTMLParser
33
+ #
34
+ # Creates a new reader by parsing the specified io object.
35
+ #
36
+ # Parameters:
37
+ #
38
+ # io - io object that contains the xml to parser
39
+ # base_uri - The base url for the parsed document.
40
+ # encoding - The document encoding, defaults to nil. Valid values
41
+ # are the encoding constants defined on XML::Encoding.
42
+ # options - Parser options. Valid values are the constants defined on
43
+ # XML::HTMLParser::Options. Mutliple options can be combined
44
+ # by using Bitwise OR (|).
45
+ def self.io(io, options = {})
46
+ context = XML::HTMLParser::Context.io(io)
47
+ context.base_uri = options[:base_uri] if options[:base_uri]
48
+ context.encoding = options[:encoding] if options[:encoding]
49
+ context.options = options[:options] if options[:options]
50
+ self.new(context)
51
+ end
52
+
53
+ # call-seq:
54
+ # XML::HTMLParser.string(string)
55
+ # XML::HTMLParser.string(string, :encoding => XML::Encoding::UTF_8,
56
+ # :options => XML::HTMLParser::Options::NOENT
57
+ # :base_uri="http://libxml.org") -> XML::HTMLParser
58
+ #
59
+ # Creates a new parser by parsing the specified string.
60
+ #
61
+ # You may provide an optional hash table to control how the
62
+ # parsing is performed. Valid options are:
63
+ #
64
+ # base_uri - The base url for the parsed document.
65
+ # encoding - The document encoding, defaults to nil. Valid values
66
+ # are the encoding constants defined on XML::Encoding.
67
+ # options - Parser options. Valid values are the constants defined on
68
+ # XML::HTMLParser::Options. Mutliple options can be combined
69
+ # by using Bitwise OR (|).
70
+ def self.string(string, options = {})
71
+ context = XML::HTMLParser::Context.string(string)
72
+ context.base_uri = options[:base_uri] if options[:base_uri]
73
+ context.encoding = options[:encoding] if options[:encoding]
74
+ context.options = options[:options] if options[:options]
75
+ self.new(context)
76
+ end
77
+
78
+ # :enddoc:
79
+
80
+ def file=(value)
81
+ warn("XML::HTMLParser#file is deprecated. Use XML::HTMLParser.file instead")
82
+ @context = XML::HTMLParser::Context.file(value)
83
+ end
84
+
85
+ def io=(value)
86
+ warn("XML::HTMLParser#io is deprecated. Use XML::HTMLParser.io instead")
87
+ @context = XML::HTMLParser::Context.io(value)
88
+ end
89
+
90
+ def string=(value)
91
+ warn("XML::HTMLParser#string is deprecated. Use XML::HTMLParser.string instead")
92
+ @context = XML::HTMLParser::Context.string(value)
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Namespace
6
+ include Comparable
7
+ include Enumerable
8
+
9
+ # call-seq:
10
+ # namespace1 <=> namespace2
11
+ #
12
+ # Compares two namespace objects. Namespace objects are
13
+ # considered equal if their prefixes and hrefs are the same.
14
+ def <=>(other)
15
+ if self.prefix.nil? and other.prefix.nil?
16
+ self.href <=> other.href
17
+ elsif self.prefix.nil?
18
+ -1
19
+ elsif other.prefix.nil?
20
+ 1
21
+ else
22
+ self.prefix <=> other.prefix
23
+ end
24
+ end
25
+
26
+ # call-seq:
27
+ # namespace.each {|ns| .. }
28
+ #
29
+ # libxml stores namespaces in memory as a linked list.
30
+ # Use the each method to iterate over the list. Note
31
+ # the first namespace in the loop is the current namespace.
32
+ #
33
+ # Usage:
34
+ # namespace.each do |ns|
35
+ # ..
36
+ # end
37
+ def each
38
+ ns = self
39
+
40
+ while ns
41
+ yield ns
42
+ ns = ns.next
43
+ end
44
+ end
45
+
46
+ # call-seq:
47
+ # namespace.to_s -> "string"
48
+ #
49
+ # Returns the string represenation of a namespace.
50
+ #
51
+ # Usage:
52
+ # namespace.to_s
53
+ def to_s
54
+ if self.prefix
55
+ "#{self.prefix}:#{self.href}"
56
+ else
57
+ self.href
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: UTF-8
2
+
3
+ module LibXML
4
+ module XML
5
+ class Namespaces
6
+ # call-seq:
7
+ # namespace.default -> XML::Namespace
8
+ #
9
+ # Returns the default namespace for this node or nil.
10
+ #
11
+ # Usage:
12
+ # doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
13
+ # ns = doc.root.namespaces.default_namespace
14
+ # assert_equal(ns.href, 'http://schemas.xmlsoap.org/soap/envelope/')
15
+ def default
16
+ find_by_prefix(nil)
17
+ end
18
+
19
+ # call-seq:
20
+ # namespace.default_prefix = "string"
21
+ #
22
+ # Assigns a name (prefix) to the default namespace.
23
+ # This makes it much easier to perform XML::XPath
24
+ # searches.
25
+ #
26
+ # Usage:
27
+ # doc = XML::Document.string('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"/>')
28
+ # doc.root.namespaces.default_prefix = 'soap'
29
+ # node = doc.root.find_first('soap:Envelope')
30
+ def default_prefix=(prefix)
31
+ # Find default prefix
32
+ ns = find_by_prefix(nil)
33
+ raise(ArgumentError, "No default namespace was found") unless ns
34
+ Namespace.new(self.node, prefix, ns.href)
35
+ end
36
+ end
37
+ end
38
+ end