nokogiri 1.11.0.rc1-x86-linux

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 (145) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE-DEPENDENCIES.md +1614 -0
  3. data/LICENSE.md +9 -0
  4. data/README.md +200 -0
  5. data/bin/nokogiri +118 -0
  6. data/dependencies.yml +74 -0
  7. data/ext/nokogiri/depend +358 -0
  8. data/ext/nokogiri/extconf.rb +695 -0
  9. data/ext/nokogiri/html_document.c +170 -0
  10. data/ext/nokogiri/html_document.h +10 -0
  11. data/ext/nokogiri/html_element_description.c +279 -0
  12. data/ext/nokogiri/html_element_description.h +10 -0
  13. data/ext/nokogiri/html_entity_lookup.c +32 -0
  14. data/ext/nokogiri/html_entity_lookup.h +8 -0
  15. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  16. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  17. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  18. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  19. data/ext/nokogiri/nokogiri.c +147 -0
  20. data/ext/nokogiri/nokogiri.h +122 -0
  21. data/ext/nokogiri/xml_attr.c +103 -0
  22. data/ext/nokogiri/xml_attr.h +9 -0
  23. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  24. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  25. data/ext/nokogiri/xml_cdata.c +62 -0
  26. data/ext/nokogiri/xml_cdata.h +9 -0
  27. data/ext/nokogiri/xml_comment.c +69 -0
  28. data/ext/nokogiri/xml_comment.h +9 -0
  29. data/ext/nokogiri/xml_document.c +617 -0
  30. data/ext/nokogiri/xml_document.h +23 -0
  31. data/ext/nokogiri/xml_document_fragment.c +48 -0
  32. data/ext/nokogiri/xml_document_fragment.h +10 -0
  33. data/ext/nokogiri/xml_dtd.c +202 -0
  34. data/ext/nokogiri/xml_dtd.h +10 -0
  35. data/ext/nokogiri/xml_element_content.c +123 -0
  36. data/ext/nokogiri/xml_element_content.h +10 -0
  37. data/ext/nokogiri/xml_element_decl.c +69 -0
  38. data/ext/nokogiri/xml_element_decl.h +9 -0
  39. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  40. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  41. data/ext/nokogiri/xml_entity_decl.c +110 -0
  42. data/ext/nokogiri/xml_entity_decl.h +10 -0
  43. data/ext/nokogiri/xml_entity_reference.c +52 -0
  44. data/ext/nokogiri/xml_entity_reference.h +9 -0
  45. data/ext/nokogiri/xml_io.c +61 -0
  46. data/ext/nokogiri/xml_io.h +11 -0
  47. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  48. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  49. data/ext/nokogiri/xml_namespace.c +111 -0
  50. data/ext/nokogiri/xml_namespace.h +14 -0
  51. data/ext/nokogiri/xml_node.c +1773 -0
  52. data/ext/nokogiri/xml_node.h +13 -0
  53. data/ext/nokogiri/xml_node_set.c +486 -0
  54. data/ext/nokogiri/xml_node_set.h +12 -0
  55. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  56. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  57. data/ext/nokogiri/xml_reader.c +668 -0
  58. data/ext/nokogiri/xml_reader.h +10 -0
  59. data/ext/nokogiri/xml_relax_ng.c +161 -0
  60. data/ext/nokogiri/xml_relax_ng.h +9 -0
  61. data/ext/nokogiri/xml_sax_parser.c +310 -0
  62. data/ext/nokogiri/xml_sax_parser.h +39 -0
  63. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  64. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  65. data/ext/nokogiri/xml_sax_push_parser.c +159 -0
  66. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  67. data/ext/nokogiri/xml_schema.c +205 -0
  68. data/ext/nokogiri/xml_schema.h +9 -0
  69. data/ext/nokogiri/xml_syntax_error.c +64 -0
  70. data/ext/nokogiri/xml_syntax_error.h +13 -0
  71. data/ext/nokogiri/xml_text.c +52 -0
  72. data/ext/nokogiri/xml_text.h +9 -0
  73. data/ext/nokogiri/xml_xpath_context.c +298 -0
  74. data/ext/nokogiri/xml_xpath_context.h +10 -0
  75. data/ext/nokogiri/xslt_stylesheet.c +266 -0
  76. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  77. data/lib/nokogiri.rb +127 -0
  78. data/lib/nokogiri/2.4/nokogiri.so +0 -0
  79. data/lib/nokogiri/2.5/nokogiri.so +0 -0
  80. data/lib/nokogiri/2.6/nokogiri.so +0 -0
  81. data/lib/nokogiri/2.7/nokogiri.so +0 -0
  82. data/lib/nokogiri/css.rb +28 -0
  83. data/lib/nokogiri/css/node.rb +53 -0
  84. data/lib/nokogiri/css/parser.rb +751 -0
  85. data/lib/nokogiri/css/parser.y +272 -0
  86. data/lib/nokogiri/css/parser_extras.rb +92 -0
  87. data/lib/nokogiri/css/syntax_error.rb +8 -0
  88. data/lib/nokogiri/css/tokenizer.rb +154 -0
  89. data/lib/nokogiri/css/tokenizer.rex +55 -0
  90. data/lib/nokogiri/css/xpath_visitor.rb +232 -0
  91. data/lib/nokogiri/decorators/slop.rb +43 -0
  92. data/lib/nokogiri/html.rb +38 -0
  93. data/lib/nokogiri/html/builder.rb +36 -0
  94. data/lib/nokogiri/html/document.rb +336 -0
  95. data/lib/nokogiri/html/document_fragment.rb +50 -0
  96. data/lib/nokogiri/html/element_description.rb +24 -0
  97. data/lib/nokogiri/html/element_description_defaults.rb +672 -0
  98. data/lib/nokogiri/html/entity_lookup.rb +14 -0
  99. data/lib/nokogiri/html/sax/parser.rb +63 -0
  100. data/lib/nokogiri/html/sax/parser_context.rb +17 -0
  101. data/lib/nokogiri/html/sax/push_parser.rb +37 -0
  102. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  103. data/lib/nokogiri/syntax_error.rb +5 -0
  104. data/lib/nokogiri/version.rb +149 -0
  105. data/lib/nokogiri/xml.rb +76 -0
  106. data/lib/nokogiri/xml/attr.rb +15 -0
  107. data/lib/nokogiri/xml/attribute_decl.rb +19 -0
  108. data/lib/nokogiri/xml/builder.rb +447 -0
  109. data/lib/nokogiri/xml/cdata.rb +12 -0
  110. data/lib/nokogiri/xml/character_data.rb +8 -0
  111. data/lib/nokogiri/xml/document.rb +280 -0
  112. data/lib/nokogiri/xml/document_fragment.rb +161 -0
  113. data/lib/nokogiri/xml/dtd.rb +33 -0
  114. data/lib/nokogiri/xml/element_content.rb +37 -0
  115. data/lib/nokogiri/xml/element_decl.rb +14 -0
  116. data/lib/nokogiri/xml/entity_decl.rb +20 -0
  117. data/lib/nokogiri/xml/entity_reference.rb +19 -0
  118. data/lib/nokogiri/xml/namespace.rb +14 -0
  119. data/lib/nokogiri/xml/node.rb +916 -0
  120. data/lib/nokogiri/xml/node/save_options.rb +62 -0
  121. data/lib/nokogiri/xml/node_set.rb +372 -0
  122. data/lib/nokogiri/xml/notation.rb +7 -0
  123. data/lib/nokogiri/xml/parse_options.rb +121 -0
  124. data/lib/nokogiri/xml/pp.rb +3 -0
  125. data/lib/nokogiri/xml/pp/character_data.rb +19 -0
  126. data/lib/nokogiri/xml/pp/node.rb +57 -0
  127. data/lib/nokogiri/xml/processing_instruction.rb +9 -0
  128. data/lib/nokogiri/xml/reader.rb +116 -0
  129. data/lib/nokogiri/xml/relax_ng.rb +33 -0
  130. data/lib/nokogiri/xml/sax.rb +5 -0
  131. data/lib/nokogiri/xml/sax/document.rb +172 -0
  132. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  133. data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
  134. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  135. data/lib/nokogiri/xml/schema.rb +64 -0
  136. data/lib/nokogiri/xml/searchable.rb +231 -0
  137. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  138. data/lib/nokogiri/xml/text.rb +10 -0
  139. data/lib/nokogiri/xml/xpath.rb +11 -0
  140. data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
  141. data/lib/nokogiri/xml/xpath_context.rb +17 -0
  142. data/lib/nokogiri/xslt.rb +57 -0
  143. data/lib/nokogiri/xslt/stylesheet.rb +26 -0
  144. data/lib/xsd/xmlparser/nokogiri.rb +103 -0
  145. metadata +482 -0
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ class CDATA < Nokogiri::XML::Text
5
+ ###
6
+ # Get the name of this CDATA node
7
+ def name
8
+ '#cdata-section'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ class CharacterData < Nokogiri::XML::Node
5
+ include Nokogiri::XML::PP::CharacterData
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,280 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ ##
5
+ # Nokogiri::XML::Document is the main entry point for dealing with
6
+ # XML documents. The Document is created by parsing an XML document.
7
+ # See Nokogiri::XML::Document.parse() for more information on parsing.
8
+ #
9
+ # For searching a Document, see Nokogiri::XML::Searchable#css and
10
+ # Nokogiri::XML::Searchable#xpath
11
+ #
12
+ class Document < Nokogiri::XML::Node
13
+ # I'm ignoring unicode characters here.
14
+ # See http://www.w3.org/TR/REC-xml-names/#ns-decl for more details.
15
+ NCNAME_START_CHAR = "A-Za-z_"
16
+ NCNAME_CHAR = NCNAME_START_CHAR + "\\-.0-9"
17
+ NCNAME_RE = /^xmlns(:[#{NCNAME_START_CHAR}][#{NCNAME_CHAR}]*)?$/
18
+
19
+ ##
20
+ # Parse an XML file.
21
+ #
22
+ # +string_or_io+ may be a String, or any object that responds to
23
+ # _read_ and _close_ such as an IO, or StringIO.
24
+ #
25
+ # +url+ (optional) is the URI where this document is located.
26
+ #
27
+ # +encoding+ (optional) is the encoding that should be used when processing
28
+ # the document.
29
+ #
30
+ # +options+ (optional) is a configuration object that sets options during
31
+ # parsing, such as Nokogiri::XML::ParseOptions::RECOVER. See the
32
+ # Nokogiri::XML::ParseOptions for more information.
33
+ #
34
+ # +block+ (optional) is passed a configuration object on which
35
+ # parse options may be set.
36
+ #
37
+ # By default, Nokogiri treats documents as untrusted, and so
38
+ # does not attempt to load DTDs or access the network. See
39
+ # Nokogiri::XML::ParseOptions for a complete list of options;
40
+ # and that module's DEFAULT_XML constant for what's set (and not
41
+ # set) by default.
42
+ #
43
+ # Nokogiri.XML() is a convenience method which will call this method.
44
+ #
45
+ def self.parse string_or_io, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML
46
+ options = Nokogiri::XML::ParseOptions.new(options) if Integer === options
47
+ # Give the options to the user
48
+ yield options if block_given?
49
+
50
+ if empty_doc?(string_or_io)
51
+ if options.strict?
52
+ raise Nokogiri::XML::SyntaxError.new("Empty document")
53
+ else
54
+ return encoding ? new.tap { |i| i.encoding = encoding } : new
55
+ end
56
+ end
57
+
58
+ doc = if string_or_io.respond_to?(:read)
59
+ url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil
60
+ read_io(string_or_io, url, encoding, options.to_i)
61
+ else
62
+ # read_memory pukes on empty docs
63
+ read_memory(string_or_io, url, encoding, options.to_i)
64
+ end
65
+
66
+ # do xinclude processing
67
+ doc.do_xinclude(options) if options.xinclude?
68
+
69
+ return doc
70
+ end
71
+
72
+ # A list of Nokogiri::XML::SyntaxError found when parsing a document
73
+ attr_accessor :errors
74
+
75
+ def initialize *args # :nodoc:
76
+ @errors = []
77
+ @decorators = nil
78
+ end
79
+
80
+ ##
81
+ # Create an element with +name+, and optionally setting the content and attributes.
82
+ #
83
+ # doc.create_element "div" # <div></div>
84
+ # doc.create_element "div", :class => "container" # <div class='container'></div>
85
+ # doc.create_element "div", "contents" # <div>contents</div>
86
+ # doc.create_element "div", "contents", :class => "container" # <div class='container'>contents</div>
87
+ # doc.create_element "div" { |node| node['class'] = "container" } # <div class='container'></div>
88
+ #
89
+ def create_element name, *args, &block
90
+ elm = Nokogiri::XML::Element.new(name, self, &block)
91
+ args.each do |arg|
92
+ case arg
93
+ when Hash
94
+ arg.each { |k,v|
95
+ key = k.to_s
96
+ if key =~ NCNAME_RE
97
+ ns_name = key.split(":", 2)[1]
98
+ elm.add_namespace_definition ns_name, v
99
+ else
100
+ elm[k.to_s] = v.to_s
101
+ end
102
+ }
103
+ else
104
+ elm.content = arg
105
+ end
106
+ end
107
+ if ns = elm.namespace_definitions.find { |n| n.prefix.nil? or n.prefix == '' }
108
+ elm.namespace = ns
109
+ end
110
+ elm
111
+ end
112
+
113
+ # Create a Text Node with +string+
114
+ def create_text_node string, &block
115
+ Nokogiri::XML::Text.new string.to_s, self, &block
116
+ end
117
+
118
+ # Create a CDATA Node containing +string+
119
+ def create_cdata string, &block
120
+ Nokogiri::XML::CDATA.new self, string.to_s, &block
121
+ end
122
+
123
+ # Create a Comment Node containing +string+
124
+ def create_comment string, &block
125
+ Nokogiri::XML::Comment.new self, string.to_s, &block
126
+ end
127
+
128
+ # The name of this document. Always returns "document"
129
+ def name
130
+ 'document'
131
+ end
132
+
133
+ # A reference to +self+
134
+ def document
135
+ self
136
+ end
137
+
138
+ ##
139
+ # Recursively get all namespaces from this node and its subtree and
140
+ # return them as a hash.
141
+ #
142
+ # For example, given this document:
143
+ #
144
+ # <root xmlns:foo="bar">
145
+ # <bar xmlns:hello="world" />
146
+ # </root>
147
+ #
148
+ # This method will return:
149
+ #
150
+ # { 'xmlns:foo' => 'bar', 'xmlns:hello' => 'world' }
151
+ #
152
+ # WARNING: this method will clobber duplicate names in the keys.
153
+ # For example, given this document:
154
+ #
155
+ # <root xmlns:foo="bar">
156
+ # <bar xmlns:foo="baz" />
157
+ # </root>
158
+ #
159
+ # The hash returned will look like this: { 'xmlns:foo' => 'bar' }
160
+ #
161
+ # Non-prefixed default namespaces (as in "xmlns=") are not included
162
+ # in the hash.
163
+ #
164
+ # Note that this method does an xpath lookup for nodes with
165
+ # namespaces, and as a result the order may be dependent on the
166
+ # implementation of the underlying XML library.
167
+ #
168
+ def collect_namespaces
169
+ xpath("//namespace::*").inject({}) do |hash, ns|
170
+ hash[["xmlns",ns.prefix].compact.join(":")] = ns.href if ns.prefix != "xml"
171
+ hash
172
+ end
173
+ end
174
+
175
+ # Get the list of decorators given +key+
176
+ def decorators key
177
+ @decorators ||= Hash.new
178
+ @decorators[key] ||= []
179
+ end
180
+
181
+ ##
182
+ # Validate this Document against it's DTD. Returns a list of errors on
183
+ # the document or +nil+ when there is no DTD.
184
+ def validate
185
+ return nil unless internal_subset
186
+ internal_subset.validate self
187
+ end
188
+
189
+ ##
190
+ # Explore a document with shortcut methods. See Nokogiri::Slop for details.
191
+ #
192
+ # Note that any nodes that have been instantiated before #slop!
193
+ # is called will not be decorated with sloppy behavior. So, if you're in
194
+ # irb, the preferred idiom is:
195
+ #
196
+ # irb> doc = Nokogiri::Slop my_markup
197
+ #
198
+ # and not
199
+ #
200
+ # irb> doc = Nokogiri::HTML my_markup
201
+ # ... followed by irb's implicit inspect (and therefore instantiation of every node) ...
202
+ # irb> doc.slop!
203
+ # ... which does absolutely nothing.
204
+ #
205
+ def slop!
206
+ unless decorators(XML::Node).include? Nokogiri::Decorators::Slop
207
+ decorators(XML::Node) << Nokogiri::Decorators::Slop
208
+ decorate!
209
+ end
210
+
211
+ self
212
+ end
213
+
214
+ ##
215
+ # Apply any decorators to +node+
216
+ def decorate node
217
+ return unless @decorators
218
+ @decorators.each { |klass,list|
219
+ next unless node.is_a?(klass)
220
+ list.each { |moodule| node.extend(moodule) }
221
+ }
222
+ end
223
+
224
+ alias :to_xml :serialize
225
+ alias :clone :dup
226
+
227
+ # Get the hash of namespaces on the root Nokogiri::XML::Node
228
+ def namespaces
229
+ root ? root.namespaces : {}
230
+ end
231
+
232
+ ##
233
+ # Create a Nokogiri::XML::DocumentFragment from +tags+
234
+ # Returns an empty fragment if +tags+ is nil.
235
+ def fragment tags = nil
236
+ DocumentFragment.new(self, tags, self.root)
237
+ end
238
+
239
+ undef_method :swap, :parent, :namespace, :default_namespace=
240
+ undef_method :add_namespace_definition, :attributes
241
+ undef_method :namespace_definitions, :line, :add_namespace
242
+
243
+ def add_child node_or_tags
244
+ raise "A document may not have multiple root nodes." if (root && root.name != 'nokogiri_text_wrapper') && !(node_or_tags.comment? || node_or_tags.processing_instruction?)
245
+ node_or_tags = coerce(node_or_tags)
246
+ if node_or_tags.is_a?(XML::NodeSet)
247
+ raise "A document may not have multiple root nodes." if node_or_tags.size > 1
248
+ super(node_or_tags.first)
249
+ else
250
+ super
251
+ end
252
+ end
253
+ alias :<< :add_child
254
+
255
+ ##
256
+ # +JRuby+
257
+ # Wraps Java's org.w3c.dom.document and returns Nokogiri::XML::Document
258
+ def self.wrap(document) end if false # native-ext provides Document.wrap
259
+
260
+ ##
261
+ # +JRuby+
262
+ # Returns Java's org.w3c.dom.document of this Document.
263
+ def to_java; end if false # JRuby provides #to_java
264
+
265
+ private
266
+ def self.empty_doc? string_or_io
267
+ string_or_io.nil? ||
268
+ (string_or_io.respond_to?(:empty?) && string_or_io.empty?) ||
269
+ (string_or_io.respond_to?(:eof?) && string_or_io.eof?)
270
+ end
271
+
272
+ # @private
273
+ IMPLIED_XPATH_CONTEXTS = [ '//'.freeze ].freeze # :nodoc:
274
+
275
+ def inspect_attributes
276
+ [:name, :children]
277
+ end
278
+ end
279
+ end
280
+ end
@@ -0,0 +1,161 @@
1
+ # frozen_string_literal: true
2
+ module Nokogiri
3
+ module XML
4
+ class DocumentFragment < Nokogiri::XML::Node
5
+ ##
6
+ # Create a new DocumentFragment from +tags+.
7
+ #
8
+ # If +ctx+ is present, it is used as a context node for the
9
+ # subtree created, e.g., namespaces will be resolved relative
10
+ # to +ctx+.
11
+ def initialize document, tags = nil, ctx = nil
12
+ return self unless tags
13
+
14
+ children = if ctx
15
+ # Fix for issue#490
16
+ if Nokogiri.jruby?
17
+ # fix for issue #770
18
+ ctx.parse("<root #{namespace_declarations(ctx)}>#{tags}</root>").children
19
+ else
20
+ ctx.parse(tags)
21
+ end
22
+ else
23
+ XML::Document.parse("<root>#{tags}</root>") \
24
+ .xpath("/root/node()")
25
+ end
26
+ children.each { |child| child.parent = self }
27
+ end
28
+
29
+ if Nokogiri.uses_libxml?
30
+ def dup
31
+ new_document = document.dup
32
+ new_fragment = self.class.new(new_document)
33
+ children.each do |child|
34
+ child.dup(1, new_document).parent = new_fragment
35
+ end
36
+ new_fragment
37
+ end
38
+ end
39
+
40
+ ###
41
+ # return the name for DocumentFragment
42
+ def name
43
+ '#document-fragment'
44
+ end
45
+
46
+ ###
47
+ # Convert this DocumentFragment to a string
48
+ def to_s
49
+ children.to_s
50
+ end
51
+
52
+ ###
53
+ # Convert this DocumentFragment to html
54
+ # See Nokogiri::XML::NodeSet#to_html
55
+ def to_html *args
56
+ if Nokogiri.jruby?
57
+ options = args.first.is_a?(Hash) ? args.shift : {}
58
+ if !options[:save_with]
59
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
60
+ end
61
+ args.insert(0, options)
62
+ end
63
+ children.to_html(*args)
64
+ end
65
+
66
+ ###
67
+ # Convert this DocumentFragment to xhtml
68
+ # See Nokogiri::XML::NodeSet#to_xhtml
69
+ def to_xhtml *args
70
+ if Nokogiri.jruby?
71
+ options = args.first.is_a?(Hash) ? args.shift : {}
72
+ if !options[:save_with]
73
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_XHTML
74
+ end
75
+ args.insert(0, options)
76
+ end
77
+ children.to_xhtml(*args)
78
+ end
79
+
80
+ ###
81
+ # Convert this DocumentFragment to xml
82
+ # See Nokogiri::XML::NodeSet#to_xml
83
+ def to_xml *args
84
+ children.to_xml(*args)
85
+ end
86
+
87
+ ###
88
+ # call-seq: css *rules, [namespace-bindings, custom-pseudo-class]
89
+ #
90
+ # Search this fragment for CSS +rules+. +rules+ must be one or more CSS
91
+ # selectors. For example:
92
+ #
93
+ # For more information see Nokogiri::XML::Searchable#css
94
+ def css *args
95
+ if children.any?
96
+ children.css(*args) # 'children' is a smell here
97
+ else
98
+ NodeSet.new(document)
99
+ end
100
+ end
101
+
102
+ #
103
+ # NOTE that we don't delegate #xpath to children ... another smell.
104
+ # def xpath ; end
105
+ #
106
+
107
+ ###
108
+ # call-seq: search *paths, [namespace-bindings, xpath-variable-bindings, custom-handler-class]
109
+ #
110
+ # Search this fragment for +paths+. +paths+ must be one or more XPath or CSS queries.
111
+ #
112
+ # For more information see Nokogiri::XML::Searchable#search
113
+ def search *rules
114
+ rules, handler, ns, binds = extract_params(rules)
115
+
116
+ rules.inject(NodeSet.new(document)) do |set, rule|
117
+ set += if rule =~ Searchable::LOOKS_LIKE_XPATH
118
+ xpath(*([rule, ns, handler, binds].compact))
119
+ else
120
+ children.css(*([rule, ns, handler].compact)) # 'children' is a smell here
121
+ end
122
+ end
123
+ end
124
+
125
+ alias :serialize :to_s
126
+
127
+ class << self
128
+ ####
129
+ # Create a Nokogiri::XML::DocumentFragment from +tags+
130
+ def parse tags
131
+ self.new(XML::Document.new, tags)
132
+ end
133
+ end
134
+
135
+ # A list of Nokogiri::XML::SyntaxError found when parsing a document
136
+ def errors
137
+ document.errors
138
+ end
139
+
140
+ def errors= things # :nodoc:
141
+ document.errors = things
142
+ end
143
+
144
+ private
145
+
146
+ # fix for issue 770
147
+ def namespace_declarations ctx
148
+ ctx.namespace_scopes.map do |namespace|
149
+ prefix = namespace.prefix.nil? ? "" : ":#{namespace.prefix}"
150
+ %Q{xmlns#{prefix}="#{namespace.href}"}
151
+ end.join ' '
152
+ end
153
+
154
+ def coerce data
155
+ return super unless String === data
156
+
157
+ document.fragment(data).children
158
+ end
159
+ end
160
+ end
161
+ end