nokogiri 1.0.0 → 1.6.8.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (309) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +26 -0
  3. data/.cross_rubies +9 -0
  4. data/.editorconfig +17 -0
  5. data/.gemtest +0 -0
  6. data/.travis.yml +51 -0
  7. data/CHANGELOG.rdoc +1160 -0
  8. data/CONTRIBUTING.md +42 -0
  9. data/C_CODING_STYLE.rdoc +33 -0
  10. data/Gemfile +22 -0
  11. data/LICENSE.txt +31 -0
  12. data/Manifest.txt +284 -40
  13. data/README.md +166 -0
  14. data/ROADMAP.md +111 -0
  15. data/Rakefile +310 -199
  16. data/STANDARD_RESPONSES.md +47 -0
  17. data/Y_U_NO_GEMSPEC.md +155 -0
  18. data/appveyor.yml +22 -0
  19. data/bin/nokogiri +118 -0
  20. data/build_all +45 -0
  21. data/dependencies.yml +29 -0
  22. data/ext/nokogiri/depend +358 -0
  23. data/ext/nokogiri/extconf.rb +664 -34
  24. data/ext/nokogiri/html_document.c +120 -33
  25. data/ext/nokogiri/html_document.h +1 -1
  26. data/ext/nokogiri/html_element_description.c +279 -0
  27. data/ext/nokogiri/html_element_description.h +10 -0
  28. data/ext/nokogiri/html_entity_lookup.c +32 -0
  29. data/ext/nokogiri/html_entity_lookup.h +8 -0
  30. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  31. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  32. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  33. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  34. data/ext/nokogiri/nokogiri.c +145 -0
  35. data/ext/nokogiri/nokogiri.h +131 -0
  36. data/ext/nokogiri/xml_attr.c +94 -0
  37. data/ext/nokogiri/xml_attr.h +9 -0
  38. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  39. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  40. data/ext/nokogiri/xml_cdata.c +23 -19
  41. data/ext/nokogiri/xml_cdata.h +1 -1
  42. data/ext/nokogiri/xml_comment.c +69 -0
  43. data/ext/nokogiri/xml_comment.h +9 -0
  44. data/ext/nokogiri/xml_document.c +501 -54
  45. data/ext/nokogiri/xml_document.h +14 -1
  46. data/ext/nokogiri/xml_document_fragment.c +48 -0
  47. data/ext/nokogiri/xml_document_fragment.h +10 -0
  48. data/ext/nokogiri/xml_dtd.c +109 -24
  49. data/ext/nokogiri/xml_dtd.h +3 -1
  50. data/ext/nokogiri/xml_element_content.c +123 -0
  51. data/ext/nokogiri/xml_element_content.h +10 -0
  52. data/ext/nokogiri/xml_element_decl.c +69 -0
  53. data/ext/nokogiri/xml_element_decl.h +9 -0
  54. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  55. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  56. data/ext/nokogiri/xml_entity_decl.c +110 -0
  57. data/ext/nokogiri/xml_entity_decl.h +10 -0
  58. data/ext/nokogiri/xml_entity_reference.c +52 -0
  59. data/ext/nokogiri/xml_entity_reference.h +9 -0
  60. data/ext/nokogiri/xml_io.c +60 -0
  61. data/ext/nokogiri/xml_io.h +11 -0
  62. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  63. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  64. data/ext/nokogiri/xml_namespace.c +117 -0
  65. data/ext/nokogiri/xml_namespace.h +13 -0
  66. data/ext/nokogiri/xml_node.c +1285 -315
  67. data/ext/nokogiri/xml_node.h +4 -6
  68. data/ext/nokogiri/xml_node_set.c +415 -54
  69. data/ext/nokogiri/xml_node_set.h +6 -2
  70. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  71. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  72. data/ext/nokogiri/xml_reader.c +316 -77
  73. data/ext/nokogiri/xml_reader.h +1 -1
  74. data/ext/nokogiri/xml_relax_ng.c +161 -0
  75. data/ext/nokogiri/xml_relax_ng.h +9 -0
  76. data/ext/nokogiri/xml_sax_parser.c +215 -80
  77. data/ext/nokogiri/xml_sax_parser.h +30 -1
  78. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  79. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  80. data/ext/nokogiri/xml_sax_push_parser.c +115 -0
  81. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  82. data/ext/nokogiri/xml_schema.c +205 -0
  83. data/ext/nokogiri/xml_schema.h +9 -0
  84. data/ext/nokogiri/xml_syntax_error.c +45 -175
  85. data/ext/nokogiri/xml_syntax_error.h +4 -2
  86. data/ext/nokogiri/xml_text.c +37 -14
  87. data/ext/nokogiri/xml_text.h +1 -1
  88. data/ext/nokogiri/xml_xpath_context.c +230 -13
  89. data/ext/nokogiri/xml_xpath_context.h +2 -1
  90. data/ext/nokogiri/xslt_stylesheet.c +196 -34
  91. data/ext/nokogiri/xslt_stylesheet.h +6 -1
  92. data/lib/nokogiri/css/node.rb +18 -61
  93. data/lib/nokogiri/css/parser.rb +725 -17
  94. data/lib/nokogiri/css/parser.y +126 -63
  95. data/lib/nokogiri/css/parser_extras.rb +91 -0
  96. data/lib/nokogiri/css/syntax_error.rb +7 -0
  97. data/lib/nokogiri/css/tokenizer.rb +148 -5
  98. data/lib/nokogiri/css/tokenizer.rex +31 -39
  99. data/lib/nokogiri/css/xpath_visitor.rb +109 -51
  100. data/lib/nokogiri/css.rb +24 -3
  101. data/lib/nokogiri/decorators/slop.rb +42 -0
  102. data/lib/nokogiri/html/builder.rb +27 -1
  103. data/lib/nokogiri/html/document.rb +329 -3
  104. data/lib/nokogiri/html/document_fragment.rb +39 -0
  105. data/lib/nokogiri/html/element_description.rb +23 -0
  106. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  107. data/lib/nokogiri/html/entity_lookup.rb +13 -0
  108. data/lib/nokogiri/html/sax/parser.rb +35 -4
  109. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  110. data/lib/nokogiri/html/sax/push_parser.rb +36 -0
  111. data/lib/nokogiri/html.rb +18 -76
  112. data/lib/nokogiri/syntax_error.rb +4 -0
  113. data/lib/nokogiri/version.rb +106 -1
  114. data/lib/nokogiri/xml/attr.rb +14 -0
  115. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  116. data/lib/nokogiri/xml/builder.rb +395 -31
  117. data/lib/nokogiri/xml/cdata.rb +4 -2
  118. data/lib/nokogiri/xml/character_data.rb +7 -0
  119. data/lib/nokogiri/xml/document.rb +267 -12
  120. data/lib/nokogiri/xml/document_fragment.rb +149 -0
  121. data/lib/nokogiri/xml/dtd.rb +27 -1
  122. data/lib/nokogiri/xml/element_content.rb +36 -0
  123. data/lib/nokogiri/xml/element_decl.rb +13 -0
  124. data/lib/nokogiri/xml/entity_decl.rb +19 -0
  125. data/lib/nokogiri/xml/namespace.rb +13 -0
  126. data/lib/nokogiri/xml/node/save_options.rb +61 -0
  127. data/lib/nokogiri/xml/node.rb +748 -109
  128. data/lib/nokogiri/xml/node_set.rb +200 -72
  129. data/lib/nokogiri/xml/parse_options.rb +120 -0
  130. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  131. data/lib/nokogiri/xml/pp/node.rb +56 -0
  132. data/lib/nokogiri/xml/pp.rb +2 -0
  133. data/lib/nokogiri/xml/processing_instruction.rb +8 -0
  134. data/lib/nokogiri/xml/reader.rb +102 -4
  135. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  136. data/lib/nokogiri/xml/sax/document.rb +114 -2
  137. data/lib/nokogiri/xml/sax/parser.rb +97 -7
  138. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  139. data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
  140. data/lib/nokogiri/xml/sax.rb +2 -7
  141. data/lib/nokogiri/xml/schema.rb +63 -0
  142. data/lib/nokogiri/xml/searchable.rb +221 -0
  143. data/lib/nokogiri/xml/syntax_error.rb +27 -1
  144. data/lib/nokogiri/xml/text.rb +4 -1
  145. data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
  146. data/lib/nokogiri/xml/xpath.rb +4 -0
  147. data/lib/nokogiri/xml/xpath_context.rb +3 -1
  148. data/lib/nokogiri/xml.rb +45 -38
  149. data/lib/nokogiri/xslt/stylesheet.rb +19 -0
  150. data/lib/nokogiri/xslt.rb +47 -2
  151. data/lib/nokogiri.rb +117 -24
  152. data/lib/xsd/xmlparser/nokogiri.rb +102 -0
  153. data/patches/sort-patches-by-date +25 -0
  154. data/ports/archives/libxml2-2.9.4.tar.gz +0 -0
  155. data/ports/archives/libxslt-1.1.29.tar.gz +0 -0
  156. data/suppressions/README.txt +1 -0
  157. data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
  158. data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
  159. data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
  160. data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
  161. data/tasks/test.rb +100 -0
  162. data/test/css/test_nthiness.rb +73 -6
  163. data/test/css/test_parser.rb +184 -39
  164. data/test/css/test_tokenizer.rb +72 -19
  165. data/test/css/test_xpath_visitor.rb +44 -2
  166. data/test/decorators/test_slop.rb +20 -0
  167. data/test/files/2ch.html +108 -0
  168. data/test/files/GH_1042.html +18 -0
  169. data/test/files/address_book.rlx +12 -0
  170. data/test/files/address_book.xml +10 -0
  171. data/test/files/atom.xml +344 -0
  172. data/test/files/bar/bar.xsd +4 -0
  173. data/test/files/bogus.xml +0 -0
  174. data/test/files/dont_hurt_em_why.xml +422 -0
  175. data/test/files/encoding.html +82 -0
  176. data/test/files/encoding.xhtml +84 -0
  177. data/test/files/exslt.xml +8 -0
  178. data/test/files/exslt.xslt +35 -0
  179. data/test/files/foo/foo.xsd +4 -0
  180. data/test/files/metacharset.html +10 -0
  181. data/test/files/namespace_pressure_test.xml +1684 -0
  182. data/test/files/noencoding.html +47 -0
  183. data/test/files/po.xml +32 -0
  184. data/test/files/po.xsd +66 -0
  185. data/test/files/saml/saml20assertion_schema.xsd +283 -0
  186. data/test/files/saml/saml20protocol_schema.xsd +302 -0
  187. data/test/files/saml/xenc_schema.xsd +146 -0
  188. data/test/files/saml/xmldsig_schema.xsd +318 -0
  189. data/test/files/shift_jis.html +10 -0
  190. data/test/files/shift_jis.xml +5 -0
  191. data/test/files/shift_jis_no_charset.html +9 -0
  192. data/test/files/slow-xpath.xml +25509 -0
  193. data/test/files/snuggles.xml +3 -0
  194. data/test/files/staff.dtd +10 -0
  195. data/test/files/test_document_url/bar.xml +2 -0
  196. data/test/files/test_document_url/document.dtd +4 -0
  197. data/test/files/test_document_url/document.xml +6 -0
  198. data/test/files/tlm.html +2 -1
  199. data/test/files/to_be_xincluded.xml +2 -0
  200. data/test/files/valid_bar.xml +2 -0
  201. data/test/files/xinclude.xml +4 -0
  202. data/test/helper.rb +124 -13
  203. data/test/html/sax/test_parser.rb +118 -4
  204. data/test/html/sax/test_parser_context.rb +46 -0
  205. data/test/html/sax/test_push_parser.rb +87 -0
  206. data/test/html/test_builder.rb +94 -8
  207. data/test/html/test_document.rb +626 -11
  208. data/test/html/test_document_encoding.rb +145 -0
  209. data/test/html/test_document_fragment.rb +301 -0
  210. data/test/html/test_element_description.rb +105 -0
  211. data/test/html/test_named_characters.rb +14 -0
  212. data/test/html/test_node.rb +212 -0
  213. data/test/html/test_node_encoding.rb +85 -0
  214. data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +14 -0
  215. data/test/namespaces/test_namespaces_aliased_default.rb +24 -0
  216. data/test/namespaces/test_namespaces_in_builder_doc.rb +75 -0
  217. data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
  218. data/test/namespaces/test_namespaces_in_created_doc.rb +75 -0
  219. data/test/namespaces/test_namespaces_in_parsed_doc.rb +80 -0
  220. data/test/namespaces/test_namespaces_preservation.rb +31 -0
  221. data/test/test_convert_xpath.rb +2 -47
  222. data/test/test_css_cache.rb +45 -0
  223. data/test/test_encoding_handler.rb +48 -0
  224. data/test/test_memory_leak.rb +156 -0
  225. data/test/test_nokogiri.rb +103 -1
  226. data/test/test_soap4r_sax.rb +52 -0
  227. data/test/test_xslt_transforms.rb +293 -8
  228. data/test/xml/node/test_save_options.rb +28 -0
  229. data/test/xml/node/test_subclass.rb +44 -0
  230. data/test/xml/sax/test_parser.rb +309 -8
  231. data/test/xml/sax/test_parser_context.rb +115 -0
  232. data/test/xml/sax/test_push_parser.rb +157 -0
  233. data/test/xml/test_attr.rb +67 -0
  234. data/test/xml/test_attribute_decl.rb +86 -0
  235. data/test/xml/test_builder.rb +327 -2
  236. data/test/xml/test_c14n.rb +180 -0
  237. data/test/xml/test_cdata.rb +32 -2
  238. data/test/xml/test_comment.rb +40 -0
  239. data/test/xml/test_document.rb +846 -35
  240. data/test/xml/test_document_encoding.rb +31 -0
  241. data/test/xml/test_document_fragment.rb +271 -0
  242. data/test/xml/test_dtd.rb +153 -9
  243. data/test/xml/test_dtd_encoding.rb +31 -0
  244. data/test/xml/test_element_content.rb +56 -0
  245. data/test/xml/test_element_decl.rb +73 -0
  246. data/test/xml/test_entity_decl.rb +122 -0
  247. data/test/xml/test_entity_reference.rb +251 -0
  248. data/test/xml/test_namespace.rb +96 -0
  249. data/test/xml/test_node.rb +1126 -105
  250. data/test/xml/test_node_attributes.rb +115 -0
  251. data/test/xml/test_node_encoding.rb +69 -0
  252. data/test/xml/test_node_inheritance.rb +32 -0
  253. data/test/xml/test_node_reparenting.rb +549 -0
  254. data/test/xml/test_node_set.rb +668 -9
  255. data/test/xml/test_parse_options.rb +64 -0
  256. data/test/xml/test_processing_instruction.rb +30 -0
  257. data/test/xml/test_reader.rb +589 -0
  258. data/test/xml/test_reader_encoding.rb +134 -0
  259. data/test/xml/test_relax_ng.rb +60 -0
  260. data/test/xml/test_schema.rb +142 -0
  261. data/test/xml/test_syntax_error.rb +30 -0
  262. data/test/xml/test_text.rb +49 -2
  263. data/test/xml/test_unparented_node.rb +440 -0
  264. data/test/xml/test_xinclude.rb +83 -0
  265. data/test/xml/test_xpath.rb +445 -0
  266. data/test/xslt/test_custom_functions.rb +133 -0
  267. data/test/xslt/test_exception_handling.rb +37 -0
  268. data/test_all +107 -0
  269. metadata +459 -115
  270. data/History.txt +0 -6
  271. data/README.ja.txt +0 -86
  272. data/README.txt +0 -87
  273. data/ext/nokogiri/html_sax_parser.c +0 -32
  274. data/ext/nokogiri/html_sax_parser.h +0 -11
  275. data/ext/nokogiri/native.c +0 -40
  276. data/ext/nokogiri/native.h +0 -51
  277. data/ext/nokogiri/xml_xpath.c +0 -46
  278. data/ext/nokogiri/xml_xpath.h +0 -11
  279. data/lib/nokogiri/css/generated_parser.rb +0 -653
  280. data/lib/nokogiri/css/generated_tokenizer.rb +0 -159
  281. data/lib/nokogiri/decorators/hpricot/node.rb +0 -58
  282. data/lib/nokogiri/decorators/hpricot/node_set.rb +0 -14
  283. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +0 -17
  284. data/lib/nokogiri/decorators/hpricot.rb +0 -3
  285. data/lib/nokogiri/decorators.rb +0 -1
  286. data/lib/nokogiri/hpricot.rb +0 -47
  287. data/lib/nokogiri/xml/after_handler.rb +0 -18
  288. data/lib/nokogiri/xml/before_handler.rb +0 -32
  289. data/lib/nokogiri/xml/element.rb +0 -6
  290. data/lib/nokogiri/xml/entity_declaration.rb +0 -9
  291. data/nokogiri.gemspec +0 -34
  292. data/test/hpricot/files/basic.xhtml +0 -17
  293. data/test/hpricot/files/boingboing.html +0 -2266
  294. data/test/hpricot/files/cy0.html +0 -3653
  295. data/test/hpricot/files/immob.html +0 -400
  296. data/test/hpricot/files/pace_application.html +0 -1320
  297. data/test/hpricot/files/tenderlove.html +0 -16
  298. data/test/hpricot/files/uswebgen.html +0 -220
  299. data/test/hpricot/files/utf8.html +0 -1054
  300. data/test/hpricot/files/week9.html +0 -1723
  301. data/test/hpricot/files/why.xml +0 -19
  302. data/test/hpricot/load_files.rb +0 -7
  303. data/test/hpricot/test_alter.rb +0 -67
  304. data/test/hpricot/test_builder.rb +0 -27
  305. data/test/hpricot/test_parser.rb +0 -423
  306. data/test/hpricot/test_paths.rb +0 -15
  307. data/test/hpricot/test_preserved.rb +0 -78
  308. data/test/hpricot/test_xml.rb +0 -30
  309. data/test/test_reader.rb +0 -222
