nokogiri 1.6.2.rc1-x64-mingw32

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 (263) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +26 -0
  3. data/.editorconfig +17 -0
  4. data/.gemtest +0 -0
  5. data/.travis.yml +25 -0
  6. data/CHANGELOG.ja.rdoc +857 -0
  7. data/CHANGELOG.rdoc +880 -0
  8. data/C_CODING_STYLE.rdoc +33 -0
  9. data/Gemfile +21 -0
  10. data/Manifest.txt +371 -0
  11. data/README.ja.rdoc +112 -0
  12. data/README.rdoc +180 -0
  13. data/ROADMAP.md +89 -0
  14. data/Rakefile +351 -0
  15. data/STANDARD_RESPONSES.md +47 -0
  16. data/Y_U_NO_GEMSPEC.md +155 -0
  17. data/bin/nokogiri +78 -0
  18. data/build_all +130 -0
  19. data/dependencies.yml +4 -0
  20. data/ext/nokogiri/depend +358 -0
  21. data/ext/nokogiri/extconf.rb +453 -0
  22. data/ext/nokogiri/html_document.c +170 -0
  23. data/ext/nokogiri/html_document.h +10 -0
  24. data/ext/nokogiri/html_element_description.c +279 -0
  25. data/ext/nokogiri/html_element_description.h +10 -0
  26. data/ext/nokogiri/html_entity_lookup.c +32 -0
  27. data/ext/nokogiri/html_entity_lookup.h +8 -0
  28. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  29. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  30. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  31. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  32. data/ext/nokogiri/nokogiri.c +148 -0
  33. data/ext/nokogiri/nokogiri.h +164 -0
  34. data/ext/nokogiri/xml_attr.c +94 -0
  35. data/ext/nokogiri/xml_attr.h +9 -0
  36. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  37. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  38. data/ext/nokogiri/xml_cdata.c +56 -0
  39. data/ext/nokogiri/xml_cdata.h +9 -0
  40. data/ext/nokogiri/xml_comment.c +54 -0
  41. data/ext/nokogiri/xml_comment.h +9 -0
  42. data/ext/nokogiri/xml_document.c +577 -0
  43. data/ext/nokogiri/xml_document.h +23 -0
  44. data/ext/nokogiri/xml_document_fragment.c +48 -0
  45. data/ext/nokogiri/xml_document_fragment.h +10 -0
  46. data/ext/nokogiri/xml_dtd.c +202 -0
  47. data/ext/nokogiri/xml_dtd.h +10 -0
  48. data/ext/nokogiri/xml_element_content.c +123 -0
  49. data/ext/nokogiri/xml_element_content.h +10 -0
  50. data/ext/nokogiri/xml_element_decl.c +69 -0
  51. data/ext/nokogiri/xml_element_decl.h +9 -0
  52. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  53. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  54. data/ext/nokogiri/xml_entity_decl.c +110 -0
  55. data/ext/nokogiri/xml_entity_decl.h +10 -0
  56. data/ext/nokogiri/xml_entity_reference.c +52 -0
  57. data/ext/nokogiri/xml_entity_reference.h +9 -0
  58. data/ext/nokogiri/xml_io.c +56 -0
  59. data/ext/nokogiri/xml_io.h +11 -0
  60. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  61. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  62. data/ext/nokogiri/xml_namespace.c +78 -0
  63. data/ext/nokogiri/xml_namespace.h +13 -0
  64. data/ext/nokogiri/xml_node.c +1541 -0
  65. data/ext/nokogiri/xml_node.h +13 -0
  66. data/ext/nokogiri/xml_node_set.c +467 -0
  67. data/ext/nokogiri/xml_node_set.h +14 -0
  68. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  69. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  70. data/ext/nokogiri/xml_reader.c +681 -0
  71. data/ext/nokogiri/xml_reader.h +10 -0
  72. data/ext/nokogiri/xml_relax_ng.c +161 -0
  73. data/ext/nokogiri/xml_relax_ng.h +9 -0
  74. data/ext/nokogiri/xml_sax_parser.c +312 -0
  75. data/ext/nokogiri/xml_sax_parser.h +39 -0
  76. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  77. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  78. data/ext/nokogiri/xml_sax_push_parser.c +115 -0
  79. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  80. data/ext/nokogiri/xml_schema.c +205 -0
  81. data/ext/nokogiri/xml_schema.h +9 -0
  82. data/ext/nokogiri/xml_syntax_error.c +63 -0
  83. data/ext/nokogiri/xml_syntax_error.h +13 -0
  84. data/ext/nokogiri/xml_text.c +52 -0
  85. data/ext/nokogiri/xml_text.h +9 -0
  86. data/ext/nokogiri/xml_xpath_context.c +307 -0
  87. data/ext/nokogiri/xml_xpath_context.h +10 -0
  88. data/ext/nokogiri/xslt_stylesheet.c +270 -0
  89. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  90. data/lib/nokogiri.rb +137 -0
  91. data/lib/nokogiri/2.0/nokogiri.so +0 -0
  92. data/lib/nokogiri/2.1/nokogiri.so +0 -0
  93. data/lib/nokogiri/css.rb +27 -0
  94. data/lib/nokogiri/css/node.rb +52 -0
  95. data/lib/nokogiri/css/parser.rb +715 -0
  96. data/lib/nokogiri/css/parser.y +249 -0
  97. data/lib/nokogiri/css/parser_extras.rb +91 -0
  98. data/lib/nokogiri/css/syntax_error.rb +7 -0
  99. data/lib/nokogiri/css/tokenizer.rb +152 -0
  100. data/lib/nokogiri/css/tokenizer.rex +55 -0
  101. data/lib/nokogiri/css/xpath_visitor.rb +219 -0
  102. data/lib/nokogiri/decorators/slop.rb +35 -0
  103. data/lib/nokogiri/html.rb +37 -0
  104. data/lib/nokogiri/html/builder.rb +35 -0
  105. data/lib/nokogiri/html/document.rb +333 -0
  106. data/lib/nokogiri/html/document_fragment.rb +41 -0
  107. data/lib/nokogiri/html/element_description.rb +23 -0
  108. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  109. data/lib/nokogiri/html/entity_lookup.rb +13 -0
  110. data/lib/nokogiri/html/sax/parser.rb +52 -0
  111. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  112. data/lib/nokogiri/html/sax/push_parser.rb +16 -0
  113. data/lib/nokogiri/syntax_error.rb +4 -0
  114. data/lib/nokogiri/version.rb +106 -0
  115. data/lib/nokogiri/xml.rb +73 -0
  116. data/lib/nokogiri/xml/attr.rb +14 -0
  117. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  118. data/lib/nokogiri/xml/builder.rb +443 -0
  119. data/lib/nokogiri/xml/cdata.rb +11 -0
  120. data/lib/nokogiri/xml/character_data.rb +7 -0
  121. data/lib/nokogiri/xml/document.rb +279 -0
  122. data/lib/nokogiri/xml/document_fragment.rb +112 -0
  123. data/lib/nokogiri/xml/dtd.rb +32 -0
  124. data/lib/nokogiri/xml/element_content.rb +36 -0
  125. data/lib/nokogiri/xml/element_decl.rb +13 -0
  126. data/lib/nokogiri/xml/entity_decl.rb +19 -0
  127. data/lib/nokogiri/xml/namespace.rb +13 -0
  128. data/lib/nokogiri/xml/node.rb +982 -0
  129. data/lib/nokogiri/xml/node/save_options.rb +61 -0
  130. data/lib/nokogiri/xml/node_set.rb +355 -0
  131. data/lib/nokogiri/xml/notation.rb +6 -0
  132. data/lib/nokogiri/xml/parse_options.rb +98 -0
  133. data/lib/nokogiri/xml/pp.rb +2 -0
  134. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  135. data/lib/nokogiri/xml/pp/node.rb +56 -0
  136. data/lib/nokogiri/xml/processing_instruction.rb +8 -0
  137. data/lib/nokogiri/xml/reader.rb +112 -0
  138. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  139. data/lib/nokogiri/xml/sax.rb +4 -0
  140. data/lib/nokogiri/xml/sax/document.rb +171 -0
  141. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  142. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  143. data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
  144. data/lib/nokogiri/xml/schema.rb +63 -0
  145. data/lib/nokogiri/xml/syntax_error.rb +47 -0
  146. data/lib/nokogiri/xml/text.rb +9 -0
  147. data/lib/nokogiri/xml/xpath.rb +10 -0
  148. data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
  149. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  150. data/lib/nokogiri/xslt.rb +56 -0
  151. data/lib/nokogiri/xslt/stylesheet.rb +25 -0
  152. data/lib/xsd/xmlparser/nokogiri.rb +102 -0
  153. data/suppressions/README.txt +1 -0
  154. data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
  155. data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
  156. data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
  157. data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
  158. data/tasks/nokogiri.org.rb +24 -0
  159. data/tasks/test.rb +95 -0
  160. data/test/css/test_nthiness.rb +222 -0
  161. data/test/css/test_parser.rb +358 -0
  162. data/test/css/test_tokenizer.rb +198 -0
  163. data/test/css/test_xpath_visitor.rb +96 -0
  164. data/test/decorators/test_slop.rb +16 -0
  165. data/test/files/2ch.html +108 -0
  166. data/test/files/address_book.rlx +12 -0
  167. data/test/files/address_book.xml +10 -0
  168. data/test/files/atom.xml +344 -0
  169. data/test/files/bar/bar.xsd +4 -0
  170. data/test/files/bogus.xml +0 -0
  171. data/test/files/dont_hurt_em_why.xml +422 -0
  172. data/test/files/encoding.html +82 -0
  173. data/test/files/encoding.xhtml +84 -0
  174. data/test/files/exslt.xml +8 -0
  175. data/test/files/exslt.xslt +35 -0
  176. data/test/files/foo/foo.xsd +4 -0
  177. data/test/files/metacharset.html +10 -0
  178. data/test/files/noencoding.html +47 -0
  179. data/test/files/po.xml +32 -0
  180. data/test/files/po.xsd +66 -0
  181. data/test/files/saml/saml20assertion_schema.xsd +283 -0
  182. data/test/files/saml/saml20protocol_schema.xsd +302 -0
  183. data/test/files/saml/xenc_schema.xsd +146 -0
  184. data/test/files/saml/xmldsig_schema.xsd +318 -0
  185. data/test/files/shift_jis.html +10 -0
  186. data/test/files/shift_jis.xml +5 -0
  187. data/test/files/shift_jis_no_charset.html +9 -0
  188. data/test/files/snuggles.xml +3 -0
  189. data/test/files/staff.dtd +10 -0
  190. data/test/files/staff.xml +59 -0
  191. data/test/files/staff.xslt +32 -0
  192. data/test/files/test_document_url/bar.xml +2 -0
  193. data/test/files/test_document_url/document.dtd +4 -0
  194. data/test/files/test_document_url/document.xml +6 -0
  195. data/test/files/tlm.html +850 -0
  196. data/test/files/to_be_xincluded.xml +2 -0
  197. data/test/files/valid_bar.xml +2 -0
  198. data/test/files/xinclude.xml +4 -0
  199. data/test/helper.rb +164 -0
  200. data/test/html/sax/test_parser.rb +141 -0
  201. data/test/html/sax/test_parser_context.rb +46 -0
  202. data/test/html/test_builder.rb +164 -0
  203. data/test/html/test_document.rb +619 -0
  204. data/test/html/test_document_encoding.rb +148 -0
  205. data/test/html/test_document_fragment.rb +261 -0
  206. data/test/html/test_element_description.rb +105 -0
  207. data/test/html/test_named_characters.rb +14 -0
  208. data/test/html/test_node.rb +196 -0
  209. data/test/html/test_node_encoding.rb +27 -0
  210. data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +14 -0
  211. data/test/namespaces/test_namespaces_in_builder_doc.rb +75 -0
  212. data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
  213. data/test/namespaces/test_namespaces_in_created_doc.rb +75 -0
  214. data/test/namespaces/test_namespaces_in_parsed_doc.rb +66 -0
  215. data/test/test_convert_xpath.rb +135 -0
  216. data/test/test_css_cache.rb +45 -0
  217. data/test/test_encoding_handler.rb +46 -0
  218. data/test/test_memory_leak.rb +156 -0
  219. data/test/test_nokogiri.rb +138 -0
  220. data/test/test_reader.rb +558 -0
  221. data/test/test_soap4r_sax.rb +52 -0
  222. data/test/test_xslt_transforms.rb +279 -0
  223. data/test/xml/node/test_save_options.rb +28 -0
  224. data/test/xml/node/test_subclass.rb +44 -0
  225. data/test/xml/sax/test_parser.rb +382 -0
  226. data/test/xml/sax/test_parser_context.rb +115 -0
  227. data/test/xml/sax/test_push_parser.rb +157 -0
  228. data/test/xml/test_attr.rb +64 -0
  229. data/test/xml/test_attribute_decl.rb +86 -0
  230. data/test/xml/test_builder.rb +315 -0
  231. data/test/xml/test_c14n.rb +161 -0
  232. data/test/xml/test_cdata.rb +48 -0
  233. data/test/xml/test_comment.rb +29 -0
  234. data/test/xml/test_document.rb +934 -0
  235. data/test/xml/test_document_encoding.rb +28 -0
  236. data/test/xml/test_document_fragment.rb +228 -0
  237. data/test/xml/test_dtd.rb +187 -0
  238. data/test/xml/test_dtd_encoding.rb +33 -0
  239. data/test/xml/test_element_content.rb +56 -0
  240. data/test/xml/test_element_decl.rb +73 -0
  241. data/test/xml/test_entity_decl.rb +122 -0
  242. data/test/xml/test_entity_reference.rb +245 -0
  243. data/test/xml/test_namespace.rb +95 -0
  244. data/test/xml/test_node.rb +1155 -0
  245. data/test/xml/test_node_attributes.rb +113 -0
  246. data/test/xml/test_node_encoding.rb +107 -0
  247. data/test/xml/test_node_inheritance.rb +32 -0
  248. data/test/xml/test_node_reparenting.rb +374 -0
  249. data/test/xml/test_node_set.rb +755 -0
  250. data/test/xml/test_parse_options.rb +64 -0
  251. data/test/xml/test_processing_instruction.rb +30 -0
  252. data/test/xml/test_reader_encoding.rb +142 -0
  253. data/test/xml/test_relax_ng.rb +60 -0
  254. data/test/xml/test_schema.rb +129 -0
  255. data/test/xml/test_syntax_error.rb +12 -0
  256. data/test/xml/test_text.rb +45 -0
  257. data/test/xml/test_unparented_node.rb +422 -0
  258. data/test/xml/test_xinclude.rb +83 -0
  259. data/test/xml/test_xpath.rb +376 -0
  260. data/test/xslt/test_custom_functions.rb +133 -0
  261. data/test/xslt/test_exception_handling.rb +37 -0
  262. data/test_all +81 -0
  263. metadata +601 -0
