nokogiri 1.4.1-java → 1.4.2-java
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.
- data/CHANGELOG.ja.rdoc +45 -0
- data/CHANGELOG.rdoc +53 -1
- data/Manifest.txt +3 -3
- data/README.ja.rdoc +1 -1
- data/README.rdoc +11 -5
- data/Rakefile +13 -79
- data/ext/nokogiri/extconf.rb +22 -74
- data/ext/nokogiri/html_document.c +17 -8
- data/ext/nokogiri/html_element_description.c +20 -16
- data/ext/nokogiri/html_entity_lookup.c +2 -2
- data/ext/nokogiri/html_sax_parser_context.c +10 -8
- data/ext/nokogiri/libcharset-1.dll +0 -0
- data/ext/nokogiri/libexslt.dll +0 -0
- data/ext/nokogiri/libiconv-2.dll +0 -0
- data/ext/nokogiri/libxml2.dll +0 -0
- data/ext/nokogiri/libxslt.dll +0 -0
- data/ext/nokogiri/nokogiri.c +0 -1
- data/ext/nokogiri/nokogiri.h +33 -28
- data/ext/nokogiri/xml_attr.c +7 -5
- data/ext/nokogiri/xml_attribute_decl.c +5 -2
- data/ext/nokogiri/xml_cdata.c +4 -2
- data/ext/nokogiri/xml_comment.c +4 -2
- data/ext/nokogiri/xml_document.c +93 -15
- data/ext/nokogiri/xml_document.h +0 -1
- data/ext/nokogiri/xml_document_fragment.c +4 -2
- data/ext/nokogiri/xml_dtd.c +18 -8
- data/ext/nokogiri/xml_element_content.c +2 -2
- data/ext/nokogiri/xml_entity_decl.c +15 -2
- data/ext/nokogiri/xml_entity_reference.c +4 -2
- data/ext/nokogiri/xml_io.c +1 -1
- data/ext/nokogiri/xml_namespace.c +5 -3
- data/ext/nokogiri/xml_node.c +353 -114
- data/ext/nokogiri/xml_node_set.c +35 -22
- data/ext/nokogiri/xml_node_set.h +1 -1
- data/ext/nokogiri/xml_processing_instruction.c +4 -2
- data/ext/nokogiri/xml_reader.c +119 -47
- data/ext/nokogiri/xml_relax_ng.c +21 -12
- data/ext/nokogiri/xml_sax_parser.c +6 -3
- data/ext/nokogiri/xml_sax_parser.h +13 -17
- data/ext/nokogiri/xml_sax_parser_context.c +8 -6
- data/ext/nokogiri/xml_sax_push_parser.c +7 -6
- data/ext/nokogiri/xml_schema.c +62 -13
- data/ext/nokogiri/xml_syntax_error.c +18 -12
- data/ext/nokogiri/xml_syntax_error.h +1 -1
- data/ext/nokogiri/xml_text.c +4 -2
- data/ext/nokogiri/xml_xpath_context.c +60 -23
- data/ext/nokogiri/xslt_stylesheet.c +14 -3
- data/ext/nokogiri/zlib1.dll +0 -0
- data/lib/nokogiri.rb +17 -0
- data/lib/nokogiri/css/generated_parser.rb +72 -62
- data/lib/nokogiri/css/generated_tokenizer.rb +23 -24
- data/lib/nokogiri/css/parser.y +3 -1
- data/lib/nokogiri/css/tokenizer.rex +3 -3
- data/lib/nokogiri/css/xpath_visitor.rb +8 -3
- data/lib/nokogiri/ffi/html/sax/parser_context.rb +3 -3
- data/lib/nokogiri/ffi/libxml.rb +16 -2
- data/lib/nokogiri/ffi/structs/common_node.rb +15 -3
- data/lib/nokogiri/ffi/structs/xml_document.rb +13 -4
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +3 -2
- data/lib/nokogiri/ffi/weak_bucket.rb +40 -0
- data/lib/nokogiri/ffi/xml/document.rb +27 -0
- data/lib/nokogiri/ffi/xml/entity_decl.rb +9 -0
- data/lib/nokogiri/ffi/xml/node.rb +142 -61
- data/lib/nokogiri/ffi/xml/node_set.rb +15 -12
- data/lib/nokogiri/ffi/xml/reader.rb +5 -0
- data/lib/nokogiri/ffi/xml/schema.rb +17 -0
- data/lib/nokogiri/ffi/xml/syntax_error.rb +4 -4
- data/lib/nokogiri/ffi/xml/xpath.rb +0 -10
- data/lib/nokogiri/ffi/xml/xpath_context.rb +22 -9
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +3 -0
- data/lib/nokogiri/html/document.rb +5 -3
- data/lib/nokogiri/html/document_fragment.rb +28 -7
- data/lib/nokogiri/nokogiri.rb +1 -0
- data/lib/nokogiri/version.rb +6 -2
- data/lib/nokogiri/version_warning.rb +6 -3
- data/lib/nokogiri/xml.rb +1 -1
- data/lib/nokogiri/xml/builder.rb +35 -22
- data/lib/nokogiri/xml/document.rb +44 -12
- data/lib/nokogiri/xml/document_fragment.rb +16 -12
- data/lib/nokogiri/xml/entity_decl.rb +4 -0
- data/lib/nokogiri/xml/node.rb +152 -95
- data/lib/nokogiri/xml/node_set.rb +2 -1
- data/lib/nokogiri/xml/sax/push_parser.rb +1 -1
- data/lib/nokogiri/xml/schema.rb +1 -5
- data/lib/nokogiri/xml/syntax_error.rb +4 -0
- data/lib/nokogiri/xml/text.rb +9 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +3 -0
- data/tasks/cross_compile.rb +157 -0
- data/tasks/test.rb +0 -6
- data/test/css/test_xpath_visitor.rb +9 -0
- data/test/helper.rb +49 -11
- data/test/html/sax/test_parser.rb +11 -1
- data/test/html/test_document.rb +8 -0
- data/test/html/test_document_fragment.rb +14 -2
- data/test/html/test_element_description.rb +5 -1
- data/test/html/test_node.rb +5 -66
- data/test/test_reader.rb +28 -0
- data/test/test_xslt_transforms.rb +14 -0
- data/test/xml/test_builder.rb +43 -0
- data/test/xml/test_cdata.rb +12 -0
- data/test/xml/test_document.rb +74 -39
- data/test/xml/test_document_fragment.rb +36 -0
- data/test/xml/test_entity_decl.rb +37 -0
- data/test/xml/test_node.rb +192 -65
- data/test/xml/test_node_reparenting.rb +253 -236
- data/test/xml/test_node_set.rb +67 -0
- data/test/xml/test_text.rb +8 -0
- data/test/xml/test_xpath.rb +32 -0
- metadata +119 -48
- data.tar.gz.sig +0 -0
- data/ext/nokogiri/iconv.dll +0 -0
- data/ext/nokogiri/xml_xpath.c +0 -53
- data/ext/nokogiri/xml_xpath.h +0 -11
- data/lib/nokogiri/xml/fragment_handler.rb +0 -79
- metadata.gz.sig +0 -0
@@ -4,16 +4,6 @@ module Nokogiri
|
|
4
4
|
|
5
5
|
attr_accessor :cstruct # :nodoc:
|
6
6
|
|
7
|
-
def node_set # :nodoc:
|
8
|
-
ptr = cstruct[:nodesetval] if cstruct[:nodesetval]
|
9
|
-
ptr = LibXML.xmlXPathNodeSetCreate(nil) if ptr.null?
|
10
|
-
|
11
|
-
set = XML::NodeSet.new(@document)
|
12
|
-
set.cstruct = LibXML::XmlNodeSet.new(ptr)
|
13
|
-
set.document = @document
|
14
|
-
set
|
15
|
-
end
|
16
|
-
|
17
7
|
end
|
18
8
|
end
|
19
9
|
end
|
@@ -43,8 +43,24 @@ module Nokogiri
|
|
43
43
|
|
44
44
|
xpath = XML::XPath.new
|
45
45
|
xpath.cstruct = LibXML::XmlXpathObject.new(xpath_ptr)
|
46
|
-
xpath.document = cstruct
|
47
|
-
|
46
|
+
xpath.document = cstruct.document.ruby_doc
|
47
|
+
|
48
|
+
case xpath.cstruct[:type]
|
49
|
+
when LibXML::XmlXpathObject::XPATH_NODESET
|
50
|
+
if xpath.cstruct[:nodesetval].null?
|
51
|
+
NodeSet.new(xpath.document)
|
52
|
+
else
|
53
|
+
NodeSet.wrap(xpath.cstruct[:nodesetval], xpath.document)
|
54
|
+
end
|
55
|
+
when LibXML::XmlXpathObject::XPATH_STRING
|
56
|
+
xpath.cstruct[:stringval]
|
57
|
+
when LibXML::XmlXpathObject::XPATH_NUMBER
|
58
|
+
xpath.cstruct[:floatval]
|
59
|
+
when LibXML::XmlXpathObject::XPATH_BOOLEAN
|
60
|
+
0 != xpath.cstruct[:boolval]
|
61
|
+
else
|
62
|
+
NodeSet.new(xpath.document)
|
63
|
+
end
|
48
64
|
end
|
49
65
|
|
50
66
|
def self.new(node) # :nodoc:
|
@@ -66,8 +82,8 @@ module Nokogiri
|
|
66
82
|
def ruby_funcall(name, xpath_handler) # :nodoc:
|
67
83
|
lambda do |ctx, nargs|
|
68
84
|
parser_context = LibXML::XmlXpathParserContext.new(ctx)
|
69
|
-
|
70
|
-
|
85
|
+
context_cstruct = parser_context.context
|
86
|
+
document = context_cstruct.document.ruby_doc
|
71
87
|
|
72
88
|
params = []
|
73
89
|
|
@@ -81,10 +97,7 @@ module Nokogiri
|
|
81
97
|
when LibXML::XmlXpathObject::XPATH_NUMBER
|
82
98
|
params.unshift obj[:floatval]
|
83
99
|
when LibXML::XmlXpathObject::XPATH_NODESET
|
84
|
-
|
85
|
-
set = NodeSet.allocate
|
86
|
-
set.cstruct = ns_ptr
|
87
|
-
params.unshift set
|
100
|
+
params.unshift NodeSet.wrap(obj[:nodesetval], document)
|
88
101
|
else
|
89
102
|
char_ptr = params.unshift LibXML.xmlXPathCastToString(obj)
|
90
103
|
string = char_ptr.read_string
|
@@ -110,7 +123,7 @@ module Nokogiri
|
|
110
123
|
when NilClass.to_s
|
111
124
|
;
|
112
125
|
when Array.to_s
|
113
|
-
node_set = XML::NodeSet.new(
|
126
|
+
node_set = XML::NodeSet.new(document, result)
|
114
127
|
LibXML.xmlXPathReturnNodeSet(
|
115
128
|
ctx,
|
116
129
|
LibXML.xmlXPathNodeSetMerge(nil, node_set.cstruct)
|
@@ -30,6 +30,9 @@ module Nokogiri
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def transform(document, params=[]) # :nodoc:
|
33
|
+
params = params.to_a.flatten if params.is_a?(Hash)
|
34
|
+
raise(TypeError) unless params.is_a?(Array)
|
35
|
+
|
33
36
|
param_arr = FFI::MemoryPointer.new(:pointer, params.length + 1, false)
|
34
37
|
|
35
38
|
# Keep the MemoryPointer instances alive until after the call
|
@@ -9,7 +9,7 @@ module Nokogiri
|
|
9
9
|
node['http-equiv'] =~ /Content-Type/i
|
10
10
|
}
|
11
11
|
|
12
|
-
/charset\s*=\s*([\w
|
12
|
+
/charset\s*=\s*([\w-]+)/i.match(meta['content'])[1]
|
13
13
|
end
|
14
14
|
|
15
15
|
###
|
@@ -49,7 +49,7 @@ module Nokogiri
|
|
49
49
|
####
|
50
50
|
# Create a Nokogiri::XML::DocumentFragment from +tags+
|
51
51
|
def fragment tags = nil
|
52
|
-
DocumentFragment.new(self, tags)
|
52
|
+
DocumentFragment.new(self, tags, self.root)
|
53
53
|
end
|
54
54
|
|
55
55
|
class << self
|
@@ -68,7 +68,9 @@ module Nokogiri
|
|
68
68
|
yield options if block_given?
|
69
69
|
|
70
70
|
if string_or_io.respond_to?(:encoding)
|
71
|
-
|
71
|
+
unless string_or_io.encoding.name == "ASCII-8BIT"
|
72
|
+
encoding ||= string_or_io.encoding.name
|
73
|
+
end
|
72
74
|
end
|
73
75
|
|
74
76
|
if string_or_io.respond_to?(:read)
|
@@ -1,15 +1,36 @@
|
|
1
1
|
module Nokogiri
|
2
2
|
module HTML
|
3
3
|
class DocumentFragment < Nokogiri::XML::DocumentFragment
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
4
|
+
####
|
5
|
+
# Create a Nokogiri::XML::DocumentFragment from +tags+
|
6
|
+
def self.parse tags
|
7
|
+
doc = HTML::Document.new
|
8
|
+
doc.encoding = 'UTF-8'
|
9
|
+
self.new(doc, tags)
|
11
10
|
end
|
12
11
|
|
12
|
+
def initialize document, tags = nil, ctx = nil
|
13
|
+
return self unless tags
|
14
|
+
|
15
|
+
children = if ctx
|
16
|
+
ctx.parse("<div>#{tags.strip}</div>").first.children
|
17
|
+
else
|
18
|
+
###
|
19
|
+
# This is a horrible hack, but I don't care
|
20
|
+
if tags.strip =~ /^<body/i
|
21
|
+
path = "/html/body"
|
22
|
+
else
|
23
|
+
path = "/html/body/node()"
|
24
|
+
end
|
25
|
+
|
26
|
+
HTML::Document.parse(
|
27
|
+
"<html><body>#{tags.strip}</body></html>",
|
28
|
+
nil,
|
29
|
+
document.encoding
|
30
|
+
).xpath(path)
|
31
|
+
end
|
32
|
+
children.each { |child| child.parent = self }
|
33
|
+
end
|
13
34
|
end
|
14
35
|
end
|
15
36
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "nokogiri/#{RUBY_VERSION.sub(/\.\d+$/, '')}/nokogiri"
|
data/lib/nokogiri/version.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
module Nokogiri
|
2
2
|
# The version of Nokogiri you are using
|
3
|
-
VERSION = '1.4.
|
3
|
+
VERSION = '1.4.2'
|
4
4
|
|
5
5
|
# More complete version information about libxml
|
6
6
|
VERSION_INFO = {}
|
7
7
|
VERSION_INFO['warnings'] = []
|
8
|
-
VERSION_INFO['nokogiri'] = VERSION
|
8
|
+
VERSION_INFO['nokogiri'] = Nokogiri::VERSION
|
9
|
+
VERSION_INFO['ruby'] = {}
|
10
|
+
VERSION_INFO['ruby']['version'] = ::RUBY_VERSION
|
11
|
+
VERSION_INFO['ruby']['platform'] = ::RUBY_PLATFORM
|
12
|
+
VERSION_INFO['ruby']['jruby'] = ::JRUBY_VERSION if RUBY_PLATFORM == "java"
|
9
13
|
if defined?(LIBXML_VERSION)
|
10
14
|
VERSION_INFO['libxml'] = {}
|
11
15
|
VERSION_INFO['libxml']['binding'] = 'extension'
|
@@ -1,11 +1,14 @@
|
|
1
1
|
module Nokogiri
|
2
|
-
if self.is_2_6_16?
|
3
|
-
|
2
|
+
if self.is_2_6_16?
|
3
|
+
VERSION_INFO['warnings'] << "libxml 2.6.16 is old and buggy."
|
4
|
+
if !defined?(I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2)
|
5
|
+
warn <<-eom
|
4
6
|
HI. You're using libxml2 version 2.6.16 which is over 4 years old and has
|
5
7
|
plenty of bugs. We suggest that for maximum HTML/XML parsing pleasure, you
|
6
8
|
upgrade your version of libxml2 and re-install nokogiri. If you like using
|
7
9
|
libxml2 version 2.6.16, but don't like this warning, please define the constant
|
8
10
|
I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 before requring nokogiri.
|
9
|
-
|
11
|
+
eom
|
12
|
+
end
|
10
13
|
end
|
11
14
|
end
|
data/lib/nokogiri/xml.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'nokogiri/xml/pp'
|
2
2
|
require 'nokogiri/xml/parse_options'
|
3
3
|
require 'nokogiri/xml/sax'
|
4
|
-
require 'nokogiri/xml/fragment_handler'
|
5
4
|
require 'nokogiri/xml/node'
|
6
5
|
require 'nokogiri/xml/attribute_decl'
|
7
6
|
require 'nokogiri/xml/element_decl'
|
@@ -11,6 +10,7 @@ require 'nokogiri/xml/namespace'
|
|
11
10
|
require 'nokogiri/xml/attr'
|
12
11
|
require 'nokogiri/xml/dtd'
|
13
12
|
require 'nokogiri/xml/cdata'
|
13
|
+
require 'nokogiri/xml/text'
|
14
14
|
require 'nokogiri/xml/document'
|
15
15
|
require 'nokogiri/xml/document_fragment'
|
16
16
|
require 'nokogiri/xml/processing_instruction'
|
data/lib/nokogiri/xml/builder.rb
CHANGED
@@ -194,6 +194,36 @@ module Nokogiri
|
|
194
194
|
# </root>
|
195
195
|
#
|
196
196
|
# Note the "foo:object" tag.
|
197
|
+
#
|
198
|
+
# == Document Types
|
199
|
+
#
|
200
|
+
# To create a document type (DTD), access use the Builder#doc method to get
|
201
|
+
# the current context document. Then call Node#create_internal_subset to
|
202
|
+
# create the DTD node.
|
203
|
+
#
|
204
|
+
# For example, this Ruby:
|
205
|
+
#
|
206
|
+
# builder = Nokogiri::XML::Builder.new do |xml|
|
207
|
+
# xml.doc.create_internal_subset(
|
208
|
+
# 'html',
|
209
|
+
# "-//W3C//DTD HTML 4.01 Transitional//EN",
|
210
|
+
# "http://www.w3.org/TR/html4/loose.dtd"
|
211
|
+
# )
|
212
|
+
# xml.root do
|
213
|
+
# xml.foo
|
214
|
+
# end
|
215
|
+
# end
|
216
|
+
#
|
217
|
+
# puts builder.to_xml
|
218
|
+
#
|
219
|
+
# Will output this xml:
|
220
|
+
#
|
221
|
+
# <?xml version="1.0"?>
|
222
|
+
# <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
223
|
+
# <root>
|
224
|
+
# <foo/>
|
225
|
+
# </root>
|
226
|
+
#
|
197
227
|
class Builder
|
198
228
|
# The current Document object being built
|
199
229
|
attr_accessor :doc
|
@@ -275,8 +305,7 @@ module Nokogiri
|
|
275
305
|
###
|
276
306
|
# Create a CDATA Node with content of +string+
|
277
307
|
def cdata string
|
278
|
-
|
279
|
-
insert(node)
|
308
|
+
insert(doc.create_cdata(string))
|
280
309
|
end
|
281
310
|
|
282
311
|
###
|
@@ -311,29 +340,12 @@ module Nokogiri
|
|
311
340
|
if @context && @context.respond_to?(method)
|
312
341
|
@context.send(method, *args, &block)
|
313
342
|
else
|
314
|
-
node = @doc.create_element(method.to_s.sub(/[_!]$/, '')) { |n|
|
343
|
+
node = @doc.create_element(method.to_s.sub(/[_!]$/, ''),*args) { |n|
|
315
344
|
# Set up the namespace
|
316
345
|
if @ns
|
317
346
|
n.namespace = @ns
|
318
347
|
@ns = nil
|
319
348
|
end
|
320
|
-
|
321
|
-
args.each do |arg|
|
322
|
-
case arg
|
323
|
-
when Hash
|
324
|
-
arg.each { |k,v|
|
325
|
-
key = k.to_s
|
326
|
-
if key =~ /^xmlns(:\w+)?$/
|
327
|
-
ns_name = key.split(":", 2)[1]
|
328
|
-
n.add_namespace_definition ns_name, v
|
329
|
-
next
|
330
|
-
end
|
331
|
-
n[k.to_s] = v.to_s
|
332
|
-
}
|
333
|
-
else
|
334
|
-
n.content = arg
|
335
|
-
end
|
336
|
-
end
|
337
349
|
}
|
338
350
|
insert(node, &block)
|
339
351
|
end
|
@@ -345,14 +357,15 @@ module Nokogiri
|
|
345
357
|
def insert(node, &block)
|
346
358
|
node.parent = @parent
|
347
359
|
if block_given?
|
348
|
-
|
360
|
+
old_parent = @parent
|
361
|
+
@parent = node
|
349
362
|
@arity ||= block.arity
|
350
363
|
if @arity <= 0
|
351
364
|
instance_eval(&block)
|
352
365
|
else
|
353
366
|
block.call(self)
|
354
367
|
end
|
355
|
-
@parent =
|
368
|
+
@parent = old_parent
|
356
369
|
end
|
357
370
|
NodeBuilder.new(node, self)
|
358
371
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Nokogiri
|
2
2
|
module XML
|
3
|
-
|
3
|
+
##
|
4
4
|
# Nokogiri::XML::Document is the main entry point for dealing with
|
5
5
|
# XML documents. The Document is created by parsing an XML document.
|
6
6
|
# See Nokogiri.XML()
|
@@ -8,7 +8,7 @@ module Nokogiri
|
|
8
8
|
# For searching a Document, see Nokogiri::XML::Node#css and
|
9
9
|
# Nokogiri::XML::Node#xpath
|
10
10
|
class Document < Node
|
11
|
-
|
11
|
+
##
|
12
12
|
# Parse an XML file. +thing+ may be a String, or any object that
|
13
13
|
# responds to _read_ and _close_ such as an IO, or StringIO.
|
14
14
|
# +url+ is resource where this document is located. +encoding+ is the
|
@@ -36,13 +36,39 @@ module Nokogiri
|
|
36
36
|
# A list of Nokogiri::XML::SyntaxError found when parsing a document
|
37
37
|
attr_accessor :errors
|
38
38
|
|
39
|
-
def initialize *args
|
39
|
+
def initialize *args # :nodoc:
|
40
|
+
@errors = []
|
40
41
|
@decorators = nil
|
41
42
|
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
##
|
45
|
+
# Create an element with +name+, and optionally setting the content and attributes.
|
46
|
+
#
|
47
|
+
# doc.create_element "div" # <div></div>
|
48
|
+
# doc.create_element "div", :class => "container" # <div class='container'></div>
|
49
|
+
# doc.create_element "div", "contents" # <div>contents</div>
|
50
|
+
# doc.create_element "div", "contents", :class => "container" # <div class='container'>contents</div>
|
51
|
+
# doc.create_element "div" { |node| node['class'] = "container" } # <div class='container'></div>
|
52
|
+
#
|
53
|
+
def create_element name, *args, &block
|
54
|
+
elm = Nokogiri::XML::Element.new(name, self, &block)
|
55
|
+
args.each do |arg|
|
56
|
+
case arg
|
57
|
+
when Hash
|
58
|
+
arg.each { |k,v|
|
59
|
+
key = k.to_s
|
60
|
+
if key =~ /^xmlns(:\w+)?$/
|
61
|
+
ns_name = key.split(":", 2)[1]
|
62
|
+
elm.add_namespace_definition ns_name, v
|
63
|
+
next
|
64
|
+
end
|
65
|
+
elm[k.to_s] = v.to_s
|
66
|
+
}
|
67
|
+
else
|
68
|
+
elm.content = arg
|
69
|
+
end
|
70
|
+
end
|
71
|
+
elm
|
46
72
|
end
|
47
73
|
|
48
74
|
# Create a text node with +text+
|
@@ -50,6 +76,11 @@ module Nokogiri
|
|
50
76
|
Nokogiri::XML::Text.new(text.to_s, self, &block)
|
51
77
|
end
|
52
78
|
|
79
|
+
# Create a CDATA element containing +text+
|
80
|
+
def create_cdata text
|
81
|
+
Nokogiri::XML::CDATA.new(self, text.to_s)
|
82
|
+
end
|
83
|
+
|
53
84
|
# The name of this document. Always returns "document"
|
54
85
|
def name
|
55
86
|
'document'
|
@@ -60,7 +91,7 @@ module Nokogiri
|
|
60
91
|
self
|
61
92
|
end
|
62
93
|
|
63
|
-
|
94
|
+
##
|
64
95
|
# Recursively get all namespaces from this node and its subtree and
|
65
96
|
# return them as a hash.
|
66
97
|
#
|
@@ -94,7 +125,7 @@ module Nokogiri
|
|
94
125
|
@decorators[key] ||= []
|
95
126
|
end
|
96
127
|
|
97
|
-
|
128
|
+
##
|
98
129
|
# Validate this Document against it's DTD. Returns a list of errors on
|
99
130
|
# the document or +nil+ when there is no DTD.
|
100
131
|
def validate
|
@@ -102,7 +133,7 @@ module Nokogiri
|
|
102
133
|
internal_subset.validate self
|
103
134
|
end
|
104
135
|
|
105
|
-
|
136
|
+
##
|
106
137
|
# Explore a document with shortcut methods.
|
107
138
|
def slop!
|
108
139
|
unless decorators(XML::Node).include? Nokogiri::Decorators::Slop
|
@@ -113,7 +144,7 @@ module Nokogiri
|
|
113
144
|
self
|
114
145
|
end
|
115
146
|
|
116
|
-
|
147
|
+
##
|
117
148
|
# Apply any decorators to +node+
|
118
149
|
def decorate node
|
119
150
|
return unless @decorators
|
@@ -131,16 +162,17 @@ module Nokogiri
|
|
131
162
|
root ? root.namespaces : {}
|
132
163
|
end
|
133
164
|
|
134
|
-
|
165
|
+
##
|
135
166
|
# Create a Nokogiri::XML::DocumentFragment from +tags+
|
136
167
|
# Returns an empty fragment if +tags+ is nil.
|
137
168
|
def fragment tags = nil
|
138
|
-
DocumentFragment.new(self, tags)
|
169
|
+
DocumentFragment.new(self, tags, self.root)
|
139
170
|
end
|
140
171
|
|
141
172
|
undef_method :swap, :parent, :namespace, :default_namespace=
|
142
173
|
undef_method :add_namespace_definition, :attributes
|
143
174
|
undef_method :namespace_definitions, :line, :add_namespace
|
175
|
+
undef_method :parse, :in_context
|
144
176
|
|
145
177
|
def add_child child
|
146
178
|
raise "Document already has a root node" if root
|
@@ -1,18 +1,22 @@
|
|
1
1
|
module Nokogiri
|
2
2
|
module XML
|
3
3
|
class DocumentFragment < Nokogiri::XML::Node
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
+
ctx.parse(tags.strip)
|
15
|
+
else
|
16
|
+
XML::Document.parse("<root>#{tags.strip}</root>") \
|
17
|
+
.xpath("/root/node()")
|
18
|
+
end
|
19
|
+
children.each { |child| child.parent = self }
|
16
20
|
end
|
17
21
|
|
18
22
|
###
|