@@ -1,21 +1,47 @@
1
1
  module Nokogiri
2
2
  module XML
3
- class SyntaxError < SyntaxError
3
+ ###
4
+ # This class provides information about XML SyntaxErrors. These
5
+ # exceptions are typically stored on Nokogiri::XML::Document#errors.
6
+ class SyntaxError < ::Nokogiri::SyntaxError
7
+ attr_reader :domain
8
+ attr_reader :code
9
+ attr_reader :level
10
+ attr_reader :file
11
+ attr_reader :line
12
+ attr_reader :str1
13
+ attr_reader :str2
14
+ attr_reader :str3
15
+ attr_reader :int1
16
+ attr_reader :column
17
+
18
+ ###
19
+ # return true if this is a non error
4
20
  def none?
5
21
  level == 0
6
22
  end
7
23
 
24
+ ###
25
+ # return true if this is a warning
8
26
  def warning?
9
27
  level == 1
10
28
  end
11
29
 
30
+ ###
31
+ # return true if this is an error
12
32
  def error?
13
33
  level == 2
14
34
  end
15
35
 
36
+ ###
37
+ # return true if this error is fatal
16
38
  def fatal?
17
39
  level == 3
18
40
  end
41
+
42
+ def to_s
43
+ super.chomp
44
+ end
19
45
  end
