nokogiri-fitzsimmons 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (237) hide show
  1. data/.autotest +26 -0
  2. data/.gemtest +0 -0
  3. data/CHANGELOG.ja.rdoc +666 -0
  4. data/CHANGELOG.rdoc +659 -0
  5. data/C_CODING_STYLE.rdoc +33 -0
  6. data/Manifest.txt +295 -0
  7. data/README.ja.rdoc +106 -0
  8. data/README.rdoc +178 -0
  9. data/ROADMAP.md +86 -0
  10. data/Rakefile +194 -0
  11. data/STANDARD_RESPONSES.md +47 -0
  12. data/Y_U_NO_GEMSPEC.md +155 -0
  13. data/bin/nokogiri +63 -0
  14. data/build_all +58 -0
  15. data/ext/nokogiri/depend +358 -0
  16. data/ext/nokogiri/extconf.rb +142 -0
  17. data/ext/nokogiri/html_document.c +170 -0
  18. data/ext/nokogiri/html_document.h +10 -0
  19. data/ext/nokogiri/html_element_description.c +276 -0
  20. data/ext/nokogiri/html_element_description.h +10 -0
  21. data/ext/nokogiri/html_entity_lookup.c +32 -0
  22. data/ext/nokogiri/html_entity_lookup.h +8 -0
  23. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  24. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  25. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  26. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  27. data/ext/nokogiri/nokogiri.c +133 -0
  28. data/ext/nokogiri/nokogiri.h +160 -0
  29. data/ext/nokogiri/xml_attr.c +94 -0
  30. data/ext/nokogiri/xml_attr.h +9 -0
  31. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  32. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  33. data/ext/nokogiri/xml_cdata.c +56 -0
  34. data/ext/nokogiri/xml_cdata.h +9 -0
  35. data/ext/nokogiri/xml_comment.c +54 -0
  36. data/ext/nokogiri/xml_comment.h +9 -0
  37. data/ext/nokogiri/xml_document.c +576 -0
  38. data/ext/nokogiri/xml_document.h +23 -0
  39. data/ext/nokogiri/xml_document_fragment.c +48 -0
  40. data/ext/nokogiri/xml_document_fragment.h +10 -0
  41. data/ext/nokogiri/xml_dtd.c +202 -0
  42. data/ext/nokogiri/xml_dtd.h +10 -0
  43. data/ext/nokogiri/xml_element_content.c +123 -0
  44. data/ext/nokogiri/xml_element_content.h +10 -0
  45. data/ext/nokogiri/xml_element_decl.c +69 -0
  46. data/ext/nokogiri/xml_element_decl.h +9 -0
  47. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  48. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  49. data/ext/nokogiri/xml_entity_decl.c +110 -0
  50. data/ext/nokogiri/xml_entity_decl.h +10 -0
  51. data/ext/nokogiri/xml_entity_reference.c +52 -0
  52. data/ext/nokogiri/xml_entity_reference.h +9 -0
  53. data/ext/nokogiri/xml_io.c +56 -0
  54. data/ext/nokogiri/xml_io.h +11 -0
  55. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  56. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  57. data/ext/nokogiri/xml_namespace.c +78 -0
  58. data/ext/nokogiri/xml_namespace.h +13 -0
  59. data/ext/nokogiri/xml_node.c +1480 -0
  60. data/ext/nokogiri/xml_node.h +13 -0
  61. data/ext/nokogiri/xml_node_set.c +467 -0
  62. data/ext/nokogiri/xml_node_set.h +14 -0
  63. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  64. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  65. data/ext/nokogiri/xml_reader.c +684 -0
  66. data/ext/nokogiri/xml_reader.h +10 -0
  67. data/ext/nokogiri/xml_relax_ng.c +161 -0
  68. data/ext/nokogiri/xml_relax_ng.h +9 -0
  69. data/ext/nokogiri/xml_sax_parser.c +293 -0
  70. data/ext/nokogiri/xml_sax_parser.h +39 -0
  71. data/ext/nokogiri/xml_sax_parser_context.c +222 -0
  72. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  73. data/ext/nokogiri/xml_sax_push_parser.c +115 -0
  74. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  75. data/ext/nokogiri/xml_schema.c +205 -0
  76. data/ext/nokogiri/xml_schema.h +9 -0
  77. data/ext/nokogiri/xml_syntax_error.c +58 -0
  78. data/ext/nokogiri/xml_syntax_error.h +13 -0
  79. data/ext/nokogiri/xml_text.c +52 -0
  80. data/ext/nokogiri/xml_text.h +9 -0
  81. data/ext/nokogiri/xml_xpath_context.c +319 -0
  82. data/ext/nokogiri/xml_xpath_context.h +10 -0
  83. data/ext/nokogiri/xslt_stylesheet.c +270 -0
  84. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  85. data/lib/nokogiri.rb +127 -0
  86. data/lib/nokogiri/css.rb +27 -0
  87. data/lib/nokogiri/css/node.rb +102 -0
  88. data/lib/nokogiri/css/parser.rb +720 -0
  89. data/lib/nokogiri/css/parser.y +258 -0
  90. data/lib/nokogiri/css/parser_extras.rb +91 -0
  91. data/lib/nokogiri/css/syntax_error.rb +7 -0
  92. data/lib/nokogiri/css/tokenizer.rb +152 -0
  93. data/lib/nokogiri/css/tokenizer.rex +55 -0
  94. data/lib/nokogiri/css/xpath_visitor.rb +171 -0
  95. data/lib/nokogiri/decorators/slop.rb +35 -0
  96. data/lib/nokogiri/html.rb +37 -0
  97. data/lib/nokogiri/html/builder.rb +35 -0
  98. data/lib/nokogiri/html/document.rb +254 -0
  99. data/lib/nokogiri/html/document_fragment.rb +41 -0
  100. data/lib/nokogiri/html/element_description.rb +23 -0
  101. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  102. data/lib/nokogiri/html/entity_lookup.rb +13 -0
  103. data/lib/nokogiri/html/sax/parser.rb +52 -0
  104. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  105. data/lib/nokogiri/html/sax/push_parser.rb +16 -0
  106. data/lib/nokogiri/syntax_error.rb +4 -0
  107. data/lib/nokogiri/version.rb +88 -0
  108. data/lib/nokogiri/xml.rb +73 -0
  109. data/lib/nokogiri/xml/attr.rb +14 -0
  110. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  111. data/lib/nokogiri/xml/builder.rb +431 -0
  112. data/lib/nokogiri/xml/cdata.rb +11 -0
  113. data/lib/nokogiri/xml/character_data.rb +7 -0
  114. data/lib/nokogiri/xml/document.rb +267 -0
  115. data/lib/nokogiri/xml/document_fragment.rb +103 -0
  116. data/lib/nokogiri/xml/dtd.rb +22 -0
  117. data/lib/nokogiri/xml/element_content.rb +36 -0
  118. data/lib/nokogiri/xml/element_decl.rb +13 -0
  119. data/lib/nokogiri/xml/entity_decl.rb +19 -0
  120. data/lib/nokogiri/xml/namespace.rb +13 -0
  121. data/lib/nokogiri/xml/node.rb +946 -0
  122. data/lib/nokogiri/xml/node/save_options.rb +61 -0
  123. data/lib/nokogiri/xml/node_set.rb +357 -0
  124. data/lib/nokogiri/xml/notation.rb +6 -0
  125. data/lib/nokogiri/xml/parse_options.rb +98 -0
  126. data/lib/nokogiri/xml/pp.rb +2 -0
  127. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  128. data/lib/nokogiri/xml/pp/node.rb +56 -0
  129. data/lib/nokogiri/xml/processing_instruction.rb +8 -0
  130. data/lib/nokogiri/xml/reader.rb +112 -0
  131. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  132. data/lib/nokogiri/xml/sax.rb +4 -0
  133. data/lib/nokogiri/xml/sax/document.rb +164 -0
  134. data/lib/nokogiri/xml/sax/parser.rb +115 -0
  135. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  136. data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
  137. data/lib/nokogiri/xml/schema.rb +63 -0
  138. data/lib/nokogiri/xml/syntax_error.rb +47 -0
  139. data/lib/nokogiri/xml/text.rb +9 -0
  140. data/lib/nokogiri/xml/xpath.rb +10 -0
  141. data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
  142. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  143. data/lib/nokogiri/xslt.rb +56 -0
  144. data/lib/nokogiri/xslt/stylesheet.rb +25 -0
  145. data/lib/xsd/xmlparser/nokogiri.rb +90 -0
  146. data/tasks/cross_compile.rb +153 -0
  147. data/tasks/nokogiri.org.rb +24 -0
  148. data/tasks/test.rb +95 -0
  149. data/test/css/test_nthiness.rb +159 -0
  150. data/test/css/test_parser.rb +341 -0
  151. data/test/css/test_tokenizer.rb +198 -0
  152. data/test/css/test_xpath_visitor.rb +91 -0
  153. data/test/decorators/test_slop.rb +16 -0
  154. data/test/files/2ch.html +108 -0
  155. data/test/files/address_book.rlx +12 -0
  156. data/test/files/address_book.xml +10 -0
  157. data/test/files/bar/bar.xsd +4 -0
  158. data/test/files/dont_hurt_em_why.xml +422 -0
  159. data/test/files/encoding.html +82 -0
  160. data/test/files/encoding.xhtml +84 -0
  161. data/test/files/exslt.xml +8 -0
  162. data/test/files/exslt.xslt +35 -0
  163. data/test/files/foo/foo.xsd +4 -0
  164. data/test/files/metacharset.html +10 -0
  165. data/test/files/noencoding.html +47 -0
  166. data/test/files/po.xml +32 -0
  167. data/test/files/po.xsd +66 -0
  168. data/test/files/shift_jis.html +10 -0
  169. data/test/files/shift_jis.xml +5 -0
  170. data/test/files/snuggles.xml +3 -0
  171. data/test/files/staff.dtd +10 -0
  172. data/test/files/staff.xml +59 -0
  173. data/test/files/staff.xslt +32 -0
  174. data/test/files/tlm.html +850 -0
  175. data/test/files/to_be_xincluded.xml +2 -0
  176. data/test/files/valid_bar.xml +2 -0
  177. data/test/files/xinclude.xml +4 -0
  178. data/test/helper.rb +147 -0
  179. data/test/html/sax/test_parser.rb +138 -0
  180. data/test/html/sax/test_parser_context.rb +46 -0
  181. data/test/html/test_builder.rb +164 -0
  182. data/test/html/test_document.rb +529 -0
  183. data/test/html/test_document_encoding.rb +138 -0
  184. data/test/html/test_document_fragment.rb +254 -0
  185. data/test/html/test_element_description.rb +100 -0
  186. data/test/html/test_named_characters.rb +14 -0
  187. data/test/html/test_node.rb +188 -0
  188. data/test/html/test_node_encoding.rb +27 -0
  189. data/test/test_convert_xpath.rb +135 -0
  190. data/test/test_css_cache.rb +45 -0
  191. data/test/test_encoding_handler.rb +46 -0
  192. data/test/test_memory_leak.rb +152 -0
  193. data/test/test_nokogiri.rb +132 -0
  194. data/test/test_reader.rb +488 -0
  195. data/test/test_soap4r_sax.rb +52 -0
  196. data/test/test_xslt_transforms.rb +254 -0
  197. data/test/xml/node/test_save_options.rb +28 -0
  198. data/test/xml/node/test_subclass.rb +44 -0
  199. data/test/xml/sax/test_parser.rb +338 -0
  200. data/test/xml/sax/test_parser_context.rb +106 -0
  201. data/test/xml/sax/test_push_parser.rb +157 -0
  202. data/test/xml/test_attr.rb +64 -0
  203. data/test/xml/test_attribute_decl.rb +86 -0
  204. data/test/xml/test_builder.rb +248 -0
  205. data/test/xml/test_c14n.rb +151 -0
  206. data/test/xml/test_cdata.rb +48 -0
  207. data/test/xml/test_comment.rb +29 -0
  208. data/test/xml/test_document.rb +742 -0
  209. data/test/xml/test_document_encoding.rb +28 -0
  210. data/test/xml/test_document_fragment.rb +216 -0
  211. data/test/xml/test_dtd.rb +103 -0
  212. data/test/xml/test_dtd_encoding.rb +33 -0
  213. data/test/xml/test_element_content.rb +56 -0
  214. data/test/xml/test_element_decl.rb +73 -0
  215. data/test/xml/test_entity_decl.rb +122 -0
  216. data/test/xml/test_entity_reference.rb +235 -0
  217. data/test/xml/test_namespace.rb +75 -0
  218. data/test/xml/test_node.rb +1029 -0
  219. data/test/xml/test_node_attributes.rb +53 -0
  220. data/test/xml/test_node_encoding.rb +107 -0
  221. data/test/xml/test_node_inheritance.rb +32 -0
  222. data/test/xml/test_node_reparenting.rb +374 -0
  223. data/test/xml/test_node_set.rb +755 -0
  224. data/test/xml/test_parse_options.rb +64 -0
  225. data/test/xml/test_processing_instruction.rb +30 -0
  226. data/test/xml/test_reader_encoding.rb +142 -0
  227. data/test/xml/test_relax_ng.rb +60 -0
  228. data/test/xml/test_schema.rb +94 -0
  229. data/test/xml/test_syntax_error.rb +12 -0
  230. data/test/xml/test_text.rb +45 -0
  231. data/test/xml/test_unparented_node.rb +413 -0
  232. data/test/xml/test_xinclude.rb +83 -0
  233. data/test/xml/test_xpath.rb +295 -0
  234. data/test/xslt/test_custom_functions.rb +129 -0
  235. data/test/xslt/test_exception_handling.rb +37 -0
  236. data/test_all +84 -0
  237. metadata +534 -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,267 @@
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
+ doc = if string_or_io.respond_to?(:read)
49
+ url ||= string_or_io.respond_to?(:path) ? string_or_io.path : nil
50
+ read_io(string_or_io, url, encoding, options.to_i)
51
+ else
52
+ # read_memory pukes on empty docs
53
+ return new if string_or_io.nil? or string_or_io.empty?
54
+ read_memory(string_or_io, url, encoding, options.to_i)
55
+ end
56
+
57
+ # do xinclude processing
58
+ doc.do_xinclude(options) if options.xinclude?
59
+
60
+ return doc
61
+ end
62
+
63
+ # A list of Nokogiri::XML::SyntaxError found when parsing a document
64
+ attr_accessor :errors
65
+
66
+ def initialize *args # :nodoc:
67
+ @errors = []
68
+ @decorators = nil
69
+ end
70
+
71
+ ##
72
+ # Create an element with +name+, and optionally setting the content and attributes.
73
+ #
74
+ # doc.create_element "div" # <div></div>
75
+ # doc.create_element "div", :class => "container" # <div class='container'></div>
76
+ # doc.create_element "div", "contents" # <div>contents</div>
77
+ # doc.create_element "div", "contents", :class => "container" # <div class='container'>contents</div>
78
+ # doc.create_element "div" { |node| node['class'] = "container" } # <div class='container'></div>
79
+ #
80
+ def create_element name, *args, &block
81
+ elm = Nokogiri::XML::Element.new(name, self, &block)
82
+ args.each do |arg|
83
+ case arg
84
+ when Hash
85
+ arg.each { |k,v|
86
+ key = k.to_s
87
+ if key =~ NCNAME_RE
88
+ ns_name = key.split(":", 2)[1]
89
+ elm.add_namespace_definition ns_name, v
90
+ next
91
+ end
92
+ elm[k.to_s] = v.to_s
93
+ }
94
+ else
95
+ elm.content = arg
96
+ end
97
+ end
98
+ elm
99
+ end
100
+
101
+ # Create a Text Node with +string+
102
+ def create_text_node string, &block
103
+ Nokogiri::XML::Text.new string.to_s, self, &block
104
+ end
105
+
106
+ # Create a CDATA Node containing +string+
107
+ def create_cdata string, &block
108
+ Nokogiri::XML::CDATA.new self, string.to_s, &block
109
+ end
110
+
111
+ # Create a Comment Node containing +string+
112
+ def create_comment string, &block
113
+ Nokogiri::XML::Comment.new self, string.to_s, &block
114
+ end
115
+
116
+ # The name of this document. Always returns "document"
117
+ def name
118
+ 'document'
119
+ end
120
+
121
+ # A reference to +self+
122
+ def document
123
+ self
124
+ end
125
+
126
+ ##
127
+ # Recursively get all namespaces from this node and its subtree and
128
+ # return them as a hash.
129
+ #
130
+ # For example, given this document:
131
+ #
132
+ # <root xmlns:foo="bar">
133
+ # <bar xmlns:hello="world" />
134
+ # </root>
135
+ #
136
+ # This method will return:
137
+ #
138
+ # { 'xmlns:foo' => 'bar', 'xmlns:hello' => 'world' }
139
+ #
140
+ # WARNING: this method will clobber duplicate names in the keys.
141
+ # For example, given this document:
142
+ #
143
+ # <root xmlns:foo="bar">
144
+ # <bar xmlns:foo="baz" />
145
+ # </root>
146
+ #
147
+ # The hash returned will look like this: { 'xmlns:foo' => 'bar' }
148
+ #
149
+ # Non-prefixed default namespaces (as in "xmlns=") are not included
150
+ # in the hash.
151
+ #
152
+ # Note this is a very expensive operation in current implementation, as it
153
+ # traverses the entire graph, and also has to bring each node across the
154
+ # libxml bridge into a ruby object.
155
+ def collect_namespaces
156
+ ns = {}
157
+ traverse { |j| ns.merge!(j.namespaces) }
158
+ ns
159
+ end
160
+
161
+ # Get the list of decorators given +key+
162
+ def decorators key
163
+ @decorators ||= Hash.new
164
+ @decorators[key] ||= []
165
+ end
166
+
167
+ ##
168
+ # Validate this Document against it's DTD. Returns a list of errors on
169
+ # the document or +nil+ when there is no DTD.
170
+ def validate
171
+ return nil unless internal_subset
172
+ internal_subset.validate self
173
+ end
174
+
175
+ ##
176
+ # Explore a document with shortcut methods. See Nokogiri::Slop for details.
177
+ #
178
+ # Note that any nodes that have been instantiated before #slop!
179
+ # is called will not be decorated with sloppy behavior. So, if you're in
180
+ # irb, the preferred idiom is:
181
+ #
182
+ # irb> doc = Nokogiri::Slop my_markup
183
+ #
184
+ # and not
185
+ #
186
+ # irb> doc = Nokogiri::HTML my_markup
187
+ # ... followed by irb's implicit inspect (and therefore instantiation of every node) ...
188
+ # irb> doc.slop!
189
+ # ... which does absolutely nothing.
190
+ #
191
+ def slop!
192
+ unless decorators(XML::Node).include? Nokogiri::Decorators::Slop
193
+ decorators(XML::Node) << Nokogiri::Decorators::Slop
194
+ decorate!
195
+ end
196
+
197
+ self
198
+ end
199
+
200
+ ##
201
+ # Apply any decorators to +node+
202
+ def decorate node
203
+ return unless @decorators
204
+ @decorators.each { |klass,list|
205
+ next unless node.is_a?(klass)
206
+ list.each { |moodule| node.extend(moodule) }
207
+ }
208
+ end
209
+
210
+ alias :to_xml :serialize
211
+ alias :clone :dup
212
+
213
+ # Get the hash of namespaces on the root Nokogiri::XML::Node
214
+ def namespaces
215
+ root ? root.namespaces : {}
216
+ end
217
+
218
+ ##
219
+ # Create a Nokogiri::XML::DocumentFragment from +tags+
220
+ # Returns an empty fragment if +tags+ is nil.
221
+ def fragment tags = nil
222
+ DocumentFragment.new(self, tags, self.root)
223
+ end
224
+
225
+ undef_method :swap, :parent, :namespace, :default_namespace=
226
+ undef_method :add_namespace_definition, :attributes
227
+ undef_method :namespace_definitions, :line, :add_namespace
228
+
229
+ def add_child node_or_tags
230
+ raise "Document already has a root node" if root
231
+ node_or_tags = coerce(node_or_tags)
232
+ if node_or_tags.is_a?(XML::NodeSet)
233
+ raise "Document cannot have multiple root nodes" if node_or_tags.size > 1
234
+ super(node_or_tags.first)
235
+ else
236
+ super
237
+ end
238
+ end
239
+ alias :<< :add_child
240
+
241
+ ##
242
+ # +JRuby+
243
+ # Wraps Java's org.w3c.dom.document and returns Nokogiri::XML::Document
244
+ def self.wrap document
245
+ raise "JRuby only method" unless Nokogiri.jruby?
246
+ return wrapJavaDocument(document)
247
+ end
248
+
249
+ ##
250
+ # +JRuby+
251
+ # Returns Java's org.w3c.dom.document of this Document.
252
+ def to_java
253
+ raise "JRuby only method" unless Nokogiri.jruby?
254
+ return toJavaDocument()
255
+ end
256
+
257
+ private
258
+ def implied_xpath_context
259
+ "/"
260
+ end
261
+
262
+ def inspect_attributes
263
+ [:name, :children]
264
+ end
265
+ end
266
+ end
267
+ end
@@ -0,0 +1,103 @@
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
+ ctx.parse("<root>#{tags}</root>").xpath("/root/node()")
17
+ else
18
+ ctx.parse(tags)
19
+ end
20
+ else
21
+ XML::Document.parse("<root>#{tags}</root>") \
22
+ .xpath("/root/node()")
23
+ end
24
+ children.each { |child| child.parent = self }
25
+ end
26
+
27
+ ###
28
+ # return the name for DocumentFragment
29
+ def name
30
+ '#document-fragment'
31
+ end
32
+
33
+ ###
34
+ # Convert this DocumentFragment to a string
35
+ def to_s
36
+ children.to_s
37
+ end
38
+
39
+ ###
40
+ # Convert this DocumentFragment to html
41
+ # See Nokogiri::XML::NodeSet#to_html
42
+ def to_html *args
43
+ if Nokogiri.jruby?
44
+ options = args.first.is_a?(Hash) ? args.shift : {}
45
+ if !options[:save_with]
46
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_HTML
47
+ end
48
+ args.insert(0, options)
49
+ end
50
+ children.to_html(*args)
51
+ end
52
+
53
+ ###
54
+ # Convert this DocumentFragment to xhtml
55
+ # See Nokogiri::XML::NodeSet#to_xhtml
56
+ def to_xhtml *args
57
+ if Nokogiri.jruby?
58
+ options = args.first.is_a?(Hash) ? args.shift : {}
59
+ if !options[:save_with]
60
+ options[:save_with] = Node::SaveOptions::NO_DECLARATION | Node::SaveOptions::NO_EMPTY_TAGS | Node::SaveOptions::AS_XHTML
61
+ end
62
+ args.insert(0, options)
63
+ end
64
+ children.to_xhtml(*args)
65
+ end
66
+
67
+ ###
68
+ # Convert this DocumentFragment to xml
69
+ # See Nokogiri::XML::NodeSet#to_xml
70
+ def to_xml *args
71
+ children.to_xml(*args)
72
+ end
73
+
74
+ ###
75
+ # Search this fragment. See Nokogiri::XML::Node#css
76
+ def css *args
77
+ if children.any?
78
+ children.css(*args)
79
+ else
80
+ NodeSet.new(document)
81
+ end
82
+ end
83
+
84
+ alias :serialize :to_s
85
+
86
+ class << self
87
+ ####
88
+ # Create a Nokogiri::XML::DocumentFragment from +tags+
89
+ def parse tags
90
+ self.new(XML::Document.new, tags)
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ def coerce data
97
+ return super unless String === data
98
+
99
+ document.fragment(data).children
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,22 @@
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
+ end
21
+ end
22
+ 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