@@ -0,0 +1,11 @@
1
+ module Nokogiri
2
+ module XML
3
+ class CDATA < Nokogiri::XML::Text
4
+ ###
5
+ # Get the name of this CDATA node
6
+ def name
7
+ '#cdata-section'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Nokogiri
2
+ module XML
3
+ class CharacterData < Nokogiri::XML::Node
4
+ include Nokogiri::XML::PP::CharacterData
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,279 @@
1
+ module Nokogiri
2
+ module XML
3
+ ##
4
+ # Nokogiri::XML::Document is the main entry point for dealing with
5
+ # XML documents. The Document is created by parsing an XML document.
6
+ # See Nokogiri::XML::Document.parse() for more information on parsing.
7
+ #
8
+ # For searching a Document, see Nokogiri::XML::Node#css and
9
+ # Nokogiri::XML::Node#xpath
10
+ #
11
+ class Document < Nokogiri::XML::Node
12
+ # I'm ignoring unicode characters here.
13
+ # See http://www.w3.org/TR/REC-xml-names/#ns-decl for more details.
14
+ NCNAME_START_CHAR = "A-Za-z_"
15
+ NCNAME_CHAR = NCNAME_START_CHAR + "\\-.0-9"
16
+ NCNAME_RE = /^xmlns(:[#{NCNAME_START_CHAR}][#{NCNAME_CHAR}]*)?$/
17
+
18
+ ##
19
+ # Parse an XML file.
20
+ #
21
+ # +string_or_io+ may be a String, or any object that responds to
22
+ # _read_ and _close_ such as an IO, or StringIO.
23
+ #
24
+ # +url+ (optional) is the URI where this document is located.
25
+ #
26
+ # +encoding+ (optional) is the encoding that should be used when processing
27
+ # the document.
28
+ #
29
+ # +options+ (optional) is a configuration object that sets options during
30
+ # parsing, such as Nokogiri::XML::ParseOptions::RECOVER. See the
31
+ # Nokogiri::XML::ParseOptions for more information.
32
+ #
33
+ # +block+ (optional) is passed a configuration object on which
34
+ # parse options may be set.
35
+ #
36
+ # When parsing untrusted documents, it's recommended that the
37
+ # +nonet+ option be used, as shown in this example code:
38
+ #
39
+ # Nokogiri::XML::Document.parse(xml_string) { |config| config.nonet }
40
+ #
41
+ # Nokogiri.XML() is a convenience method which will call this method.
42
+ #
43
+ def self.parse string_or_io, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML, &block
44
+ options = Nokogiri::XML::ParseOptions.new(options) if Fixnum === options
45
+ # Give the options to the user
46
+ yield options if block_given?
47
+
48
+ return new if !options.strict? && empty_doc?(string_or_io)
49
+
50
+ doc = if string_or_io.respond_to?(:read)
51
+ url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil
52
+ read_io(string_or_io, url, encoding, options.to_i)
53
+ else
54
+ # read_memory pukes on empty docs
55
+ read_memory(string_or_io, url, encoding, options.to_i)
56
+ end
57
+
58
+ # do xinclude processing
59
+ doc.do_xinclude(options) if options.xinclude?
60
+
61
+ return doc
62
+ end
63
+
64
+ # A list of Nokogiri::XML::SyntaxError found when parsing a document
65
+ attr_accessor :errors
66
+
67
+ def initialize *args # :nodoc:
68
+ @errors = []
69
+ @decorators = nil
70
+ end
71
+
72
+ ##
73
+ # Create an element with +name+, and optionally setting the content and attributes.
74
+ #
75
+ # doc.create_element "div" # <div></div>
76
+ # doc.create_element "div", :class => "container" # <div class='container'></div>
77
+ # doc.create_element "div", "contents" # <div>contents</div>
78
+ # doc.create_element "div", "contents", :class => "container" # <div class='container'>contents</div>
79
+ # doc.create_element "div" { |node| node['class'] = "container" } # <div class='container'></div>
80
+ #
81
+ def create_element name, *args, &block
82
+ elm = Nokogiri::XML::Element.new(name, self, &block)
83
+ args.each do |arg|
84
+ case arg
85
+ when Hash
86
+ arg.each { |k,v|
87
+ key = k.to_s
88
+ if key =~ NCNAME_RE
89
+ ns_name = key.split(":", 2)[1]
90
+ elm.add_namespace_definition ns_name, v
91
+ else
92
+ elm[k.to_s] = v.to_s
93
+ end
94
+ }
95
+ else
96
+ elm.content = arg
97
+ end
98
+ end
99
+ if ns = elm.namespace_definitions.find { |n| n.prefix.nil? or n.prefix == '' }
100
+ elm.namespace = ns
101
+ end
102
+ elm
103
+ end
104
+
105
+ # Create a Text Node with +string+
106
+ def create_text_node string, &block
107
+ Nokogiri::XML::Text.new string.to_s, self, &block
108
+ end
109
+
110
+ # Create a CDATA Node containing +string+
111
+ def create_cdata string, &block
112
+ Nokogiri::XML::CDATA.new self, string.to_s, &block
113
+ end
114
+
115
+ # Create a Comment Node containing +string+
116
+ def create_comment string, &block
117
+ Nokogiri::XML::Comment.new self, string.to_s, &block
118
+ end
119
+
120
+ # The name of this document. Always returns "document"
121
+ def name
122
+ 'document'
123
+ end
124
+
125
+ # A reference to +self+
126
+ def document
127
+ self
128
+ end
129
+
130
+ ##
131
+ # Recursively get all namespaces from this node and its subtree and
132
+ # return them as a hash.
133
+ #
134
+ # For example, given this document:
135
+ #
136
+ # <root xmlns:foo="bar">
137
+ # <bar xmlns:hello="world" />
138
+ # </root>
139
+ #
140
+ # This method will return:
141
+ #
142
+ # { 'xmlns:foo' => 'bar', 'xmlns:hello' => 'world' }
143
+ #
144
+ # WARNING: this method will clobber duplicate names in the keys.
145
+ # For example, given this document:
146
+ #
147
+ # <root xmlns:foo="bar">
148
+ # <bar xmlns:foo="baz" />
149
+ # </root>
150
+ #
151
+ # The hash returned will look like this: { 'xmlns:foo' => 'bar' }
152
+ #
153
+ # Non-prefixed default namespaces (as in "xmlns=") are not included
154
+ # in the hash.
155
+ #
156
+ # Note that this method does an xpath lookup for nodes with
157
+ # namespaces, and as a result the order may be dependent on the
158
+ # implementation of the underlying XML library.
159
+ #
160
+ def collect_namespaces
161
+ xpath("//namespace::*").inject({}) do |hash, ns|
162
+ hash[["xmlns",ns.prefix].compact.join(":")] = ns.href if ns.prefix != "xml"
163
+ hash
164
+ end
165
+ end
166
+
167
+ # Get the list of decorators given +key+
168
+ def decorators key
169
+ @decorators ||= Hash.new
170
+ @decorators[key] ||= []
171
+ end
172
+
173
+ ##
174
+ # Validate this Document against it's DTD. Returns a list of errors on
175
+ # the document or +nil+ when there is no DTD.
176
+ def validate
177
+ return nil unless internal_subset
178
+ internal_subset.validate self
179
+ end
180
+
181
+ ##
182
+ # Explore a document with shortcut methods. See Nokogiri::Slop for details.
183
+ #
184
+ # Note that any nodes that have been instantiated before #slop!
185
+ # is called will not be decorated with sloppy behavior. So, if you're in
186
+ # irb, the preferred idiom is:
187
+ #
188
+ # irb> doc = Nokogiri::Slop my_markup
189
+ #
190
+ # and not
191
+ #
192
+ # irb> doc = Nokogiri::HTML my_markup
193
+ # ... followed by irb's implicit inspect (and therefore instantiation of every node) ...
194
+ # irb> doc.slop!
195
+ # ... which does absolutely nothing.
196
+ #
197
+ def slop!
198
+ unless decorators(XML::Node).include? Nokogiri::Decorators::Slop
199
+ decorators(XML::Node) << Nokogiri::Decorators::Slop
200
+ decorate!
201
+ end
202
+
203
+ self
204
+ end
205
+
206
+ ##
207
+ # Apply any decorators to +node+
208
+ def decorate node
209
+ return unless @decorators
210
+ @decorators.each { |klass,list|
211
+ next unless node.is_a?(klass)
212
+ list.each { |moodule| node.extend(moodule) }
213
+ }
214
+ end
215
+
216
+ alias :to_xml :serialize
217
+ alias :clone :dup
218
+
219
+ # Get the hash of namespaces on the root Nokogiri::XML::Node
220
+ def namespaces
221
+ root ? root.namespaces : {}
222
+ end
223
+
224
+ ##
225
+ # Create a Nokogiri::XML::DocumentFragment from +tags+
226
+ # Returns an empty fragment if +tags+ is nil.
227
+ def fragment tags = nil
228
+ DocumentFragment.new(self, tags, self.root)
229
+ end
230
+
231
+ undef_method :swap, :parent, :namespace, :default_namespace=
232
+ undef_method :add_namespace_definition, :attributes
233
+ undef_method :namespace_definitions, :line, :add_namespace
234
+
235
+ def add_child node_or_tags
236
+ raise "Document already has a root node" if root && root.name != 'nokogiri_text_wrapper'
237
+ node_or_tags = coerce(node_or_tags)
238
+ if node_or_tags.is_a?(XML::NodeSet)
239
+ raise "Document cannot have multiple root nodes" if node_or_tags.size > 1
240
+ super(node_or_tags.first)
241
+ else
242
+ super
243
+ end
244
+ end
245
+ alias :<< :add_child
246
+
247
+ ##
248
+ # +JRuby+
249
+ # Wraps Java's org.w3c.dom.document and returns Nokogiri::XML::Document
250
+ def self.wrap document
251
+ raise "JRuby only method" unless Nokogiri.jruby?
252
+ return wrapJavaDocument(document)
253
+ end
254
+
255
+ ##
256
+ # +JRuby+
257
+ # Returns Java's org.w3c.dom.document of this Document.
258
+ def to_java
259
+ raise "JRuby only method" unless Nokogiri.jruby?
260
+ return toJavaDocument()
261
+ end
262
+
263
+ private
264
+ def self.empty_doc? string_or_io
265
+ string_or_io.nil? ||
266
+ (string_or_io.respond_to?(:empty?) && string_or_io.empty?) ||
267
+ (string_or_io.respond_to?(:eof?) && string_or_io.eof?)
268
+ end
269
+
270
+ def implied_xpath_context
271
+ "/"
272
+ end
273
+
274
+ def inspect_attributes
275
+ [:name, :children]
276
+ end
277
+ end
278
+ end
279
+ end
@@ -0,0 +1,112 @@
1
+ module Nokogiri
2
+ module XML
3
+ class DocumentFragment < Nokogiri::XML::Node
4
+ ##
5
+ # Create a new DocumentFragment from +tags+.
6
+ #
7
+ # If +ctx+ is present, it is used as a context node for the
8
+ # subtree created, e.g., namespaces will be resolved relative
9
+ # to +ctx+.
10
+ def initialize document, tags = nil, ctx = nil
11
+ return self unless tags
12
+
13
+ children = if ctx
14
+ # Fix for issue#490
15
+ if Nokogiri.jruby?
16
+ # fix for issue #770
17
+ ctx.parse("<root #{namespace_declarations(ctx)}>#{tags}</root>").children
18
+ else
19
+ ctx.parse(tags)
20
+ end
21
+ else
22
+ XML::Document.parse("<root>#{tags}</root>") \
23
+ .xpath("/root/node()")
24
+ end
25
+ children.each { |child| child.parent = self }
26
+ end
27
+
28
+ ###
29
+ # return the name for DocumentFragment
30
+ def name
31
+ '#document-fragment'
32
+ end
33
+
34
+ ###
35
+ # Convert this DocumentFragment to a string
36
+ def to_s
37
+ children.to_s
38
+ end
39
+
40
+ ###
41
+ # Convert this DocumentFragment to html
42
+ # See Nokogiri::XML::NodeSet#to_html
43
+ def to_html *args
44
+ if Nokogiri.jruby?
45
+ options = args.first.is_a?(Hash) ? args.shift : {}
46
+ if !options[:save_with]
47
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
48
+ end
49
+ args.insert(0, options)
50
+ end
51
+ children.to_html(*args)
52
+ end
53
+
54
+ ###
55
+ # Convert this DocumentFragment to xhtml
56
+ # See Nokogiri::XML::NodeSet#to_xhtml
57
+ def to_xhtml *args
58
+ if Nokogiri.jruby?
59
+ options = args.first.is_a?(Hash) ? args.shift : {}
60
+ if !options[:save_with]
61
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_XHTML
62
+ end
63
+ args.insert(0, options)
64
+ end
65
+ children.to_xhtml(*args)
66
+ end
67
+
68
+ ###
69
+ # Convert this DocumentFragment to xml
70
+ # See Nokogiri::XML::NodeSet#to_xml
71
+ def to_xml *args
72
+ children.to_xml(*args)
73
+ end
74
+
75
+ ###
76
+ # Search this fragment. See Nokogiri::XML::Node#css
77
+ def css *args
78
+ if children.any?
79
+ children.css(*args)
80
+ else
81
+ NodeSet.new(document)
82
+ end
83
+ end
84
+
85
+ alias :serialize :to_s
86
+
87
+ class << self
88
+ ####
89
+ # Create a Nokogiri::XML::DocumentFragment from +tags+
90
+ def parse tags
91
+ self.new(XML::Document.new, tags)
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ # fix for issue 770
98
+ def namespace_declarations ctx
99
+ ctx.namespace_scopes.map do |namespace|
100
+ prefix = namespace.prefix.nil? ? "" : ":#{namespace.prefix}"
101
+ %Q{xmlns#{prefix}="#{namespace.href}"}
102
+ end.join ' '
103
+ end
104
+
105
+ def coerce data
106
+ return super unless String === data
107
+
108
+ document.fragment(data).children
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,32 @@
1
+ module Nokogiri
2
+ module XML
3
+ class DTD < Nokogiri::XML::Node
4
+ undef_method :attribute_nodes
5
+ undef_method :values
6
+ undef_method :content
7
+ undef_method :namespace
8
+ undef_method :namespace_definitions
9
+ undef_method :line if method_defined?(:line)
10
+
11
+ def keys
12
+ attributes.keys
13
+ end
14
+
15
+ def each &block
16
+ attributes.each { |key, value|
17
+ block.call([key, value])
18
+ }
19
+ end
20
+
21
+ def html_dtd?
22
+ name.casecmp('html').zero?
23
+ end
24
+
25
+ def html5_dtd?
26
+ html_dtd? &&
27
+ external_id.nil? &&
28
+ (system_id.nil? || system_id == 'about:legacy-compat')
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,36 @@
1
+ module Nokogiri
2
+ module XML
3
+ ###
4
+ # Represents the allowed content in an Element Declaration inside a DTD:
5
+ #
6
+ # <?xml version="1.0"?><?TEST-STYLE PIDATA?>
7
+ # <!DOCTYPE staff SYSTEM "staff.dtd" [
8
+ # <!ELEMENT div1 (head, (p | list | note)*, div2*)>
9
+ # ]>
10
+ # </root>
11
+ #
12
+ # ElementContent represents the tree inside the <!ELEMENT> tag shown above
13
+ # that lists the possible content for the div1 tag.
14
+ class ElementContent
15
+ # Possible definitions of type
16
+ PCDATA = 1
17
+ ELEMENT = 2
18
+ SEQ = 3
19
+ OR = 4
20
+
21
+ # Possible content occurrences
22
+ ONCE = 1
23
+ OPT = 2
24
+ MULT = 3
25
+ PLUS = 4
26
+
27
+ attr_reader :document
28
+
29
+ ###
30
+ # Get the children of this ElementContent node
31
+ def children
32
+ [c1, c2].compact
33
+ end
34
+ end
35
+ end
36
+ end