20
46
  end
21
47
  end
@@ -1,6 +1,9 @@
1
1
  module Nokogiri
2
2
  module XML
3
- class Text < Node
3
+ class Text < Nokogiri::XML::CharacterData
4
+ def content=(string)
5
+ self.native_content = string.to_s
6
+ end
4
7
  end
5
8
  end
6
9
  end
@@ -0,0 +1,11 @@
1
+ module Nokogiri
2
+ module XML
3
+ class XPath
4
+ class SyntaxError < XML::SyntaxError
5
+ def to_s
6
+ [super.chomp, str1].compact.join(': ')
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,6 +1,10 @@
1
+ require 'nokogiri/xml/xpath/syntax_error'
2
+
1
3
  module Nokogiri
2
4
  module XML
3
5
  class XPath
6
+ # The Nokogiri::XML::Document tied to this XPath instance
7
+ attr_accessor :document
4
8
  end
5
9
  end
6
10
  end
@@ -2,9 +2,11 @@ module Nokogiri
2
2
  module XML
3
3
  class XPathContext
4
4
 
5
+ ###
6
+ # Register namespaces in +namespaces+
5
7
  def register_namespaces(namespaces)
6
8
  namespaces.each do |k, v|
7
- k = k.gsub(/.*:/,'') # strip off 'xmlns:' or 'xml:'
9
+ k = k.to_s.gsub(/.*:/,'') # strip off 'xmlns:' or 'xml:'
8
10
  register_ns(k, v)
