nokogiri 1.2.3 → 1.3.0
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/.autotest +14 -2
- data/CHANGELOG.ja.rdoc +38 -0
- data/CHANGELOG.rdoc +43 -0
- data/Manifest.txt +80 -5
- data/README.ja.rdoc +12 -11
- data/README.rdoc +4 -2
- data/Rakefile +103 -173
- data/bin/nokogiri +47 -0
- data/ext/nokogiri/extconf.rb +19 -13
- data/ext/nokogiri/html_document.c +39 -3
- data/ext/nokogiri/html_document.h +1 -1
- data/ext/nokogiri/html_element_description.c +272 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.h +1 -1
- data/ext/nokogiri/html_sax_parser.h +1 -1
- data/ext/nokogiri/{native.c → nokogiri.c} +11 -3
- data/ext/nokogiri/{native.h → nokogiri.h} +18 -4
- data/ext/nokogiri/xml_attr.c +14 -5
- data/ext/nokogiri/xml_attr.h +1 -1
- data/ext/nokogiri/xml_cdata.c +15 -6
- data/ext/nokogiri/xml_cdata.h +1 -1
- data/ext/nokogiri/xml_comment.c +13 -4
- data/ext/nokogiri/xml_comment.h +1 -1
- data/ext/nokogiri/xml_document.c +50 -41
- data/ext/nokogiri/xml_document.h +1 -1
- data/ext/nokogiri/xml_document_fragment.c +12 -4
- data/ext/nokogiri/xml_document_fragment.h +1 -1
- data/ext/nokogiri/xml_dtd.c +1 -1
- data/ext/nokogiri/xml_dtd.h +1 -1
- data/ext/nokogiri/xml_entity_reference.c +13 -4
- data/ext/nokogiri/xml_entity_reference.h +1 -1
- data/ext/nokogiri/xml_io.h +1 -1
- data/ext/nokogiri/xml_namespace.c +69 -0
- data/ext/nokogiri/xml_namespace.h +12 -0
- data/ext/nokogiri/xml_node.c +232 -124
- data/ext/nokogiri/xml_node.h +3 -4
- data/ext/nokogiri/xml_node_set.c +206 -19
- data/ext/nokogiri/xml_node_set.h +1 -1
- data/ext/nokogiri/xml_processing_instruction.c +14 -4
- data/ext/nokogiri/xml_processing_instruction.h +1 -1
- data/ext/nokogiri/xml_reader.c +87 -7
- data/ext/nokogiri/xml_reader.h +1 -1
- data/ext/nokogiri/xml_relax_ng.c +106 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +122 -2
- data/ext/nokogiri/xml_sax_parser.h +1 -1
- data/ext/nokogiri/xml_sax_push_parser.c +1 -0
- data/ext/nokogiri/xml_sax_push_parser.h +1 -1
- data/ext/nokogiri/xml_schema.c +107 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.h +1 -1
- data/ext/nokogiri/xml_text.c +10 -3
- data/ext/nokogiri/xml_text.h +1 -1
- data/ext/nokogiri/xml_xpath.h +1 -1
- data/ext/nokogiri/xml_xpath_context.h +1 -1
- data/ext/nokogiri/xslt_stylesheet.c +29 -16
- data/ext/nokogiri/xslt_stylesheet.h +1 -1
- data/lib/action-nokogiri.rb +7 -1
- data/lib/nokogiri.rb +21 -5
- data/lib/nokogiri/css/generated_parser.rb +49 -14
- data/lib/nokogiri/css/generated_tokenizer.rb +2 -2
- data/lib/nokogiri/css/node.rb +13 -3
- data/lib/nokogiri/css/parser.rb +8 -0
- data/lib/nokogiri/css/parser.y +7 -7
- data/lib/nokogiri/css/tokenizer.rb +2 -0
- data/lib/nokogiri/css/xpath_visitor.rb +10 -6
- data/lib/nokogiri/decorators/hpricot/node.rb +1 -1
- data/lib/nokogiri/decorators/hpricot/node_set.rb +2 -2
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +2 -0
- data/lib/nokogiri/decorators/slop.rb +3 -1
- data/lib/nokogiri/ffi/html/document.rb +37 -0
- data/lib/nokogiri/ffi/html/element_description.rb +85 -0
- data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
- data/lib/nokogiri/ffi/html/sax/parser.rb +21 -0
- data/lib/nokogiri/ffi/io_callbacks.rb +32 -0
- data/lib/nokogiri/ffi/libxml.rb +314 -0
- data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
- data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
- data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +26 -0
- data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
- data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
- data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
- data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
- data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
- data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
- data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
- data/lib/nokogiri/ffi/xml/attr.rb +41 -0
- data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
- data/lib/nokogiri/ffi/xml/comment.rb +18 -0
- data/lib/nokogiri/ffi/xml/document.rb +107 -0
- data/lib/nokogiri/ffi/xml/document_fragment.rb +26 -0
- data/lib/nokogiri/ffi/xml/dtd.rb +42 -0
- data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/ffi/xml/namespace.rb +38 -0
- data/lib/nokogiri/ffi/xml/node.rb +380 -0
- data/lib/nokogiri/ffi/xml/node_set.rb +130 -0
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
- data/lib/nokogiri/ffi/xml/reader.rb +217 -0
- data/lib/nokogiri/ffi/xml/relax_ng.rb +51 -0
- data/lib/nokogiri/ffi/xml/sax/parser.rb +148 -0
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +38 -0
- data/lib/nokogiri/ffi/xml/schema.rb +55 -0
- data/lib/nokogiri/ffi/xml/syntax_error.rb +76 -0
- data/lib/nokogiri/ffi/xml/text.rb +18 -0
- data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
- data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +47 -0
- data/lib/nokogiri/hpricot.rb +14 -3
- data/lib/nokogiri/html.rb +11 -46
- data/lib/nokogiri/html/builder.rb +27 -1
- data/lib/nokogiri/html/document.rb +62 -6
- data/lib/nokogiri/html/document_fragment.rb +15 -0
- data/lib/nokogiri/html/element_description.rb +23 -0
- data/lib/nokogiri/html/entity_lookup.rb +2 -0
- data/lib/nokogiri/html/sax/parser.rb +27 -1
- data/lib/nokogiri/version.rb +26 -1
- data/lib/nokogiri/version_warning.rb +11 -0
- data/lib/nokogiri/xml.rb +25 -51
- data/lib/nokogiri/xml/builder.rb +166 -10
- data/lib/nokogiri/xml/cdata.rb +3 -1
- data/lib/nokogiri/xml/document.rb +39 -6
- data/lib/nokogiri/xml/document_fragment.rb +41 -1
- data/lib/nokogiri/xml/dtd.rb +3 -1
- data/lib/nokogiri/xml/entity_declaration.rb +3 -1
- data/lib/nokogiri/xml/fragment_handler.rb +24 -3
- data/lib/nokogiri/xml/namespace.rb +7 -0
- data/lib/nokogiri/xml/node.rb +314 -65
- data/lib/nokogiri/xml/node/save_options.rb +12 -2
- data/lib/nokogiri/xml/node_set.rb +58 -8
- data/lib/nokogiri/xml/parse_options.rb +80 -0
- data/lib/nokogiri/xml/processing_instruction.rb +2 -0
- data/lib/nokogiri/xml/reader.rb +42 -3
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +0 -7
- data/lib/nokogiri/xml/sax/document.rb +84 -0
- data/lib/nokogiri/xml/sax/parser.rb +38 -2
- data/lib/nokogiri/xml/sax/push_parser.rb +12 -0
- data/lib/nokogiri/xml/schema.rb +65 -0
- data/lib/nokogiri/xml/syntax_error.rb +11 -0
- data/lib/nokogiri/xml/xpath.rb +1 -1
- data/lib/nokogiri/xml/xpath_context.rb +2 -0
- data/lib/nokogiri/xslt.rb +21 -1
- data/lib/nokogiri/xslt/stylesheet.rb +19 -0
- data/lib/xsd/xmlparser/nokogiri.rb +12 -2
- data/tasks/test.rb +42 -19
- data/test/css/test_parser.rb +29 -0
- data/test/ffi/test_document.rb +35 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/helper.rb +38 -8
- data/test/html/sax/test_parser.rb +12 -0
- data/test/html/test_builder.rb +25 -2
- data/test/html/test_document.rb +91 -20
- data/test/html/test_document_fragment.rb +97 -0
- data/test/html/test_element_description.rb +95 -0
- data/test/html/test_node.rb +66 -3
- data/test/test_convert_xpath.rb +1 -1
- data/test/test_memory_leak.rb +57 -18
- data/test/test_nokogiri.rb +24 -2
- data/test/test_reader.rb +77 -0
- data/test/test_xslt_transforms.rb +120 -82
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +9 -0
- data/test/xml/sax/test_push_parser.rb +24 -0
- data/test/xml/test_attr.rb +7 -0
- data/test/xml/test_builder.rb +48 -0
- data/test/xml/test_cdata.rb +19 -0
- data/test/xml/test_comment.rb +6 -0
- data/test/xml/test_document.rb +101 -2
- data/test/xml/test_document_fragment.rb +55 -3
- data/test/xml/test_entity_reference.rb +4 -0
- data/test/xml/test_namespace.rb +43 -0
- data/test/xml/test_node.rb +255 -8
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +9 -2
- data/test/xml/test_node_set.rb +197 -1
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +5 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +65 -0
- data/test/xml/test_text.rb +5 -0
- data/test/xml/test_unparented_node.rb +3 -3
- metadata +128 -12
- data/lib/nokogiri/xml/comment.rb +0 -6
- data/lib/nokogiri/xml/element.rb +0 -6
- data/lib/nokogiri/xml/text.rb +0 -6
@@ -1,6 +1,6 @@
|
|
1
1
|
module Nokogiri
|
2
2
|
module CSS
|
3
|
-
class XPathVisitor
|
3
|
+
class XPathVisitor # :nodoc:
|
4
4
|
def visit_function node
|
5
5
|
# note that nth-child and nth-last-child are preprocessed in css/node.rb.
|
6
6
|
msg = :"visit_function_#{node.value.first.gsub(/[(]/, '')}"
|
@@ -76,15 +76,19 @@ module Nokogiri
|
|
76
76
|
value = "'#{value}'" if value !~ /^['"]/
|
77
77
|
|
78
78
|
case node.value[1]
|
79
|
-
when
|
79
|
+
when :equal
|
80
|
+
attribute + " = " + "#{value}"
|
81
|
+
when :not_equal
|
82
|
+
attribute + " != " + "#{value}"
|
83
|
+
when :substring_match
|
80
84
|
"contains(#{attribute}, #{value})"
|
81
|
-
when
|
85
|
+
when :prefix_match
|
82
86
|
"starts-with(#{attribute}, #{value})"
|
83
|
-
when
|
87
|
+
when :dash_match
|
84
88
|
"#{attribute} = #{value} or starts-with(#{attribute}, concat(#{value}, '-'))"
|
85
|
-
when
|
89
|
+
when :includes
|
86
90
|
"contains(concat(\" \", #{attribute}, \" \"),concat(\" \", #{value}, \" \"))"
|
87
|
-
when
|
91
|
+
when :suffix_match
|
88
92
|
"substring(#{attribute}, string-length(#{attribute}) - " +
|
89
93
|
"string-length(#{value}) + 1, string-length(#{value})) = #{value}"
|
90
94
|
else
|
@@ -6,7 +6,7 @@ module Nokogiri
|
|
6
6
|
# Select nodes matching the supplied rule.
|
7
7
|
# Note that positional rules (like <tt>:nth()</tt>) aren't currently supported.
|
8
8
|
#
|
9
|
-
# example:
|
9
|
+
# example:
|
10
10
|
# node_set.filter('.ohmy') # selects nodes from the set with class "ohmy"
|
11
11
|
# node_set.filter('a#link2') # selects nodes from the set with child node <a id='link2'>
|
12
12
|
# node_set.filter('a[@id="link2"]') # selects nodes from the set with child node <a id='link2'>
|
@@ -29,7 +29,7 @@ module Nokogiri
|
|
29
29
|
end
|
30
30
|
|
31
31
|
private
|
32
|
-
def filter_transformer(transformer, rule)
|
32
|
+
def filter_transformer(transformer, rule) # :nodoc:
|
33
33
|
sub_set = XML::NodeSet.new(document)
|
34
34
|
document.decorate(sub_set)
|
35
35
|
|
@@ -4,6 +4,8 @@ module Nokogiri
|
|
4
4
|
####
|
5
5
|
# This mixin does custom adjustments to deal with _whyML
|
6
6
|
module XPathVisitor
|
7
|
+
###
|
8
|
+
# Visit attribute condition nodes with +node+
|
7
9
|
def visit_attribute_condition node
|
8
10
|
unless (node.value.first.type == :FUNCTION) or (node.value.first.value.first =~ /^@/)
|
9
11
|
node.value.first.value[0] = "child::" +
|
@@ -4,6 +4,8 @@ module Nokogiri
|
|
4
4
|
# The Slop decorator implements method missing such that a methods may be
|
5
5
|
# used instead of XPath or CSS. See Nokogiri.Slop
|
6
6
|
module Slop
|
7
|
+
###
|
8
|
+
# look for node with +name+. See Nokogiri.Slop
|
7
9
|
def method_missing name, *args, &block
|
8
10
|
if args.empty?
|
9
11
|
list = xpath("./#{name}")
|
@@ -22,7 +24,7 @@ module Nokogiri
|
|
22
24
|
)
|
23
25
|
end
|
24
26
|
end
|
25
|
-
|
27
|
+
|
26
28
|
super if list.empty?
|
27
29
|
list.length == 1 ? list.first : list
|
28
30
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module HTML
|
3
|
+
class Document < XML::Document
|
4
|
+
|
5
|
+
attr_accessor :cstruct # :nodoc:
|
6
|
+
|
7
|
+
def self.new(*args) # :nodoc:
|
8
|
+
uri = args[0]
|
9
|
+
external_id = args[1]
|
10
|
+
doc = wrap(LibXML.htmlNewDoc(uri, external_id))
|
11
|
+
doc.send :initialize, *args
|
12
|
+
doc
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.read_io(io, url, encoding, options) # :nodoc:
|
16
|
+
wrap_with_error_handling do
|
17
|
+
LibXML.htmlReadIO(IoCallbacks.reader(io), nil, nil, url, encoding, options)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.read_memory(string, url, encoding, options) # :nodoc:
|
22
|
+
wrap_with_error_handling do
|
23
|
+
LibXML.htmlReadMemory(string, string.length, url, encoding, options)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def meta_encoding=(encoding) # :nodoc:
|
28
|
+
LibXML.htmlSetMetaEncoding(cstruct, encoding)
|
29
|
+
encoding
|
30
|
+
end
|
31
|
+
|
32
|
+
def meta_encoding # :nodoc:
|
33
|
+
LibXML.htmlGetMetaEncoding(cstruct)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module HTML
|
3
|
+
class ElementDescription
|
4
|
+
|
5
|
+
attr_accessor :cstruct # :nodoc:
|
6
|
+
|
7
|
+
def required_attributes # :nodoc:
|
8
|
+
get_string_array_from :attrs_req
|
9
|
+
end
|
10
|
+
|
11
|
+
def deprecated_attributes # :nodoc:
|
12
|
+
get_string_array_from :attrs_depr
|
13
|
+
end
|
14
|
+
|
15
|
+
def optional_attributes # :nodoc:
|
16
|
+
get_string_array_from :attrs_opt
|
17
|
+
end
|
18
|
+
|
19
|
+
def default_sub_element # :nodoc:
|
20
|
+
cstruct[:defaultsubelt]
|
21
|
+
end
|
22
|
+
|
23
|
+
def sub_elements # :nodoc:
|
24
|
+
get_string_array_from :subelts
|
25
|
+
end
|
26
|
+
|
27
|
+
def description # :nodoc:
|
28
|
+
cstruct[:desc]
|
29
|
+
end
|
30
|
+
|
31
|
+
def inline? # :nodoc:
|
32
|
+
cstruct[:isinline] != 0
|
33
|
+
end
|
34
|
+
|
35
|
+
def deprecated? # :nodoc:
|
36
|
+
cstruct[:depr] != 0
|
37
|
+
end
|
38
|
+
|
39
|
+
def empty? # :nodoc:
|
40
|
+
cstruct[:empty] != 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def save_end_tag? # :nodoc:
|
44
|
+
cstruct[:saveEndTag] != 0
|
45
|
+
end
|
46
|
+
|
47
|
+
def implied_end_tag? # :nodoc:
|
48
|
+
cstruct[:endTag] != 0
|
49
|
+
end
|
50
|
+
|
51
|
+
def implied_start_tag? # :nodoc:
|
52
|
+
cstruct[:startTag] != 0
|
53
|
+
end
|
54
|
+
|
55
|
+
def name # :nodoc:
|
56
|
+
cstruct[:name]
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.[](tag_name) # :nodoc:
|
60
|
+
ptr = LibXML.htmlTagLookup(tag_name)
|
61
|
+
return nil if ptr.null?
|
62
|
+
|
63
|
+
desc = allocate
|
64
|
+
desc.cstruct = LibXML::HtmlElemDesc.new(ptr)
|
65
|
+
desc
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def get_string_array_from(sym) # :nodoc:
|
71
|
+
list = []
|
72
|
+
return list if cstruct[sym].null?
|
73
|
+
|
74
|
+
j = 0
|
75
|
+
while (ptr = cstruct[sym].get_pointer(j * FFI.type_size(:pointer))) && ! ptr.null?
|
76
|
+
list << ptr.read_string
|
77
|
+
j += 1
|
78
|
+
end
|
79
|
+
|
80
|
+
list
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module HTML
|
3
|
+
class EntityLookup
|
4
|
+
|
5
|
+
def get(key) # :nodoc:
|
6
|
+
ptr = LibXML.htmlEntityLookup(key.to_s)
|
7
|
+
return nil if ptr.null?
|
8
|
+
|
9
|
+
cstruct = LibXML::HtmlEntityDesc.new(ptr)
|
10
|
+
EntityDescription.new cstruct[:value], cstruct[:name], cstruct[:desc]
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module HTML
|
3
|
+
module SAX
|
4
|
+
class Parser < XML::SAX::Parser
|
5
|
+
|
6
|
+
def native_parse_file(data, encoding) # :nodoc:
|
7
|
+
docptr = LibXML.htmlSAXParseFile(data, encoding, cstruct, nil)
|
8
|
+
LibXML.xmlFreeDoc docptr
|
9
|
+
data
|
10
|
+
end
|
11
|
+
|
12
|
+
def native_parse_memory(data, encoding) # :nodoc:
|
13
|
+
docptr = LibXML.htmlSAXParseDoc(data, encoding, cstruct, nil)
|
14
|
+
LibXML.xmlFreeDoc docptr
|
15
|
+
data
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module IoCallbacks # :nodoc:
|
3
|
+
|
4
|
+
class << self
|
5
|
+
if defined?(FFI::IO.native_read)
|
6
|
+
def reader(io)
|
7
|
+
lambda do |ctx, buffer, len|
|
8
|
+
rcode = FFI::IO.native_read(io, buffer, len)
|
9
|
+
(rcode < 0) ? 0 : rcode
|
10
|
+
end
|
11
|
+
end
|
12
|
+
else
|
13
|
+
def reader(io) # TODO: this can be removed once JRuby 1.3.0RC2 and ruby-ffi 0.4.0 are both released
|
14
|
+
lambda do |ctx, buffer, len|
|
15
|
+
string = io.read(len)
|
16
|
+
return 0 if string.nil?
|
17
|
+
buffer.put_bytes(0, string, 0, string.length)
|
18
|
+
string.length
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def writer(io)
|
24
|
+
lambda do |context, buffer, len|
|
25
|
+
io.write buffer
|
26
|
+
len
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,314 @@
|
|
1
|
+
|
2
|
+
module Nokogiri
|
3
|
+
module LibXML # :nodoc: all
|
4
|
+
extend FFI::Library
|
5
|
+
ffi_lib 'xml2', 'xslt', 'exslt'
|
6
|
+
|
7
|
+
# globals.c
|
8
|
+
attach_function :__xmlParserVersion, [], :pointer
|
9
|
+
attach_function :__xmlIndentTreeOutput, [], :pointer
|
10
|
+
attach_function :__xmlTreeIndentString, [], :pointer
|
11
|
+
attach_function :xmlDeregisterNodeDefault, [:pointer], :pointer
|
12
|
+
end
|
13
|
+
|
14
|
+
LIBXML_PARSER_VERSION = LibXML.__xmlParserVersion().read_pointer.read_string
|
15
|
+
LIBXML_VERSION = LIBXML_PARSER_VERSION.scan(/^(.*)(..)(..)$/).first.collect{|j|j.to_i}.join(".")
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'nokogiri/version'
|
19
|
+
|
20
|
+
Nokogiri::VERSION_INFO['libxml'] = {}
|
21
|
+
Nokogiri::VERSION_INFO['libxml']['loaded'] = Nokogiri::LIBXML_VERSION
|
22
|
+
Nokogiri::VERSION_INFO['libxml']['binding'] = 'ffi'
|
23
|
+
if RUBY_PLATFORM =~ /java/
|
24
|
+
Nokogiri::VERSION_INFO['libxml']['platform'] = 'jruby'
|
25
|
+
raise(RuntimeError, "Nokogiri requires JRuby 1.3.0 or later") if JRUBY_VERSION < "1.3.0"
|
26
|
+
else
|
27
|
+
Nokogiri::VERSION_INFO['libxml']['platform'] = 'ruby'
|
28
|
+
end
|
29
|
+
|
30
|
+
module Nokogiri
|
31
|
+
module LibXML # :nodoc:
|
32
|
+
# useful callback signatures
|
33
|
+
callback :syntax_error_handler, [:pointer, :pointer], :void
|
34
|
+
callback :generic_error_handler, [:pointer, :string], :void
|
35
|
+
callback :io_write_callback, [:pointer, :string, :int], :int
|
36
|
+
callback :io_read_callback, [:pointer, :pointer, :int], :int
|
37
|
+
callback :io_close_callback, [:pointer], :int
|
38
|
+
callback :hash_copier_callback, [:pointer, :pointer, :string], :void
|
39
|
+
callback :xpath_callback, [:pointer, :int], :void
|
40
|
+
callback :xpath_lookup_callback, [:pointer, :string, :pointer], :xpath_callback
|
41
|
+
callback :start_document_sax_func, [:pointer], :void
|
42
|
+
callback :end_document_sax_func, [:pointer], :void
|
43
|
+
callback :start_element_sax_func, [:pointer, :string, :pointer], :void
|
44
|
+
callback :end_element_sax_func, [:pointer, :string], :void
|
45
|
+
callback :characters_sax_func, [:pointer, :string, :int], :void
|
46
|
+
callback :comment_sax_func, [:pointer, :string], :void
|
47
|
+
callback :warning_sax_func, [:pointer, :string], :void
|
48
|
+
callback :error_sax_func, [:pointer, :string], :void
|
49
|
+
callback :cdata_block_sax_func, [:pointer, :string, :int], :void
|
50
|
+
callback :start_element_ns_sax2_func, [:pointer, :pointer, :pointer, :pointer, :int, :pointer, :int, :int, :pointer], :void
|
51
|
+
callback :end_element_ns_sax2_func, [:pointer, :pointer, :pointer, :pointer], :void
|
52
|
+
|
53
|
+
# libc
|
54
|
+
attach_function :calloc, [:int, :int], :pointer
|
55
|
+
attach_function :free, [:pointer], :void
|
56
|
+
|
57
|
+
# HTMLparser.c
|
58
|
+
attach_function :htmlReadMemory, [:string, :int, :string, :string, :int], :pointer
|
59
|
+
attach_function :htmlReadIO, [:io_read_callback, :io_close_callback, :pointer, :string, :string, :int], :pointer
|
60
|
+
attach_function :htmlNewDoc, [:string, :string], :pointer
|
61
|
+
attach_function :htmlTagLookup, [:string], :pointer
|
62
|
+
attach_function :htmlEntityLookup, [:string], :pointer
|
63
|
+
attach_function :htmlSAXParseFile, [:string, :pointer, :pointer, :pointer], :pointer # second arg 'encoding' should be a string, but we assign it as a pointer elsewhere
|
64
|
+
attach_function :htmlSAXParseDoc, [:pointer, :pointer, :pointer, :pointer], :pointer # second arg 'encoding' should be a string, but we assign it as a pointer elsewhere
|
65
|
+
|
66
|
+
# HTMLtree.c
|
67
|
+
attach_function :htmlDocDumpMemory, [:pointer, :pointer, :pointer], :void
|
68
|
+
attach_function :htmlNodeDump, [:pointer, :pointer, :pointer], :int
|
69
|
+
attach_function :htmlGetMetaEncoding, [:pointer], :string # returns const char*
|
70
|
+
attach_function :htmlSetMetaEncoding, [:pointer, :string], :void
|
71
|
+
|
72
|
+
# parser.c
|
73
|
+
attach_function :xmlReadMemory, [:string, :int, :string, :string, :int], :pointer
|
74
|
+
attach_function :xmlInitParser, [], :void
|
75
|
+
attach_function :xmlReadIO, [:io_read_callback, :io_close_callback, :pointer, :string, :string, :int], :pointer
|
76
|
+
attach_function :xmlCreateIOParserCtxt, [:pointer, :pointer, :io_read_callback, :io_close_callback, :pointer, :int], :pointer
|
77
|
+
attach_function :xmlSAXUserParseMemory, [:pointer, :pointer, :string, :int], :int
|
78
|
+
attach_function :xmlSAXUserParseFile, [:pointer, :pointer, :string], :int
|
79
|
+
attach_function :xmlParseDocument, [:pointer], :int
|
80
|
+
attach_function :xmlFreeParserCtxt, [:pointer], :void
|
81
|
+
attach_function :xmlCreatePushParserCtxt, [:pointer, :pointer, :string, :int, :string], :pointer
|
82
|
+
attach_function :xmlParseChunk, [:pointer, :string, :int, :int], :int
|
83
|
+
|
84
|
+
# tree.c
|
85
|
+
attach_function :xmlNewDoc, [:string], :pointer
|
86
|
+
attach_function :xmlNewDocFragment, [:pointer], :pointer
|
87
|
+
attach_function :xmlDocGetRootElement, [:pointer], :pointer
|
88
|
+
attach_function :xmlDocSetRootElement, [:pointer, :pointer], :pointer
|
89
|
+
attach_function :xmlCopyDoc, [:pointer, :int], :pointer
|
90
|
+
attach_function :xmlFreeDoc, [:pointer], :void
|
91
|
+
attach_function :xmlSetTreeDoc, [:pointer, :pointer], :void
|
92
|
+
attach_function :xmlNewReference, [:pointer, :string], :pointer
|
93
|
+
attach_function :xmlNewNode, [:pointer, :string], :pointer
|
94
|
+
attach_function :xmlCopyNode, [:pointer, :int], :pointer
|
95
|
+
attach_function :xmlDocCopyNode, [:pointer, :pointer, :int], :pointer
|
96
|
+
attach_function :xmlReplaceNode, [:pointer, :pointer], :pointer
|
97
|
+
attach_function :xmlUnlinkNode, [:pointer], :void
|
98
|
+
attach_function :xmlAddChild, [:pointer, :pointer], :pointer
|
99
|
+
attach_function :xmlAddNextSibling, [:pointer, :pointer], :pointer
|
100
|
+
attach_function :xmlAddPrevSibling, [:pointer, :pointer], :pointer
|
101
|
+
attach_function :xmlIsBlankNode, [:pointer], :int
|
102
|
+
attach_function :xmlHasProp, [:pointer, :string], :pointer
|
103
|
+
attach_function :xmlHasNsProp, [:pointer, :string, :string], :pointer
|
104
|
+
attach_function :xmlGetProp, [:pointer, :string], :pointer # returns char* that must be freed
|
105
|
+
attach_function :xmlSetProp, [:pointer, :string, :string], :pointer
|
106
|
+
attach_function :xmlRemoveProp, [:pointer], :int
|
107
|
+
attach_function :xmlNodeSetContent, [:pointer, :string], :void
|
108
|
+
attach_function :xmlNodeGetContent, [:pointer], :pointer # returns char* that must be freed
|
109
|
+
attach_function :xmlNodeSetName, [:pointer, :string], :void
|
110
|
+
attach_function :xmlGetNodePath, [:pointer], :pointer
|
111
|
+
attach_function :xmlNewCDataBlock, [:pointer, :string, :int], :pointer
|
112
|
+
attach_function :xmlNewDocComment, [:pointer, :string], :pointer
|
113
|
+
attach_function :xmlNewDocPI, [:pointer, :string, :string], :pointer
|
114
|
+
attach_function :xmlNewText, [:string], :pointer
|
115
|
+
attach_function :xmlFreeNode, [:pointer], :void
|
116
|
+
attach_function :xmlFreeNodeList, [:pointer], :void
|
117
|
+
attach_function :xmlEncodeEntitiesReentrant, [:pointer, :string], :pointer # returns char* that must be freed
|
118
|
+
attach_function :xmlStringGetNodeList, [:pointer, :pointer], :pointer # second arg should be a :string, but we only ship the results of xmlEncodeEntitiesReentrant, so let's optimize.
|
119
|
+
attach_function :xmlNewNs, [:pointer, :string, :string], :pointer
|
120
|
+
attach_function :xmlNewNsProp, [:pointer, :pointer, :string, :string], :pointer
|
121
|
+
attach_function :xmlSearchNsByHref, [:pointer, :pointer, :string], :pointer
|
122
|
+
attach_function :xmlGetIntSubset, [:pointer], :pointer
|
123
|
+
attach_function :xmlBufferCreate, [], :pointer
|
124
|
+
attach_function :xmlBufferFree, [:pointer], :void
|
125
|
+
attach_function :xmlSplitQName2, [:string, :pointer], :pointer # returns char* that must be freed
|
126
|
+
attach_function :xmlNewDocProp, [:pointer, :string, :string], :pointer
|
127
|
+
attach_function :xmlFreePropList, [:pointer], :void
|
128
|
+
|
129
|
+
# xmlsave.c
|
130
|
+
attach_function :xmlDocDumpMemory, [:pointer, :pointer, :pointer], :void
|
131
|
+
attach_function :xmlNodeDump, [:pointer, :pointer, :pointer, :int, :int], :int
|
132
|
+
attach_function :xmlSaveToIO, [:io_write_callback, :io_close_callback, :pointer, :string, :int], :pointer
|
133
|
+
attach_function :xmlSaveTree, [:pointer, :pointer], :int
|
134
|
+
attach_function :xmlSaveClose, [:pointer], :int
|
135
|
+
attach_function :xmlSetNs, [:pointer, :pointer], :void
|
136
|
+
|
137
|
+
# entities.c
|
138
|
+
attach_function :xmlEncodeSpecialChars, [:pointer, :string], :pointer # returns char* that must be freed
|
139
|
+
|
140
|
+
# xpath.c
|
141
|
+
attach_function :xmlXPathInit, [], :void
|
142
|
+
attach_function :xmlXPathNewContext, [:pointer], :pointer
|
143
|
+
attach_function :xmlXPathFreeContext, [:pointer], :void
|
144
|
+
attach_function :xmlXPathEvalExpression, [:string, :pointer], :pointer
|
145
|
+
attach_function :xmlXPathRegisterNs, [:pointer, :string, :string], :int
|
146
|
+
attach_function :xmlXPathCmpNodes, [:pointer, :pointer], :int
|
147
|
+
attach_function :xmlXPathNodeSetContains, [:pointer, :pointer], :int
|
148
|
+
attach_function :xmlXPathNodeSetAdd, [:pointer, :pointer], :void
|
149
|
+
attach_function :xmlXPathNodeSetRemove, [:pointer, :int], :void
|
150
|
+
attach_function :xmlXPathNodeSetCreate, [:pointer], :pointer
|
151
|
+
attach_function :xmlXPathNodeSetDel, [:pointer, :pointer], :void
|
152
|
+
attach_function :xmlXPathIntersection, [:pointer, :pointer], :pointer
|
153
|
+
attach_function :xmlXPathFreeNodeSetList, [:pointer], :void
|
154
|
+
attach_function :xmlXPathRegisterFuncLookup, [:pointer, :xpath_lookup_callback, :pointer], :void
|
155
|
+
attach_function :valuePop, [:pointer], :pointer
|
156
|
+
attach_function :valuePush, [:pointer, :pointer], :int
|
157
|
+
attach_function :xmlXPathCastToString, [:pointer], :pointer # returns char* that must be freed
|
158
|
+
attach_function :xmlXPathNodeSetMerge, [:pointer, :pointer], :pointer
|
159
|
+
attach_function :xmlXPathWrapNodeSet, [:pointer], :pointer
|
160
|
+
attach_function :xmlXPathWrapCString, [:pointer], :pointer # should take a :string, but we optimize
|
161
|
+
attach_function :xmlXPathWrapString, [:pointer], :pointer # should take a :string, but we optimize
|
162
|
+
attach_function :xmlXPathNewBoolean, [:int], :pointer
|
163
|
+
attach_function :xmlXPathNewFloat, [:double], :pointer
|
164
|
+
|
165
|
+
class << self
|
166
|
+
# these functions are implemented as C macros
|
167
|
+
def xmlXPathReturnNodeSet(ctx, ns)
|
168
|
+
valuePush(ctx, xmlXPathWrapNodeSet(ns))
|
169
|
+
end
|
170
|
+
def xmlXPathReturnTrue(ctx)
|
171
|
+
valuePush(ctx, xmlXPathNewBoolean(1))
|
172
|
+
end
|
173
|
+
def xmlXPathReturnFalse(ctx)
|
174
|
+
valuePush(ctx, xmlXPathNewBoolean(0))
|
175
|
+
end
|
176
|
+
def xmlXPathReturnString(ctx, str)
|
177
|
+
valuePush(ctx, xmlXPathWrapString(str))
|
178
|
+
end
|
179
|
+
def xmlXPathReturnNumber(ctx, val)
|
180
|
+
valuePush(ctx, xmlXPathNewFloat(val))
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# xmlstring.c
|
185
|
+
attach_function :xmlStrdup, [:string], :pointer # returns char* that must be freed
|
186
|
+
def self.xmlFree(pointer)
|
187
|
+
# xmlFree is a C preprocessor macro, not an actual function
|
188
|
+
self.free(pointer)
|
189
|
+
end
|
190
|
+
|
191
|
+
# error.c
|
192
|
+
attach_function :xmlSetStructuredErrorFunc, [:pointer, :syntax_error_handler], :void
|
193
|
+
attach_function :xmlSetGenericErrorFunc, [:pointer, :generic_error_handler], :void
|
194
|
+
attach_function :xmlResetLastError, [], :void
|
195
|
+
attach_function :xmlCopyError, [:pointer, :pointer], :int
|
196
|
+
attach_function :xmlGetLastError, [], :pointer
|
197
|
+
|
198
|
+
# hash.c
|
199
|
+
attach_function :xmlHashScan, [:pointer, :hash_copier_callback, :pointer], :void
|
200
|
+
|
201
|
+
# xmlreader.c
|
202
|
+
attach_function :xmlReaderForMemory, [:pointer, :int, :string, :string, :int], :pointer
|
203
|
+
attach_function :xmlTextReaderGetAttribute, [:pointer, :string], :pointer # returns char* that must be freed
|
204
|
+
attach_function :xmlTextReaderGetAttributeNo, [:pointer, :int], :pointer # returns char* that must be freed
|
205
|
+
attach_function :xmlTextReaderLookupNamespace, [:pointer, :string], :pointer # returns char* that must be freed
|
206
|
+
attach_function :xmlTextReaderRead, [:pointer], :int
|
207
|
+
attach_function :xmlTextReaderAttributeCount, [:pointer], :int
|
208
|
+
attach_function :xmlTextReaderCurrentNode, [:pointer], :pointer
|
209
|
+
attach_function :xmlTextReaderExpand, [:pointer], :pointer
|
210
|
+
attach_function :xmlTextReaderIsDefault, [:pointer], :int
|
211
|
+
attach_function :xmlTextReaderDepth, [:pointer], :int
|
212
|
+
attach_function :xmlTextReaderConstXmlLang, [:pointer], :pointer # returns a const char*, but must check for null
|
213
|
+
attach_function :xmlTextReaderConstLocalName, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
214
|
+
attach_function :xmlTextReaderConstName, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
215
|
+
attach_function :xmlTextReaderConstNamespaceUri, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
216
|
+
attach_function :xmlTextReaderConstPrefix, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
217
|
+
attach_function :xmlTextReaderConstValue, [:pointer], :pointer # returns a const char* that is deallocated on the next read()
|
218
|
+
attach_function :xmlTextReaderConstXmlVersion, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
219
|
+
attach_function :xmlTextReaderReadState, [:pointer], :int
|
220
|
+
attach_function :xmlTextReaderHasValue, [:pointer], :int
|
221
|
+
attach_function :xmlFreeTextReader, [:pointer], :void
|
222
|
+
attach_function :xmlReaderForIO, [:io_read_callback, :io_close_callback, :pointer, :string, :string, :int], :pointer
|
223
|
+
|
224
|
+
# xslt.c
|
225
|
+
attach_function :xsltParseStylesheetDoc, [:pointer], :pointer
|
226
|
+
attach_function :xsltFreeStylesheet, [:pointer], :void
|
227
|
+
attach_function :xsltApplyStylesheet, [:pointer, :pointer, :pointer], :pointer
|
228
|
+
attach_function :xsltSaveResultToString, [:pointer, :pointer, :pointer, :pointer], :int
|
229
|
+
attach_function :xsltSetGenericErrorFunc, [:pointer, :generic_error_handler], :void
|
230
|
+
|
231
|
+
# exslt.c
|
232
|
+
attach_function :exsltRegisterAll, [], :void
|
233
|
+
|
234
|
+
# xmlschemas.c
|
235
|
+
attach_function :xmlSchemaNewValidCtxt, [:pointer], :pointer
|
236
|
+
attach_function :xmlSchemaSetValidStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
237
|
+
attach_function :xmlSchemaValidateDoc, [:pointer, :pointer], :void
|
238
|
+
attach_function :xmlSchemaFreeValidCtxt, [:pointer], :void
|
239
|
+
attach_function :xmlSchemaNewMemParserCtxt, [:pointer, :int], :pointer # first arg could be string, but we pass length, so let's optimize
|
240
|
+
attach_function :xmlSchemaSetParserStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
241
|
+
attach_function :xmlSchemaParse, [:pointer], :pointer
|
242
|
+
attach_function :xmlSchemaFreeParserCtxt, [:pointer], :void
|
243
|
+
|
244
|
+
# relaxng.c
|
245
|
+
attach_function :xmlRelaxNGNewValidCtxt, [:pointer], :pointer
|
246
|
+
attach_function :xmlRelaxNGSetValidStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
247
|
+
attach_function :xmlRelaxNGValidateDoc, [:pointer, :pointer], :int
|
248
|
+
attach_function :xmlRelaxNGFreeValidCtxt, [:pointer], :void
|
249
|
+
attach_function :xmlRelaxNGNewMemParserCtxt, [:pointer, :int], :pointer # first arg could be string, but we pass length, so let's optimize
|
250
|
+
attach_function :xmlRelaxNGSetParserStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
251
|
+
attach_function :xmlRelaxNGParse, [:pointer], :pointer
|
252
|
+
attach_function :xmlRelaxNGFreeParserCtxt, [:pointer], :void
|
253
|
+
|
254
|
+
# helpers
|
255
|
+
def self.pointer_offset(n)
|
256
|
+
n * FFI.type_size(:pointer) # byte offset of nth pointer in an array of pointers
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
require 'nokogiri/syntax_error'
|
262
|
+
require 'nokogiri/xml/syntax_error'
|
263
|
+
|
264
|
+
[ "io_callbacks",
|
265
|
+
"structs/common_node",
|
266
|
+
"structs/xml_alloc",
|
267
|
+
"structs/xml_document",
|
268
|
+
"structs/xml_node",
|
269
|
+
"structs/xml_dtd",
|
270
|
+
"structs/xml_notation",
|
271
|
+
"structs/xml_node_set",
|
272
|
+
"structs/xml_xpath_context",
|
273
|
+
"structs/xml_xpath_object",
|
274
|
+
"structs/xml_xpath_parser_context",
|
275
|
+
"structs/xml_buffer",
|
276
|
+
"structs/xml_syntax_error",
|
277
|
+
"structs/xml_attr",
|
278
|
+
"structs/xml_ns",
|
279
|
+
"structs/xml_schema",
|
280
|
+
"structs/xml_relax_ng",
|
281
|
+
"structs/xml_text_reader",
|
282
|
+
"structs/xml_sax_handler",
|
283
|
+
"structs/xml_sax_push_parser_context",
|
284
|
+
"structs/html_elem_desc",
|
285
|
+
"structs/html_entity_desc",
|
286
|
+
"structs/xslt_stylesheet",
|
287
|
+
"xml/node",
|
288
|
+
"xml/namespace",
|
289
|
+
"xml/dtd",
|
290
|
+
"xml/attr",
|
291
|
+
"xml/document",
|
292
|
+
"xml/document_fragment",
|
293
|
+
"xml/schema",
|
294
|
+
"xml/relax_ng",
|
295
|
+
"xml/text",
|
296
|
+
"xml/cdata",
|
297
|
+
"xml/comment",
|
298
|
+
"xml/processing_instruction",
|
299
|
+
"xml/node_set",
|
300
|
+
"xml/xpath",
|
301
|
+
"xml/xpath_context",
|
302
|
+
"xml/syntax_error",
|
303
|
+
"xml/reader",
|
304
|
+
"xml/entity_reference",
|
305
|
+
"xml/sax/parser",
|
306
|
+
"xml/sax/push_parser",
|
307
|
+
"html/document",
|
308
|
+
"html/element_description",
|
309
|
+
"html/entity_lookup",
|
310
|
+
"html/sax/parser",
|
311
|
+
"xslt/stylesheet",
|
312
|
+
].each do |file|
|
313
|
+
require File.join(File.dirname(__FILE__), file)
|
314
|
+
end
|