9
11
  end
10
12
  end
data/lib/nokogiri/xml.rb CHANGED
@@ -1,66 +1,73 @@
1
+ require 'nokogiri/xml/pp'
2
+ require 'nokogiri/xml/parse_options'
1
3
  require 'nokogiri/xml/sax'
2
- require 'nokogiri/xml/before_handler'
3
- require 'nokogiri/xml/after_handler'
4
+ require 'nokogiri/xml/searchable'
4
5
  require 'nokogiri/xml/node'
6
+ require 'nokogiri/xml/attribute_decl'
7
+ require 'nokogiri/xml/element_decl'
8
+ require 'nokogiri/xml/element_content'
9
+ require 'nokogiri/xml/character_data'
10
+ require 'nokogiri/xml/namespace'
11
+ require 'nokogiri/xml/attr'
5
12
  require 'nokogiri/xml/dtd'
6
- require 'nokogiri/xml/text'
7
13
  require 'nokogiri/xml/cdata'
14
+ require 'nokogiri/xml/text'
8
15
  require 'nokogiri/xml/document'
16
+ require 'nokogiri/xml/document_fragment'
17
+ require 'nokogiri/xml/processing_instruction'
9
18
  require 'nokogiri/xml/node_set'
19
+ require 'nokogiri/xml/syntax_error'
10
20
  require 'nokogiri/xml/xpath'
11
21
  require 'nokogiri/xml/xpath_context'
12
22
  require 'nokogiri/xml/builder'
13
23
  require 'nokogiri/xml/reader'
14
- require 'nokogiri/xml/syntax_error'
15
24
  require 'nokogiri/xml/notation'
16
- require 'nokogiri/xml/element'
17
- require 'nokogiri/xml/entity_declaration'
25
+ require 'nokogiri/xml/entity_decl'
26
+ require 'nokogiri/xml/schema'
27
+ require 'nokogiri/xml/relax_ng'
18
28
 
19
29
  module Nokogiri
20
30
  class << self
21
- def XML thing, url = nil, encoding = nil, options = 1
22
- Nokogiri::XML.parse(thing, url, encoding, options)
31
+ ###
32
+ # Parse XML. Convenience method for Nokogiri::XML::Document.parse
33
+ def XML thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT_XML, &block
34
+ Nokogiri::XML::Document.parse(thing, url, encoding, options, &block)
23
35
  end
24
36
  end
25
37
 
26
38
  module XML
27
- # Parser options
28
- PARSE_RECOVER = 1 << 0 # Recover from errors
29
- PARSE_NOENT = 1 << 1 # Substitute entities
30
- PARSE_DTDLOAD = 1 << 2 # Load external subsets
31
- PARSE_DTDATTR = 1 << 3 # Default DTD attributes
32
- PARSE_DTDVALID = 1 << 4 # validate with the DTD
33
- PARSE_NOERROR = 1 << 5 # suppress error reports
34
- PARSE_NOWARNING = 1 << 6 # suppress warning reports
35
- PARSE_PEDANTIC = 1 << 7 # pedantic error reporting
36
- PARSE_NOBLANKS = 1 << 8 # remove blank nodes
37
- PARSE_SAX1 = 1 << 9 # use the SAX1 interface internally
38
- PARSE_XINCLUDE = 1 << 10 # Implement XInclude substitition
39
- PARSE_NONET = 1 << 11 # Forbid network access
40
- PARSE_NODICT = 1 << 12 # Do not reuse the context dictionnary
41
- PARSE_NSCLEAN = 1 << 13 # remove redundant namespaces declarations
42
- PARSE_NOCDATA = 1 << 14 # merge CDATA as text nodes
43
- PARSE_NOXINCNODE = 1 << 15 # do not generate XINCLUDE START/END nodes
44
-
39
+ # Original C14N 1.0 spec canonicalization
40
+ XML_C14N_1_0 = 0
41
+ # Exclusive C14N 1.0 spec canonicalization
42
+ XML_C14N_EXCLUSIVE_1_0 = 1
43
+ # C14N 1.1 spec canonicalization
44
+ XML_C14N_1_1 = 2
45
45
  class << self
46
- def parse string_or_io, url = nil, encoding = nil, options = 2159
47
- if string_or_io.respond_to?(:read)
48
- url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil
49
- string_or_io = string_or_io.read
50
- end
46
+ ###
47
+ # Parse an XML document using the Nokogiri::XML::Reader API. See
48
+ # Nokogiri::XML::Reader for mor information
49
+ def Reader string_or_io, url = nil, encoding = nil, options = ParseOptions::STRICT
51
50
 
52
- # read_memory pukes on empty docs
53
- return Document.new if string_or_io.nil? or string_or_io.empty?
51
+ options = Nokogiri::XML::ParseOptions.new(options) if Fixnum === options
52
+ # Give the options to the user
53
+ yield options if block_given?
54
54
 
55
- Document.read_memory(string_or_io, url, encoding, options)
55
+ if string_or_io.respond_to? :read
56
+ return Reader.from_io(string_or_io, url, encoding, options.to_i)
57
+ end
58
+ Reader.from_memory(string_or_io, url, encoding, options.to_i)
56
59
  end
57
60
 
58
- def substitute_entities=(value = true)
59
- Document.substitute_entities = value
61
+ ###
62
+ # Parse XML. Convenience method for Nokogiri::XML::Document.parse
63
+ def parse thing, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML, &block
64
+ Document.parse(thing, url, encoding, options, &block)
60
65
  end
61
66
 
62
- def load_external_subsets=(value = true)
63
- Document.load_external_subsets = value
67
+ ####
68
+ # Parse a fragment from +string+ in to a NodeSet.
69
+ def fragment string
70
+ XML::DocumentFragment.parse(string)
64
71
  end
65
72
  end
66
73
  end
@@ -1,6 +1,25 @@
1
1
  module Nokogiri
2
2
  module XSLT
3
+ ###
4
+ # A Stylesheet represents an XSLT Stylesheet object. Stylesheet creation
5
+ # is done through Nokogiri.XSLT. Here is an example of transforming
6
+ # an XML::Document with a Stylesheet:
7
+ #
8
+ # doc = Nokogiri::XML(File.read('some_file.xml'))
9
+ # xslt = Nokogiri::XSLT(File.read('some_transformer.xslt'))
10
+ #
11
+ # puts xslt.transform(doc)
12
+ #
13
+ # See Nokogiri::XSLT::Stylesheet#transform for more transformation
14
+ # information.
3
15
  class Stylesheet
16
+ ###
17
+ # Apply an XSLT stylesheet to an XML::Document.
18
+ # +params+ is an array of strings used as XSLT parameters.
19
+ # returns serialized document
20
+ def apply_to document, params = []
21
+ serialize(transform(document, params))
22
+ end
4
23
  end
5
24
  end
6
25
  end
data/lib/nokogiri/xslt.rb CHANGED
@@ -1,10 +1,55 @@
1
1
  require 'nokogiri/xslt/stylesheet'
2
2
 
3
3
  module Nokogiri
4
+ class << self
5
+ ###
6
+ # Create a Nokogiri::XSLT::Stylesheet with +stylesheet+.
7
+ #
8
+ # Example:
9
+ #
10
+ # xslt = Nokogiri::XSLT(File.read(ARGV[0]))
11
+ #
12
+ def XSLT stylesheet, modules = {}
13
+ XSLT.parse(stylesheet, modules)
14
+ end
15
+ end
16
+
17
+ ###
18
+ # See Nokogiri::XSLT::Stylesheet for creating and manipulating
19
+ # Stylesheet object.
4
20
  module XSLT
5
21
  class << self
6
- def parse(string)
7
- Stylesheet.parse_stylesheet_doc(XML.parse(string))
22
+ ###
23
+ # Parse the stylesheet in +string+, register any +modules+
24
+ def parse string, modules = {}
25
+ modules.each do |url, klass|
26
+ XSLT.register url, klass
27
+ end
28
+
29
+ if Nokogiri.jruby?
30
+ Stylesheet.parse_stylesheet_doc(XML.parse(string), string)
31
+ else
32
+ Stylesheet.parse_stylesheet_doc(XML.parse(string))
33
+ end
34
+ end
35
+
36
+ ###
37
+ # Quote parameters in +params+ for stylesheet safety
38
+ def quote_params params
39
+ parray = (params.instance_of?(Hash) ? params.to_a.flatten : params).dup
40
+ parray.each_with_index do |v,i|
41
+ if i % 2 > 0
42
+ parray[i]=
43
+ if v =~ /'/
44
+ "concat('#{ v.gsub(/'/, %q{', "'", '}) }')"
45
+ else
46
+ "'#{v}'";
47
+ end
48
+ else
49
+ parray[i] = v.to_s
50
+ end
51
+ end
52
+ parray.flatten
8
53
  end
9
54
  end
10
55
  end
data/lib/nokogiri.rb CHANGED
@@ -1,51 +1,144 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Modify the PATH on windows so that the external DLLs will get loaded.
3
+
4
+ require 'rbconfig'
5
+
6
+ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
7
+ # The line below caused a problem on non-GAE rack environment.
8
+ # unless defined?(JRuby::Rack::VERSION) || defined?(AppEngine::ApiProxy)
9
+ #
10
+ # However, simply cutting defined?(JRuby::Rack::VERSION) off resulted in
11
+ # an unable-to-load-nokogiri problem. Thus, now, Nokogiri checks the presense
12
+ # of appengine-rack.jar in $LOAD_PATH. If Nokogiri is on GAE, Nokogiri
13
+ # should skip loading xml jars. This is because those are in WEB-INF/lib and
14
+ # already set in the classpath.
15
+ unless $LOAD_PATH.to_s.include?("appengine-rack")
16
+ require 'stringio'
17
+ require 'isorelax.jar'
18
+ require 'jing.jar'
19
+ require 'nekohtml.jar'
20
+ require 'nekodtd.jar'
21
+ require 'xercesImpl.jar'
22
+ require 'serializer.jar'
23
+ require 'xalan.jar'
24
+ require 'xml-apis.jar'
25
+ end
26
+ end
27
+
28
+ begin
29
+ RUBY_VERSION =~ /(\d+.\d+)/
30
+ require "nokogiri/#{$1}/nokogiri"
31
+ rescue LoadError
32
+ require 'nokogiri/nokogiri'
33
+ end
1
34
  require 'nokogiri/version'
35
+ require 'nokogiri/syntax_error'
2
36
  require 'nokogiri/xml'
3
37
  require 'nokogiri/xslt'
4
38
  require 'nokogiri/html'
5
- require 'nokogiri/decorators'
39
+ require 'nokogiri/decorators/slop'
6
40
  require 'nokogiri/css'
7
41
  require 'nokogiri/html/builder'
8
- require 'nokogiri/hpricot'
9
-
10
- # Modify the PATH on windows so that the external DLLs will get loaded.
11
- ENV['PATH'] += ";" + File.expand_path(
12
- File.join(File.dirname(__FILE__), "..", "ext", "nokogiri")
13
- ) if RUBY_PLATFORM =~ /mswin/i
14
-
15
- require 'nokogiri/native'
16
42
 
43
+ # Nokogiri parses and searches XML/HTML very quickly, and also has
44
+ # correctly implemented CSS3 selector support as well as XPath 1.0
45
+ # support.
46
+ #
47
+ # Parsing a document returns either a Nokogiri::XML::Document, or a
48
+ # Nokogiri::HTML::Document depending on the kind of document you parse.
49
+ #
50
+ # Here is an example:
51
+ #
52
+ # require 'nokogiri'
53
+ # require 'open-uri'
54
+ #
55
+ # # Get a Nokogiri::HTML:Document for the page we’re interested in...
56
+ #
57
+ # doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
58
+ #
59
+ # # Do funky things with it using Nokogiri::XML::Node methods...
60
+ #
61
+ # ####
62
+ # # Search for nodes by css
63
+ # doc.css('h3.r a.l').each do |link|
64
+ # puts link.content
65
+ # end
66
+ #
67
+ # See Nokogiri::XML::Searchable#css for more information about CSS searching.
68
+ # See Nokogiri::XML::Searchable#xpath for more information about XPath searching.
17
69
  module Nokogiri
18
70
  class << self
19
- attr_accessor :error_handler
20
-
71
+ ###
72
+ # Parse an HTML or XML document. +string+ contains the document.
21
73
  def parse string, url = nil, encoding = nil, options = nil
22
- doc =
23
- if string =~ /^\s*<[^Hh>]*html/i # Probably html
24
- Nokogiri::HTML.parse(string, url, encoding, options || 2145)
25
- else
26
- Nokogiri::XML.parse(string, url, encoding, options || 2159)
27
- end
28
- yield doc if block_given?
29
- doc
74
+ if string.respond_to?(:read) ||
75
+ /^\s*<(?:!DOCTYPE\s+)?html[\s>]/i === string[0, 512]
76
+ # Expect an HTML indicator to appear within the first 512
77
+ # characters of a document. (<?xml ?> + <?xml-stylesheet ?>
78
+ # shouldn't be that long)
79
+ Nokogiri.HTML(string, url, encoding,
80
+ options || XML::ParseOptions::DEFAULT_HTML)
81
+ else
82
+ Nokogiri.XML(string, url, encoding,
83
+ options || XML::ParseOptions::DEFAULT_XML)
84
+ end.tap { |doc|
85
+ yield doc if block_given?
86
+ }
30
87
  end
31
88
 
89
+ ###
90
+ # Create a new Nokogiri::XML::DocumentFragment
32
91
  def make input = nil, opts = {}, &blk
33
92
  if input
34
- Nokogiri::XML::Node.new_from_str(input)
93
+ Nokogiri::HTML.fragment(input).children.first
35
94
  else
36
95
  Nokogiri(&blk)
37
96
  end
38
97
  end
98
+
99
+ ###
100
+ # Parse a document and add the Slop decorator. The Slop decorator
101
+ # implements method_missing such that methods may be used instead of CSS
102
+ # or XPath. For example:
103
+ #
104
+ # doc = Nokogiri::Slop(<<-eohtml)
105
+ # <html>
106
+ # <body>
107
+ # <p>first</p>
108
+ # <p>second</p>
109
+ # </body>
110
+ # </html>
111
+ # eohtml
112
+ # assert_equal('second', doc.html.body.p[1].text)
113
+ #
114
+ def Slop(*args, &block)
115
+ Nokogiri(*args, &block).slop!
116
+ end
117
+
118
+ def install_default_aliases
119
+ # Make sure to support some popular encoding aliases not known by
120
+ # all iconv implementations.
121
+ {
122
+ 'Windows-31J' => 'CP932', # Windows-31J is the IANA registered name of CP932.
123
+ }.each { |alias_name, name|
124
+ EncodingHandler.alias(name, alias_name) if EncodingHandler[alias_name].nil?
125
+ }
126
+ end
39
127
  end
40
128
 
41
- self.error_handler = lambda { |syntax_error| }
129
+ Nokogiri.install_default_aliases
42
130
  end
43
131
 
132
+ ###
133
+ # Parser a document contained in +args+. Nokogiri will try to guess what
134
+ # type of document you are attempting to parse. For more information, see
135
+ # Nokogiri.parse
136
+ #
137
+ # To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
44
138
  def Nokogiri(*args, &block)
45
139
  if block_given?
46
- builder = Nokogiri::HTML::Builder.new(&block)
47
- return builder.doc
140
+ Nokogiri::HTML::Builder.new(&block).doc.root
48
141
  else
49
- Nokogiri::HTML.parse(*args)
142
+ Nokogiri.parse(*args)
50
143
  end
51
144
  end
@@ -0,0 +1,102 @@
1
+ require 'nokogiri'
2
+
3
+ module XSD # :nodoc:
4
+ module XMLParser # :nodoc:
5
+ ###
6
+ # Nokogiri XML parser for soap4r.
7
+ #
8
+ # Nokogiri may be used as the XML parser in soap4r. Simply require
9
+ # 'xsd/xmlparser/nokogiri' in your soap4r applications, and soap4r
10
+ # will use Nokogiri as it's XML parser. No other changes should be
11
+ # required to use Nokogiri as the XML parser.
12
+ #
13
+ # Example (using UW ITS Web Services):
14
+ #
15
+ # require 'rubygems'
16
+ # require 'nokogiri'
17
+ # gem 'soap4r'
18
+ # require 'defaultDriver'
19
+ # require 'xsd/xmlparser/nokogiri'
20
+ #
21
+ # obj = AvlPortType.new
22
+ # obj.getLatestByRoute(obj.getAgencies.first, 8).each do |bus|
23
+ # p "#{bus.routeID}, #{bus.longitude}, #{bus.latitude}"
24
+ # end
25
+ #
26
+ class Nokogiri < XSD::XMLParser::Parser
27
+ ###
28
+ # Create a new XSD parser with +host+ and +opt+
29
+ def initialize host, opt = {}
30
+ super
31
+ @parser = ::Nokogiri::XML::SAX::Parser.new(self, @charset || 'UTF-8')
32
+ end
33
+
34
+ ###
35
+ # Start parsing +string_or_readable+
36
+ def do_parse string_or_readable
37
+ @parser.parse(string_or_readable)
38
+ end
39
+
40
+ ###
41
+ # Handle the start_element event with +name+ and +attrs+
42
+ def start_element name, attrs = []
43
+ super(name, Hash[*attrs.flatten])
44
+ end
45
+
46
+ ###
47
+ # Handle the end_element event with +name+
48
+ def end_element name
49
+ super
50
+ end
51
+
52
+ ###
53
+ # Handle errors with message +msg+
54
+ def error msg
55
+ raise ParseError.new(msg)
56
+ end
57
+ alias :warning :error
58
+
59
+ ###
60
+ # Handle cdata_blocks containing +string+
61
+ def cdata_block string
62
+ characters string
63
+ end
64
+
65
+ ###
66
+ # Called at the beginning of an element
67
+ # +name+ is the element name
68
+ # +attrs+ is a list of attributes
69
+ # +prefix+ is the namespace prefix for the element
70
+ # +uri+ is the associated namespace URI
71
+ # +ns+ is a hash of namespace prefix:urls associated with the element
72
+ def start_element_namespace name, attrs = [], prefix = nil, uri = nil, ns = []
73
+ ###
74
+ # Deal with SAX v1 interface
75
+ name = [prefix, name].compact.join(':')
76
+ attributes = ns.map { |ns_prefix,ns_uri|
77
+ [['xmlns', ns_prefix].compact.join(':'), ns_uri]
78
+ } + attrs.map { |attr|
79
+ [[attr.prefix, attr.localname].compact.join(':'), attr.value]
80
+ }.flatten
81
+ start_element name, attributes
82
+ end
83
+
84
+ ###
85
+ # Called at the end of an element
86
+ # +name+ is the element's name
87
+ # +prefix+ is the namespace prefix associated with the element
88
+ # +uri+ is the associated namespace URI
89
+ def end_element_namespace name, prefix = nil, uri = nil
90
+ ###
91
+ # Deal with SAX v1 interface
92
+ end_element [prefix, name].compact.join(':')
93
+ end
94
+
95
+ %w{ xmldecl start_document end_document comment }.each do |name|
96
+ class_eval %{ def #{name}(*args); end }
97
+ end
98
+
99
+ add_factory(self)
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,25 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "date"
4
+
5
+ dir = ARGV[0] || raise("ERROR: arg1 must be dir")
6
+
7
+ Dir.chdir dir
8
+
9
+ files_and_times = {}
10
+ Dir["*.patch"].sort.each do |filename|
11
+ dateline = `cat #{filename} | grep "Date:"`
12
+ datestr = dateline.split("Date:").last.strip
13
+ time = DateTime.parse datestr
14
+ files_and_times[filename] = time
15
+ end
16
+
17
+ count = 0
18
+ files_and_times.sort_by {|k,v| v}.each do |filename, time|
19
+ count += 1
20
+ _, patch_name = filename.split("-", 2)
21
+ new_filename = sprintf("%4.4d-%s", count, patch_name)
22
+ printf "mv -f %s %s # %s\n", filename, new_filename, time
23
+ end
24
+
25
+ STDERR.print "\n**\n** REMEMBER TO UPDATE THE Manifest.txt FILE\n**\n"
Binary file
@@ -0,0 +1 @@
1
+ This directory contains valgrind suppression files generated by the hoe-debugging gem.
@@ -0,0 +1,61 @@
1
+ {
2
+ <insert_a_suppression_name_here>
3
+ Memcheck:Addr8
4
+ fun:garbage_collect
5
+ fun:rb_newobj
6
+ fun:rb_node_newnode
7
+ fun:ruby_yyparse
8
+ fun:yycompile
9
+ fun:load_file
10
+ fun:rb_load
11
+ fun:rb_require_safe
12
+ fun:rb_call0
13
+ fun:rb_call
14
+ fun:eval_fcall
15
+ fun:rb_eval
16
+ fun:rb_load
17
+ fun:rb_require_safe
18
+ fun:rb_call0
19
+ fun:rb_call
20
+ fun:eval_fcall
21
+ fun:rb_eval
22
+ fun:rb_load
23
+ fun:rb_require_safe
24
+ fun:rb_protect
25
+ fun:require_libraries
26
+ fun:proc_options
27
+ fun:ruby_process_options
28
+ }
29
+ {
30
+ <insert_a_suppression_name_here>
31
+ Memcheck:Addr8
32
+ fun:garbage_collect_0
33
+ fun:rb_newobj
34
+ fun:rb_node_newnode
35
+ fun:ruby_yyparse
36
+ fun:yycompile
37
+ fun:load_file
38
+ fun:rb_load
39
+ fun:rb_require_safe
40
+ fun:rb_call0
41
+ fun:rb_call
42
+ fun:eval_fcall
43
+ fun:rb_eval
44
+ fun:rb_load
45
+ fun:rb_require_safe
46
+ fun:rb_call0
47
+ fun:rb_call
48
+ fun:eval_fcall
49
+ fun:rb_eval
50
+ fun:rb_load
51
+ fun:rb_require_safe
52
+ fun:rb_protect
53
+ fun:require_libraries
54
+ fun:proc_options
55
+ fun:ruby_process_options
56
+ }
57
+ {
58
+ <insert_a_suppression_name_here>
59
+ Memcheck:Addr8
60
+ fun:rb_gc_wipe_stack
61
+ }
File without changes