nokogiri 1.2.3-x86-mswin32-60 → 1.4.5-x86-mswin32-60
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 +18 -7
- data/.gemtest +0 -0
- data/CHANGELOG.ja.rdoc +297 -3
- data/CHANGELOG.rdoc +289 -0
- data/Manifest.txt +148 -37
- data/README.ja.rdoc +20 -20
- data/README.rdoc +53 -22
- data/Rakefile +127 -211
- data/bin/nokogiri +54 -0
- data/ext/nokogiri/depend +358 -0
- data/ext/nokogiri/extconf.rb +89 -54
- data/ext/nokogiri/html_document.c +34 -27
- data/ext/nokogiri/html_document.h +1 -1
- data/ext/nokogiri/html_element_description.c +276 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +7 -5
- data/ext/nokogiri/html_entity_lookup.h +1 -1
- data/ext/nokogiri/html_sax_parser_context.c +94 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/{native.c → nokogiri.c} +31 -7
- data/ext/nokogiri/{native.h → nokogiri.h} +68 -41
- data/ext/nokogiri/xml_attr.c +20 -9
- data/ext/nokogiri/xml_attr.h +1 -1
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +21 -9
- data/ext/nokogiri/xml_cdata.h +1 -1
- data/ext/nokogiri/xml_comment.c +18 -6
- data/ext/nokogiri/xml_comment.h +1 -1
- data/ext/nokogiri/xml_document.c +247 -68
- data/ext/nokogiri/xml_document.h +5 -3
- data/ext/nokogiri/xml_document_fragment.c +15 -7
- data/ext/nokogiri/xml_document_fragment.h +1 -1
- data/ext/nokogiri/xml_dtd.c +110 -10
- data/ext/nokogiri/xml_dtd.h +3 -1
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_encoding_handler.c +79 -0
- data/ext/nokogiri/xml_encoding_handler.h +8 -0
- data/ext/nokogiri/xml_entity_decl.c +110 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +16 -5
- data/ext/nokogiri/xml_entity_reference.h +1 -1
- data/ext/nokogiri/xml_io.c +40 -8
- data/ext/nokogiri/xml_io.h +2 -1
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_namespace.c +84 -0
- data/ext/nokogiri/xml_namespace.h +13 -0
- data/ext/nokogiri/xml_node.c +782 -225
- data/ext/nokogiri/xml_node.h +2 -4
- data/ext/nokogiri/xml_node_set.c +253 -34
- data/ext/nokogiri/xml_node_set.h +2 -2
- data/ext/nokogiri/xml_processing_instruction.c +17 -5
- data/ext/nokogiri/xml_processing_instruction.h +1 -1
- data/ext/nokogiri/xml_reader.c +277 -85
- data/ext/nokogiri/xml_reader.h +1 -1
- data/ext/nokogiri/xml_relax_ng.c +168 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +183 -111
- data/ext/nokogiri/xml_sax_parser.h +30 -1
- data/ext/nokogiri/xml_sax_parser_context.c +199 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +42 -12
- data/ext/nokogiri/xml_sax_push_parser.h +1 -1
- data/ext/nokogiri/xml_schema.c +205 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +28 -173
- data/ext/nokogiri/xml_syntax_error.h +2 -1
- data/ext/nokogiri/xml_text.c +16 -6
- data/ext/nokogiri/xml_text.h +1 -1
- data/ext/nokogiri/xml_xpath_context.c +104 -47
- data/ext/nokogiri/xml_xpath_context.h +1 -1
- data/ext/nokogiri/xslt_stylesheet.c +161 -19
- data/ext/nokogiri/xslt_stylesheet.h +1 -1
- data/lib/nokogiri.rb +47 -8
- data/lib/nokogiri/1.8/nokogiri.so +0 -0
- data/lib/nokogiri/1.9/nokogiri.so +0 -0
- data/lib/nokogiri/css.rb +6 -3
- data/lib/nokogiri/css/node.rb +14 -12
- data/lib/nokogiri/css/parser.rb +665 -62
- data/lib/nokogiri/css/parser.y +20 -10
- data/lib/nokogiri/css/parser_extras.rb +91 -0
- data/lib/nokogiri/css/tokenizer.rb +148 -5
- data/lib/nokogiri/css/tokenizer.rex +10 -9
- data/lib/nokogiri/css/xpath_visitor.rb +47 -44
- data/lib/nokogiri/decorators/slop.rb +8 -4
- data/lib/nokogiri/ffi/encoding_handler.rb +42 -0
- data/lib/nokogiri/ffi/html/document.rb +28 -0
- data/lib/nokogiri/ffi/html/element_description.rb +81 -0
- data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
- data/lib/nokogiri/ffi/html/sax/parser_context.rb +38 -0
- data/lib/nokogiri/ffi/io_callbacks.rb +42 -0
- data/lib/nokogiri/ffi/libxml.rb +420 -0
- data/lib/nokogiri/ffi/structs/common_node.rb +38 -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 +20 -0
- data/lib/nokogiri/ffi/structs/xml_attribute.rb +27 -0
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_char_encoding_handler.rb +11 -0
- data/lib/nokogiri/ffi/structs/xml_document.rb +117 -0
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +28 -0
- data/lib/nokogiri/ffi/structs/xml_element.rb +26 -0
- data/lib/nokogiri/ffi/structs/xml_element_content.rb +17 -0
- data/lib/nokogiri/ffi/structs/xml_entity.rb +32 -0
- data/lib/nokogiri/ffi/structs/xml_enumeration.rb +12 -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_parser_context.rb +20 -0
- data/lib/nokogiri/ffi/structs/xml_parser_input.rb +19 -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 +124 -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 +38 -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/weak_bucket.rb +40 -0
- data/lib/nokogiri/ffi/xml/attr.rb +41 -0
- data/lib/nokogiri/ffi/xml/attribute_decl.rb +27 -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 +174 -0
- data/lib/nokogiri/ffi/xml/document_fragment.rb +21 -0
- data/lib/nokogiri/ffi/xml/dtd.rb +67 -0
- data/lib/nokogiri/ffi/xml/element_content.rb +43 -0
- data/lib/nokogiri/ffi/xml/element_decl.rb +19 -0
- data/lib/nokogiri/ffi/xml/entity_decl.rb +36 -0
- data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/ffi/xml/namespace.rb +44 -0
- data/lib/nokogiri/ffi/xml/node.rb +559 -0
- data/lib/nokogiri/ffi/xml/node_set.rb +150 -0
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
- data/lib/nokogiri/ffi/xml/reader.rb +236 -0
- data/lib/nokogiri/ffi/xml/relax_ng.rb +85 -0
- data/lib/nokogiri/ffi/xml/sax/parser.rb +143 -0
- data/lib/nokogiri/ffi/xml/sax/parser_context.rb +79 -0
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +51 -0
- data/lib/nokogiri/ffi/xml/schema.rb +109 -0
- data/lib/nokogiri/ffi/xml/syntax_error.rb +98 -0
- data/lib/nokogiri/ffi/xml/text.rb +18 -0
- data/lib/nokogiri/ffi/xml/xpath.rb +9 -0
- data/lib/nokogiri/ffi/xml/xpath_context.rb +153 -0
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +77 -0
- data/lib/nokogiri/html.rb +13 -47
- data/lib/nokogiri/html/builder.rb +27 -1
- data/lib/nokogiri/html/document.rb +201 -7
- data/lib/nokogiri/html/document_fragment.rb +41 -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 +34 -3
- data/lib/nokogiri/html/sax/parser_context.rb +16 -0
- data/lib/nokogiri/nokogiri.rb +1 -0
- data/lib/nokogiri/version.rb +40 -1
- data/lib/nokogiri/version_warning.rb +14 -0
- data/lib/nokogiri/xml.rb +32 -53
- data/lib/nokogiri/xml/attr.rb +5 -0
- data/lib/nokogiri/xml/attribute_decl.rb +18 -0
- data/lib/nokogiri/xml/builder.rb +349 -29
- data/lib/nokogiri/xml/cdata.rb +3 -1
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +166 -14
- data/lib/nokogiri/xml/document_fragment.rb +76 -1
- data/lib/nokogiri/xml/dtd.rb +16 -3
- data/lib/nokogiri/xml/element_content.rb +36 -0
- data/lib/nokogiri/xml/element_decl.rb +13 -0
- data/lib/nokogiri/xml/entity_decl.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +13 -0
- data/lib/nokogiri/xml/node.rb +561 -166
- data/lib/nokogiri/xml/node/save_options.rb +22 -2
- data/lib/nokogiri/xml/node_set.rb +202 -40
- data/lib/nokogiri/xml/parse_options.rb +93 -0
- data/lib/nokogiri/xml/pp.rb +2 -0
- data/lib/nokogiri/xml/pp/character_data.rb +18 -0
- data/lib/nokogiri/xml/pp/node.rb +56 -0
- data/lib/nokogiri/xml/processing_instruction.rb +2 -0
- data/lib/nokogiri/xml/reader.rb +93 -8
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +1 -7
- data/lib/nokogiri/xml/sax/document.rb +107 -2
- data/lib/nokogiri/xml/sax/parser.rb +57 -7
- data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +13 -1
- data/lib/nokogiri/xml/schema.rb +63 -0
- data/lib/nokogiri/xml/syntax_error.rb +25 -1
- data/lib/nokogiri/xml/text.rb +4 -1
- data/lib/nokogiri/xml/xpath.rb +1 -1
- data/lib/nokogiri/xml/xpath/syntax_error.rb +3 -0
- data/lib/nokogiri/xml/xpath_context.rb +2 -0
- data/lib/nokogiri/xslt.rb +26 -2
- data/lib/nokogiri/xslt/stylesheet.rb +19 -0
- data/lib/xsd/xmlparser/nokogiri.rb +45 -9
- data/tasks/cross_compile.rb +173 -0
- data/tasks/test.rb +25 -69
- data/test/css/test_nthiness.rb +3 -4
- data/test/css/test_parser.rb +75 -20
- data/test/css/test_tokenizer.rb +23 -1
- data/test/css/test_xpath_visitor.rb +10 -1
- data/test/decorators/test_slop.rb +16 -0
- data/test/ffi/test_document.rb +35 -0
- data/test/files/2ch.html +108 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/bar/bar.xsd +4 -0
- data/test/files/encoding.html +82 -0
- data/test/files/encoding.xhtml +84 -0
- data/test/files/foo/foo.xsd +4 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/files/shift_jis.html +10 -0
- data/test/files/shift_jis.xml +5 -0
- data/test/files/snuggles.xml +3 -0
- data/test/files/staff.dtd +10 -0
- data/test/files/valid_bar.xml +2 -0
- data/test/helper.rb +101 -23
- data/test/html/sax/test_parser.rb +81 -2
- data/test/html/sax/test_parser_context.rb +48 -0
- data/test/html/test_builder.rb +39 -8
- data/test/html/test_document.rb +186 -23
- data/test/html/test_document_encoding.rb +78 -1
- data/test/html/test_document_fragment.rb +253 -0
- data/test/html/test_element_description.rb +98 -0
- data/test/html/test_named_characters.rb +1 -1
- data/test/html/test_node.rb +124 -36
- data/test/html/test_node_encoding.rb +27 -0
- data/test/test_convert_xpath.rb +1 -52
- data/test/test_css_cache.rb +2 -13
- data/test/test_encoding_handler.rb +46 -0
- data/test/test_memory_leak.rb +88 -19
- data/test/test_nokogiri.rb +38 -5
- data/test/test_reader.rb +188 -6
- data/test/test_soap4r_sax.rb +52 -0
- data/test/test_xslt_transforms.rb +183 -83
- data/test/xml/node/test_save_options.rb +1 -1
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +175 -4
- data/test/xml/sax/test_parser_context.rb +113 -0
- data/test/xml/sax/test_push_parser.rb +90 -2
- data/test/xml/test_attr.rb +35 -1
- data/test/xml/test_attribute_decl.rb +82 -0
- data/test/xml/test_builder.rb +186 -1
- data/test/xml/test_cdata.rb +32 -1
- data/test/xml/test_comment.rb +13 -1
- data/test/xml/test_document.rb +415 -43
- data/test/xml/test_document_encoding.rb +1 -1
- data/test/xml/test_document_fragment.rb +173 -5
- data/test/xml/test_dtd.rb +61 -6
- data/test/xml/test_dtd_encoding.rb +3 -1
- data/test/xml/test_element_content.rb +56 -0
- data/test/xml/test_element_decl.rb +73 -0
- data/test/xml/test_entity_decl.rb +120 -0
- data/test/xml/test_entity_reference.rb +5 -1
- data/test/xml/test_namespace.rb +68 -0
- data/test/xml/test_node.rb +546 -201
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +33 -3
- data/test/xml/test_node_reparenting.rb +321 -0
- data/test/xml/test_node_set.rb +538 -2
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +6 -1
- data/test/xml/test_reader_encoding.rb +1 -1
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +94 -0
- data/test/xml/test_syntax_error.rb +12 -0
- data/test/xml/test_text.rb +35 -1
- data/test/xml/test_unparented_node.rb +5 -5
- data/test/xml/test_xpath.rb +142 -11
- data/test/xslt/test_custom_functions.rb +94 -0
- metadata +328 -92
- data/ext/nokogiri/html_sax_parser.c +0 -57
- data/ext/nokogiri/html_sax_parser.h +0 -11
- data/ext/nokogiri/iconv.dll +0 -0
- data/ext/nokogiri/libexslt.dll +0 -0
- data/ext/nokogiri/libxml2.dll +0 -0
- data/ext/nokogiri/libxslt.dll +0 -0
- data/ext/nokogiri/native.so +0 -0
- data/ext/nokogiri/xml_xpath.c +0 -53
- data/ext/nokogiri/xml_xpath.h +0 -11
- data/ext/nokogiri/zlib1.dll +0 -0
- data/lib/action-nokogiri.rb +0 -30
- data/lib/nokogiri/css/generated_parser.rb +0 -713
- data/lib/nokogiri/css/generated_tokenizer.rb +0 -144
- data/lib/nokogiri/decorators.rb +0 -2
- data/lib/nokogiri/decorators/hpricot.rb +0 -3
- data/lib/nokogiri/decorators/hpricot/node.rb +0 -56
- data/lib/nokogiri/decorators/hpricot/node_set.rb +0 -54
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +0 -28
- data/lib/nokogiri/hpricot.rb +0 -51
- data/lib/nokogiri/xml/comment.rb +0 -6
- data/lib/nokogiri/xml/element.rb +0 -6
- data/lib/nokogiri/xml/entity_declaration.rb +0 -9
- data/lib/nokogiri/xml/fragment_handler.rb +0 -34
- data/test/hpricot/files/basic.xhtml +0 -17
- data/test/hpricot/files/boingboing.html +0 -2266
- data/test/hpricot/files/cy0.html +0 -3653
- data/test/hpricot/files/immob.html +0 -400
- data/test/hpricot/files/pace_application.html +0 -1320
- data/test/hpricot/files/tenderlove.html +0 -16
- data/test/hpricot/files/uswebgen.html +0 -220
- data/test/hpricot/files/utf8.html +0 -1054
- data/test/hpricot/files/week9.html +0 -1723
- data/test/hpricot/files/why.xml +0 -19
- data/test/hpricot/load_files.rb +0 -11
- data/test/hpricot/test_alter.rb +0 -68
- data/test/hpricot/test_builder.rb +0 -20
- data/test/hpricot/test_parser.rb +0 -426
- data/test/hpricot/test_paths.rb +0 -15
- data/test/hpricot/test_preserved.rb +0 -77
- data/test/hpricot/test_xml.rb +0 -30
- data/test/test_gc.rb +0 -15
@@ -4,25 +4,29 @@ 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
|
10
|
+
prefix = implied_xpath_context
|
11
|
+
|
8
12
|
if args.empty?
|
9
|
-
list = xpath("
|
13
|
+
list = xpath("#{prefix}#{name.to_s.sub(/^_/, '')}")
|
10
14
|
elsif args.first.is_a? Hash
|
11
15
|
hash = args.first
|
12
16
|
if hash[:css]
|
13
17
|
list = css("#{name}#{hash[:css]}")
|
14
18
|
elsif hash[:xpath]
|
15
19
|
conds = Array(hash[:xpath]).join(' and ')
|
16
|
-
list = xpath("
|
20
|
+
list = xpath("#{prefix}#{name}[#{conds}]")
|
17
21
|
end
|
18
22
|
else
|
19
23
|
CSS::Parser.without_cache do
|
20
24
|
list = xpath(
|
21
|
-
*CSS.xpath_for("#{name}#{args.first}", :prefix =>
|
25
|
+
*CSS.xpath_for("#{name}#{args.first}", :prefix => prefix)
|
22
26
|
)
|
23
27
|
end
|
24
28
|
end
|
25
|
-
|
29
|
+
|
26
30
|
super if list.empty?
|
27
31
|
list.length == 1 ? list.first : list
|
28
32
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
class EncodingHandler
|
3
|
+
# :stopdoc:
|
4
|
+
attr_accessor :cstruct
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def [](key)
|
8
|
+
handler = LibXML.xmlFindCharEncodingHandler(key)
|
9
|
+
handler.null? ? nil : wrap(handler)
|
10
|
+
end
|
11
|
+
|
12
|
+
def delete(name)
|
13
|
+
(LibXML.xmlDelEncodingAlias(name) != 0) ? nil : true
|
14
|
+
end
|
15
|
+
|
16
|
+
def alias(from, to)
|
17
|
+
LibXML.xmlAddEncodingAlias(from, to)
|
18
|
+
to
|
19
|
+
end
|
20
|
+
|
21
|
+
def clear_aliases!
|
22
|
+
LibXML.xmlCleanupEncodingAliases
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def wrap(ptr)
|
29
|
+
cstruct = LibXML::XmlCharEncodingHandler.new(ptr)
|
30
|
+
eh = Nokogiri::EncodingHandler.allocate
|
31
|
+
eh.cstruct = cstruct
|
32
|
+
eh
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def name
|
38
|
+
cstruct[:name]
|
39
|
+
end
|
40
|
+
# :startdoc:
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,28 @@
|
|
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
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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
|
+
ptr = cstruct[sym]
|
72
|
+
unless ptr.null?
|
73
|
+
ptr.get_array_of_string(0)
|
74
|
+
else
|
75
|
+
[]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
81
|
+
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,38 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
module Nokogiri
|
3
|
+
module HTML
|
4
|
+
module SAX
|
5
|
+
class ParserContext < Nokogiri::XML::SAX::ParserContext
|
6
|
+
attr_accessor :cstruct
|
7
|
+
|
8
|
+
def self.file filename, encoding
|
9
|
+
ctx = LibXML.htmlCreateFileParserCtxt filename, encoding
|
10
|
+
pc = allocate
|
11
|
+
pc.cstruct = LibXML::XmlParserContext.new ctx
|
12
|
+
pc
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.memory data, encoding
|
16
|
+
raise ArgumentError unless data
|
17
|
+
raise "data cannot be empty" unless data.length > 0
|
18
|
+
|
19
|
+
ctx = LibXML.htmlCreateMemoryParserCtxt data, data.length
|
20
|
+
pc = allocate
|
21
|
+
pc.cstruct = LibXML::XmlParserContext.new ctx
|
22
|
+
if encoding
|
23
|
+
enc = LibXML.xmlFindCharEncodingHandler(encoding)
|
24
|
+
if !enc.null?
|
25
|
+
LibXML.xmlSwitchToEncoding(ctx, enc)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
pc
|
29
|
+
end
|
30
|
+
|
31
|
+
def parse_with sax_handler, type = :html
|
32
|
+
super
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
# :startdoc:
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
module Nokogiri
|
3
|
+
module IoCallbacks
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def plain_old_reader(io)
|
8
|
+
lambda do |ctx, buffer, len|
|
9
|
+
string = io.read(len)
|
10
|
+
return 0 if string.nil?
|
11
|
+
buffer.put_bytes(0, string, 0, string.length)
|
12
|
+
string.length
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
if defined?(FFI::IO.native_read)
|
17
|
+
def ffi_io_native_reader(io)
|
18
|
+
if io.is_a?(StringIO)
|
19
|
+
plain_old_reader(io)
|
20
|
+
else
|
21
|
+
lambda do |ctx, buffer, len|
|
22
|
+
rcode = FFI::IO.native_read(io, buffer, len)
|
23
|
+
(rcode < 0) ? 0 : rcode
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
alias :reader :ffi_io_native_reader
|
28
|
+
else
|
29
|
+
alias :reader :plain_old_reader
|
30
|
+
end
|
31
|
+
|
32
|
+
def writer(io)
|
33
|
+
lambda do |context, buffer, len|
|
34
|
+
io.write buffer
|
35
|
+
len
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
# :startdoc:
|
@@ -0,0 +1,420 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
module Nokogiri
|
3
|
+
module LibXML
|
4
|
+
extend FFI::Library
|
5
|
+
if RUBY_PLATFORM =~ /java/ && RbConfig::CONFIG['host_os'] =~ /(mswin|mingw)/i
|
6
|
+
raise(RuntimeError, "Nokogiri requires JRuby 1.4.0 or later on Windows") if JRUBY_VERSION < "1.4.0"
|
7
|
+
dll_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "ext", "nokogiri"))
|
8
|
+
libs = ["libxml2.dll", "libxslt.dll", "libexslt.dll"].collect do |lib|
|
9
|
+
File.join(dll_dir, lib).tr("/","\\") # see http://jira.codehaus.org/browse/JRUBY-2763
|
10
|
+
end + ["msvcrt"]
|
11
|
+
ffi_lib(*libs)
|
12
|
+
else
|
13
|
+
ffi_lib 'xml2', 'xslt', 'exslt'
|
14
|
+
end
|
15
|
+
|
16
|
+
# globals.c
|
17
|
+
attach_function :__xmlParserVersion, [], :pointer
|
18
|
+
attach_function :__xmlIndentTreeOutput, [], :pointer
|
19
|
+
attach_function :__xmlTreeIndentString, [], :pointer
|
20
|
+
attach_function :xmlDeregisterNodeDefault, [:pointer], :pointer
|
21
|
+
end
|
22
|
+
|
23
|
+
LIBXML_PARSER_VERSION = LibXML.__xmlParserVersion().read_pointer.read_string
|
24
|
+
LIBXML_VERSION = LIBXML_PARSER_VERSION.scan(/^(.*)(..)(..)$/).first.collect{|j|j.to_i}.join(".")
|
25
|
+
|
26
|
+
LIBXML_ICONV_ENABLED = true # sigh.
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'nokogiri/version'
|
30
|
+
|
31
|
+
Nokogiri::VERSION_INFO['libxml'] = {}
|
32
|
+
Nokogiri::VERSION_INFO['libxml']['loaded'] = Nokogiri::LIBXML_VERSION
|
33
|
+
Nokogiri::VERSION_INFO['libxml']['binding'] = 'ffi'
|
34
|
+
if RUBY_PLATFORM =~ /java/
|
35
|
+
Nokogiri::VERSION_INFO['libxml']['platform'] = 'jruby'
|
36
|
+
raise(RuntimeError, "Nokogiri requires JRuby 1.3.0 or later") if JRUBY_VERSION < "1.3.0"
|
37
|
+
else
|
38
|
+
Nokogiri::VERSION_INFO['libxml']['platform'] = 'ruby'
|
39
|
+
end
|
40
|
+
|
41
|
+
module Nokogiri
|
42
|
+
module LibXML
|
43
|
+
XML_CHAR_ENCODING_ERROR = -1
|
44
|
+
|
45
|
+
# useful callback signatures
|
46
|
+
callback :syntax_error_handler, [:pointer, :pointer], :void
|
47
|
+
callback :generic_error_handler, [:pointer, :string], :void
|
48
|
+
callback :io_write_callback, [:pointer, :string, :int], :int
|
49
|
+
callback :io_read_callback, [:pointer, :pointer, :int], :int
|
50
|
+
callback :io_close_callback, [:pointer], :int
|
51
|
+
callback :hash_copier_callback, [:pointer, :pointer, :string], :void
|
52
|
+
callback :xpath_callback, [:pointer, :int], :void
|
53
|
+
callback :xpath_lookup_callback, [:pointer, :string, :pointer], :xpath_callback
|
54
|
+
callback :start_document_sax_func, [:pointer], :void
|
55
|
+
callback :end_document_sax_func, [:pointer], :void
|
56
|
+
callback :start_element_sax_func, [:pointer, :string, :pointer], :void
|
57
|
+
callback :end_element_sax_func, [:pointer, :string], :void
|
58
|
+
callback :characters_sax_func, [:pointer, :string, :int], :void
|
59
|
+
callback :comment_sax_func, [:pointer, :string], :void
|
60
|
+
callback :warning_sax_func, [:pointer, :string], :void
|
61
|
+
callback :error_sax_func, [:pointer, :string], :void
|
62
|
+
callback :cdata_block_sax_func, [:pointer, :string, :int], :void
|
63
|
+
callback :start_element_ns_sax2_func, [:pointer, :pointer, :pointer, :pointer, :int, :pointer, :int, :int, :pointer], :void
|
64
|
+
callback :end_element_ns_sax2_func, [:pointer, :pointer, :pointer, :pointer], :void
|
65
|
+
callback :xslt_function_init, [:pointer, :string], :pointer
|
66
|
+
callback :xslt_function_shutdown, [:pointer, :string, :pointer], :void
|
67
|
+
callback :xslt_function_caller, [:pointer, :int], :void
|
68
|
+
|
69
|
+
# encoding.c
|
70
|
+
attach_function :xmlFindCharEncodingHandler, [:string], :pointer
|
71
|
+
attach_function :xmlDelEncodingAlias, [:string], :int
|
72
|
+
attach_function :xmlAddEncodingAlias, [:string, :string], :int
|
73
|
+
attach_function :xmlCleanupEncodingAliases, [], :void
|
74
|
+
|
75
|
+
# HTMLparser.c
|
76
|
+
attach_function :htmlReadMemory, [:string, :int, :string, :string, :int], :pointer
|
77
|
+
attach_function :htmlReadIO, [:io_read_callback, :io_close_callback, :pointer, :string, :string, :int], :pointer
|
78
|
+
attach_function :htmlNewDoc, [:string, :string], :pointer
|
79
|
+
attach_function :htmlTagLookup, [:string], :pointer
|
80
|
+
attach_function :htmlEntityLookup, [:string], :pointer
|
81
|
+
attach_function :htmlSAXParseFile, [:string, :pointer, :pointer, :pointer], :pointer # second arg 'encoding' should be a string, but we assign it as a pointer elsewhere
|
82
|
+
attach_function :htmlSAXParseDoc, [:pointer, :pointer, :pointer, :pointer], :pointer # second arg 'encoding' should be a string, but we assign it as a pointer elsewhere
|
83
|
+
attach_function :htmlCreateMemoryParserCtxt, [:pointer, :int], :pointer
|
84
|
+
attach_function :htmlCreateFileParserCtxt, [:pointer, :pointer], :pointer
|
85
|
+
attach_function :htmlParseDocument, [:pointer], :int
|
86
|
+
attach_function :htmlHandleOmittedElem, [:int], :int
|
87
|
+
|
88
|
+
# HTMLtree.c
|
89
|
+
attach_function :htmlDocDumpMemory, [:pointer, :pointer, :pointer], :void
|
90
|
+
attach_function :htmlNodeDump, [:pointer, :pointer, :pointer], :int
|
91
|
+
attach_function :htmlGetMetaEncoding, [:pointer], :string # returns const char*
|
92
|
+
attach_function :htmlSetMetaEncoding, [:pointer, :string], :void
|
93
|
+
|
94
|
+
# parser.c
|
95
|
+
attach_function :xmlReadMemory, [:string, :int, :string, :string, :int], :pointer
|
96
|
+
attach_function :xmlInitParser, [], :void
|
97
|
+
attach_function :xmlReadIO, [:io_read_callback, :io_close_callback, :pointer, :string, :string, :int], :pointer
|
98
|
+
attach_function :xmlCreateIOParserCtxt, [:pointer, :pointer, :io_read_callback, :io_close_callback, :pointer, :int], :pointer
|
99
|
+
attach_function :xmlCreateMemoryParserCtxt, [:pointer, :int], :pointer
|
100
|
+
attach_function :xmlCreateFileParserCtxt, [:pointer], :pointer
|
101
|
+
attach_function :xmlSAXUserParseMemory, [:pointer, :pointer, :string, :int], :int
|
102
|
+
attach_function :xmlSAXUserParseFile, [:pointer, :pointer, :string], :int
|
103
|
+
attach_function :xmlParseDocument, [:pointer], :int
|
104
|
+
attach_function :xmlFreeParserCtxt, [:pointer], :void
|
105
|
+
attach_function :xmlCreatePushParserCtxt, [:pointer, :pointer, :string, :int, :string], :pointer
|
106
|
+
attach_function :xmlParseChunk, [:pointer, :string, :int, :int], :int
|
107
|
+
attach_function :xmlCtxtUseOptions, [:pointer, :int], :int
|
108
|
+
attach_function :xmlParseInNodeContext, [:pointer, :string, :int, :int, :pointer], :pointer
|
109
|
+
|
110
|
+
# tree.c
|
111
|
+
attach_function :xmlNewDoc, [:string], :pointer
|
112
|
+
attach_function :xmlNewDocFragment, [:pointer], :pointer
|
113
|
+
attach_function :xmlDocGetRootElement, [:pointer], :pointer
|
114
|
+
attach_function :xmlDocSetRootElement, [:pointer, :pointer], :pointer
|
115
|
+
attach_function :xmlCopyDoc, [:pointer, :int], :pointer
|
116
|
+
attach_function :xmlFreeDoc, [:pointer], :void
|
117
|
+
attach_function :xmlSetTreeDoc, [:pointer, :pointer], :void
|
118
|
+
attach_function :xmlNewReference, [:pointer, :string], :pointer
|
119
|
+
# attach_function :xmlFirstElementChild, [:pointer], :pointer
|
120
|
+
# attach_function :xmlLastElementChild, [:pointer], :pointer
|
121
|
+
# attach_function :xmlNextElementSibling, [:pointer], :pointer
|
122
|
+
attach_function :xmlNewNode, [:pointer, :string], :pointer
|
123
|
+
attach_function :xmlCopyNode, [:pointer, :int], :pointer
|
124
|
+
attach_function :xmlDocCopyNode, [:pointer, :pointer, :int], :pointer
|
125
|
+
attach_function :xmlReplaceNode, [:pointer, :pointer], :pointer
|
126
|
+
attach_function :xmlUnlinkNode, [:pointer], :void
|
127
|
+
attach_function :xmlAddChild, [:pointer, :pointer], :pointer
|
128
|
+
attach_function :xmlAddNextSibling, [:pointer, :pointer], :pointer
|
129
|
+
attach_function :xmlAddPrevSibling, [:pointer, :pointer], :pointer
|
130
|
+
attach_function :xmlIsBlankNode, [:pointer], :int
|
131
|
+
attach_function :xmlHasProp, [:pointer, :string], :pointer
|
132
|
+
attach_function :xmlHasNsProp, [:pointer, :string, :string], :pointer
|
133
|
+
attach_function :xmlGetProp, [:pointer, :string], :pointer # returns char* that must be freed
|
134
|
+
attach_function :xmlSetProp, [:pointer, :string, :string], :pointer
|
135
|
+
attach_function :xmlRemoveProp, [:pointer], :int
|
136
|
+
attach_function :xmlNodeSetContent, [:pointer, :string], :void
|
137
|
+
attach_function :xmlNodeGetContent, [:pointer], :pointer # returns char* that must be freed
|
138
|
+
attach_function :xmlNodeSetName, [:pointer, :string], :void
|
139
|
+
attach_function :xmlGetNodePath, [:pointer], :pointer
|
140
|
+
attach_function :xmlNewCDataBlock, [:pointer, :string, :int], :pointer
|
141
|
+
attach_function :xmlNewDocComment, [:pointer, :string], :pointer
|
142
|
+
attach_function :xmlNewDocPI, [:pointer, :string, :string], :pointer
|
143
|
+
attach_function :xmlNewText, [:string], :pointer
|
144
|
+
attach_function :xmlFreeNode, [:pointer], :void
|
145
|
+
attach_function :xmlFreeNodeList, [:pointer], :void
|
146
|
+
attach_function :xmlEncodeEntitiesReentrant, [:pointer, :string], :pointer # returns char* that must be freed
|
147
|
+
attach_function :xmlStringGetNodeList, [:pointer, :pointer], :pointer # second arg should be a :string, but we only ship the results of xmlEncodeEntitiesReentrant, so let's optimize.
|
148
|
+
attach_function :xmlNewNs, [:pointer, :string, :string], :pointer
|
149
|
+
attach_function :xmlNewNsProp, [:pointer, :pointer, :string, :string], :pointer
|
150
|
+
attach_function :xmlSearchNs, [:pointer, :pointer, :string], :pointer
|
151
|
+
attach_function :xmlSearchNsByHref, [:pointer, :pointer, :string], :pointer
|
152
|
+
attach_function :xmlGetIntSubset, [:pointer], :pointer
|
153
|
+
attach_function :xmlBufferCreate, [], :pointer
|
154
|
+
attach_function :xmlBufferFree, [:pointer], :void
|
155
|
+
attach_function :xmlSplitQName2, [:string, :buffer_out], :pointer # returns char* that must be freed
|
156
|
+
attach_function :xmlNewDocProp, [:pointer, :string, :string], :pointer
|
157
|
+
attach_function :xmlFreePropList, [:pointer], :void
|
158
|
+
attach_function :xmlCreateIntSubset, [:pointer] * 4, :pointer
|
159
|
+
attach_function :xmlNewDtd, [:pointer] * 4, :pointer
|
160
|
+
attach_function :xmlGetNsList, [:pointer, :pointer], :pointer
|
161
|
+
attach_function :xmlTextMerge, [:pointer, :pointer], :pointer
|
162
|
+
attach_function :xmlFreeNsList, [:pointer], :void
|
163
|
+
|
164
|
+
# valid.c
|
165
|
+
attach_function :xmlNewValidCtxt, [], :pointer
|
166
|
+
attach_function :xmlValidateDtd, [:pointer, :pointer, :pointer], :int
|
167
|
+
attach_function :xmlFreeValidCtxt, [:pointer], :void
|
168
|
+
|
169
|
+
# xmlsave.c
|
170
|
+
attach_function :xmlDocDumpMemory, [:pointer, :pointer, :pointer], :void
|
171
|
+
attach_function :xmlNodeDump, [:pointer, :pointer, :pointer, :int, :int], :int
|
172
|
+
attach_function :xmlSaveToIO, [:io_write_callback, :io_close_callback, :pointer, :string, :int], :pointer
|
173
|
+
attach_function :xmlSaveTree, [:pointer, :pointer], :int
|
174
|
+
attach_function :xmlSaveClose, [:pointer], :int
|
175
|
+
attach_function :xmlSetNs, [:pointer, :pointer], :void
|
176
|
+
|
177
|
+
# entities.c
|
178
|
+
attach_function :xmlEncodeSpecialChars, [:pointer, :string], :pointer # returns char* that must be freed
|
179
|
+
attach_function :xmlAddDocEntity, [:pointer, :string, :int, :string, :string, :string], :pointer
|
180
|
+
|
181
|
+
# xpath.c
|
182
|
+
attach_function :xmlXPathInit, [], :void
|
183
|
+
attach_function :xmlXPathNewContext, [:pointer], :pointer
|
184
|
+
attach_function :xmlXPathFreeContext, [:pointer], :void
|
185
|
+
attach_function :xmlXPathEvalExpression, [:string, :pointer], :pointer
|
186
|
+
attach_function :xmlXPathRegisterNs, [:pointer, :string, :string], :int
|
187
|
+
attach_function :xmlXPathCmpNodes, [:pointer, :pointer], :int
|
188
|
+
attach_function :xmlXPathNodeSetContains, [:pointer, :pointer], :int
|
189
|
+
attach_function :xmlXPathNodeSetAdd, [:pointer, :pointer], :void
|
190
|
+
attach_function :xmlXPathNodeSetAddUnique, [:pointer, :pointer], :void
|
191
|
+
attach_function :xmlXPathNodeSetRemove, [:pointer, :int], :void
|
192
|
+
attach_function :xmlXPathNodeSetCreate, [:pointer], :pointer
|
193
|
+
attach_function :xmlXPathNodeSetDel, [:pointer, :pointer], :void
|
194
|
+
attach_function :xmlXPathIntersection, [:pointer, :pointer], :pointer
|
195
|
+
attach_function :xmlXPathFreeNodeSetList, [:pointer], :void
|
196
|
+
attach_function :xmlXPathRegisterFuncLookup, [:pointer, :xpath_lookup_callback, :pointer], :void
|
197
|
+
attach_function :valuePop, [:pointer], :pointer
|
198
|
+
attach_function :valuePush, [:pointer, :pointer], :int
|
199
|
+
attach_function :xmlXPathCastToString, [:pointer], :pointer # returns char* that must be freed
|
200
|
+
attach_function :xmlXPathNodeSetMerge, [:pointer, :pointer], :pointer
|
201
|
+
attach_function :xmlXPathWrapNodeSet, [:pointer], :pointer
|
202
|
+
attach_function :xmlXPathWrapCString, [:pointer], :pointer # should take a :string, but we optimize
|
203
|
+
attach_function :xmlXPathWrapString, [:pointer], :pointer # should take a :string, but we optimize
|
204
|
+
attach_function :xmlXPathNewBoolean, [:int], :pointer
|
205
|
+
attach_function :xmlXPathNewFloat, [:double], :pointer
|
206
|
+
attach_function :xmlXPathNewCString, [:string], :pointer
|
207
|
+
attach_function :xmlXPathRegisterVariable, [:pointer, :string, :pointer], :int
|
208
|
+
|
209
|
+
class << self
|
210
|
+
# these functions are implemented as C macros
|
211
|
+
def xmlXPathReturnNodeSet(ctx, ns)
|
212
|
+
valuePush(ctx, xmlXPathWrapNodeSet(ns))
|
213
|
+
end
|
214
|
+
def xmlXPathReturnTrue(ctx)
|
215
|
+
valuePush(ctx, xmlXPathNewBoolean(1))
|
216
|
+
end
|
217
|
+
def xmlXPathReturnFalse(ctx)
|
218
|
+
valuePush(ctx, xmlXPathNewBoolean(0))
|
219
|
+
end
|
220
|
+
def xmlXPathReturnString(ctx, str)
|
221
|
+
valuePush(ctx, xmlXPathWrapString(str))
|
222
|
+
end
|
223
|
+
def xmlXPathReturnNumber(ctx, val)
|
224
|
+
valuePush(ctx, xmlXPathNewFloat(val))
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
# xmlstring.c
|
229
|
+
attach_function :xmlStrdup, [:string], :pointer # returns char* that must be freed
|
230
|
+
def self.xmlFree(pointer)
|
231
|
+
# xmlFree is a C preprocessor macro, not an actual function
|
232
|
+
self.free(pointer)
|
233
|
+
end
|
234
|
+
|
235
|
+
# error.c
|
236
|
+
attach_function :xmlSetStructuredErrorFunc, [:pointer, :syntax_error_handler], :void
|
237
|
+
attach_function :xmlSetGenericErrorFunc, [:pointer, :generic_error_handler], :void
|
238
|
+
attach_function :xmlResetLastError, [], :void
|
239
|
+
attach_function :xmlCopyError, [:pointer, :pointer], :int
|
240
|
+
attach_function :xmlGetLastError, [], :pointer
|
241
|
+
attach_function :xmlCtxtGetLastError, [:pointer], :pointer
|
242
|
+
|
243
|
+
# hash.c
|
244
|
+
attach_function :xmlHashScan, [:pointer, :hash_copier_callback, :pointer], :void
|
245
|
+
|
246
|
+
# xmlreader.c
|
247
|
+
attach_function :xmlReaderForMemory, [:pointer, :int, :string, :string, :int], :pointer
|
248
|
+
attach_function :xmlTextReaderGetAttribute, [:pointer, :string], :pointer # returns char* that must be freed
|
249
|
+
attach_function :xmlTextReaderGetAttributeNo, [:pointer, :int], :pointer # returns char* that must be freed
|
250
|
+
attach_function :xmlTextReaderLookupNamespace, [:pointer, :string], :pointer # returns char* that must be freed
|
251
|
+
attach_function :xmlTextReaderRead, [:pointer], :int
|
252
|
+
attach_function :xmlTextReaderReadInnerXml, [:pointer], :pointer
|
253
|
+
attach_function :xmlTextReaderReadOuterXml, [:pointer], :pointer
|
254
|
+
attach_function :xmlTextReaderAttributeCount, [:pointer], :int
|
255
|
+
attach_function :xmlTextReaderCurrentNode, [:pointer], :pointer
|
256
|
+
attach_function :xmlTextReaderExpand, [:pointer], :pointer
|
257
|
+
attach_function :xmlTextReaderIsDefault, [:pointer], :int
|
258
|
+
attach_function :xmlTextReaderDepth, [:pointer], :int
|
259
|
+
attach_function :xmlTextReaderConstXmlLang, [:pointer], :pointer # returns a const char*, but must check for null
|
260
|
+
attach_function :xmlTextReaderConstLocalName, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
261
|
+
attach_function :xmlTextReaderConstName, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
262
|
+
attach_function :xmlTextReaderConstNamespaceUri, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
263
|
+
attach_function :xmlTextReaderConstPrefix, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
264
|
+
attach_function :xmlTextReaderConstValue, [:pointer], :pointer # returns a const char* that is deallocated on the next read()
|
265
|
+
attach_function :xmlTextReaderConstXmlVersion, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
266
|
+
attach_function :xmlTextReaderConstBaseUri, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
267
|
+
attach_function :xmlTextReaderReadState, [:pointer], :int
|
268
|
+
attach_function :xmlTextReaderHasValue, [:pointer], :int
|
269
|
+
attach_function :xmlFreeTextReader, [:pointer], :void
|
270
|
+
attach_function :xmlReaderForIO, [:io_read_callback, :io_close_callback, :pointer, :string, :string, :int], :pointer
|
271
|
+
attach_function :xmlTextReaderNodeType, [:pointer], :int
|
272
|
+
attach_function :xmlTextReaderIsEmptyElement, [:pointer], :int
|
273
|
+
|
274
|
+
# xslt.c
|
275
|
+
attach_function :xsltParseStylesheetDoc, [:pointer], :pointer
|
276
|
+
attach_function :xsltFreeStylesheet, [:pointer], :void
|
277
|
+
attach_function :xsltApplyStylesheet, [:pointer, :pointer, :pointer], :pointer
|
278
|
+
attach_function :xsltSaveResultToString, [:buffer_out, :buffer_out, :pointer, :pointer], :int
|
279
|
+
attach_function :xsltSetGenericErrorFunc, [:pointer, :generic_error_handler], :void
|
280
|
+
attach_function :xsltRegisterExtModule, [:string, :xslt_function_init, :xslt_function_shutdown], :int
|
281
|
+
attach_function :xsltRegisterExtFunction, [:pointer, :string, :string, :xslt_function_caller], :int
|
282
|
+
attach_function :xsltXPathGetTransformContext, [:pointer], :pointer
|
283
|
+
|
284
|
+
# exslt.c
|
285
|
+
attach_function :exsltRegisterAll, [], :void
|
286
|
+
|
287
|
+
# xmlschemas.c
|
288
|
+
attach_function :xmlSchemaNewValidCtxt, [:pointer], :pointer
|
289
|
+
attach_function :xmlSchemaSetValidStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
290
|
+
attach_function :xmlSchemaValidateDoc, [:pointer, :pointer], :void
|
291
|
+
attach_function :xmlSchemaFreeValidCtxt, [:pointer], :void
|
292
|
+
attach_function :xmlSchemaNewMemParserCtxt, [:pointer, :int], :pointer # first arg could be string, but we pass length, so let's optimize
|
293
|
+
attach_function :xmlSchemaSetParserStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
294
|
+
attach_function :xmlSchemaParse, [:pointer], :pointer
|
295
|
+
attach_function :xmlSchemaFreeParserCtxt, [:pointer], :void
|
296
|
+
attach_function :xmlSchemaNewDocParserCtxt, [:pointer], :pointer
|
297
|
+
attach_function :xmlSchemaValidateFile, [:pointer, :string, :int], :int
|
298
|
+
|
299
|
+
# relaxng.c
|
300
|
+
attach_function :xmlRelaxNGNewValidCtxt, [:pointer], :pointer
|
301
|
+
attach_function :xmlRelaxNGSetValidStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
302
|
+
attach_function :xmlRelaxNGValidateDoc, [:pointer, :pointer], :int
|
303
|
+
attach_function :xmlRelaxNGFreeValidCtxt, [:pointer], :void
|
304
|
+
attach_function :xmlRelaxNGNewMemParserCtxt, [:pointer, :int], :pointer # first arg could be string, but we pass length, so let's optimize
|
305
|
+
attach_function :xmlRelaxNGSetParserStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
306
|
+
attach_function :xmlRelaxNGParse, [:pointer], :pointer
|
307
|
+
attach_function :xmlRelaxNGFreeParserCtxt, [:pointer], :void
|
308
|
+
attach_function :xmlRelaxNGNewDocParserCtxt, [:pointer], :pointer
|
309
|
+
attach_function :xmlRelaxNGFree, [:pointer], :void
|
310
|
+
|
311
|
+
# libc
|
312
|
+
attach_function :calloc, [:int, :int], :pointer
|
313
|
+
attach_function :free, [:pointer], :void
|
314
|
+
|
315
|
+
attach_function :xmlParseCharEncoding, [:string], :int
|
316
|
+
attach_function :xmlSwitchToEncoding, [:pointer, :pointer], :void
|
317
|
+
|
318
|
+
# helpers
|
319
|
+
POINTER_SIZE = FFI.type_size(:pointer)
|
320
|
+
def self.pointer_offset(n)
|
321
|
+
n * POINTER_SIZE # byte offset of nth pointer in an array of pointers
|
322
|
+
end
|
323
|
+
|
324
|
+
# ZOMG hacks. see GH#303
|
325
|
+
class << self
|
326
|
+
def xmlFirstElementChildHack(parent)
|
327
|
+
return nil if parent.nil?
|
328
|
+
return nil unless [Nokogiri::XML::Node::ELEMENT_NODE, Nokogiri::XML::Node::ENTITY_NODE, Nokogiri::XML::Node::DOCUMENT_NODE, Nokogiri::XML::Node::HTML_DOCUMENT_NODE].include?(parent.type)
|
329
|
+
parent.children.find { |child| child.element? }
|
330
|
+
end
|
331
|
+
|
332
|
+
def xmlLastElementChildHack(parent)
|
333
|
+
return nil if parent.nil?
|
334
|
+
return nil unless [Nokogiri::XML::Node::ELEMENT_NODE, Nokogiri::XML::Node::ENTITY_NODE, Nokogiri::XML::Node::DOCUMENT_NODE, Nokogiri::XML::Node::HTML_DOCUMENT_NODE].include?(parent.type)
|
335
|
+
parent.children.reverse.find { |child| child.element? }
|
336
|
+
end
|
337
|
+
|
338
|
+
def xmlNextElementSiblingHack(sibling)
|
339
|
+
return nil if sibling.nil?
|
340
|
+
return nil unless [Nokogiri::XML::Node::ELEMENT_NODE, Nokogiri::XML::Node::ENTITY_NODE, Nokogiri::XML::Node::DOCUMENT_NODE, Nokogiri::XML::Node::HTML_DOCUMENT_NODE].include?(sibling.type)
|
341
|
+
while (sibling = sibling.next_sibling)
|
342
|
+
return sibling if sibling.element?
|
343
|
+
end
|
344
|
+
nil
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
# :startdoc:
|
351
|
+
|
352
|
+
require 'nokogiri/syntax_error'
|
353
|
+
require 'nokogiri/xml/syntax_error'
|
354
|
+
|
355
|
+
[ "io_callbacks",
|
356
|
+
"encoding_handler",
|
357
|
+
"weak_bucket",
|
358
|
+
"structs/common_node",
|
359
|
+
"structs/xml_alloc",
|
360
|
+
"structs/xml_char_encoding_handler",
|
361
|
+
"structs/xml_document",
|
362
|
+
"structs/xml_node",
|
363
|
+
"structs/xml_dtd",
|
364
|
+
"structs/xml_notation",
|
365
|
+
"structs/xml_node_set",
|
366
|
+
"structs/xml_xpath_context",
|
367
|
+
"structs/xml_xpath_object",
|
368
|
+
"structs/xml_xpath_parser_context",
|
369
|
+
"structs/xml_buffer",
|
370
|
+
"structs/xml_syntax_error",
|
371
|
+
"structs/xml_attr",
|
372
|
+
"structs/xml_ns",
|
373
|
+
"structs/xml_schema",
|
374
|
+
"structs/xml_relax_ng",
|
375
|
+
"structs/xml_text_reader",
|
376
|
+
"structs/xml_sax_handler",
|
377
|
+
"structs/xml_sax_push_parser_context",
|
378
|
+
"structs/xml_enumeration",
|
379
|
+
"structs/html_elem_desc",
|
380
|
+
"structs/html_entity_desc",
|
381
|
+
"structs/xslt_stylesheet",
|
382
|
+
"structs/xml_parser_context",
|
383
|
+
"structs/xml_attribute",
|
384
|
+
"structs/xml_element",
|
385
|
+
"structs/xml_entity",
|
386
|
+
"structs/xml_element_content",
|
387
|
+
"structs/xml_parser_input",
|
388
|
+
"xml/node",
|
389
|
+
"xml/namespace",
|
390
|
+
"xml/dtd",
|
391
|
+
"xml/attr",
|
392
|
+
"xml/attribute_decl",
|
393
|
+
"xml/element_decl",
|
394
|
+
"xml/element_content",
|
395
|
+
"xml/entity_decl",
|
396
|
+
"xml/document",
|
397
|
+
"xml/document_fragment",
|
398
|
+
"xml/schema",
|
399
|
+
"xml/relax_ng",
|
400
|
+
"xml/text",
|
401
|
+
"xml/cdata",
|
402
|
+
"xml/comment",
|
403
|
+
"xml/processing_instruction",
|
404
|
+
"xml/node_set",
|
405
|
+
"xml/xpath",
|
406
|
+
"xml/xpath_context",
|
407
|
+
"xml/syntax_error",
|
408
|
+
"xml/reader",
|
409
|
+
"xml/entity_reference",
|
410
|
+
"xml/sax/parser_context",
|
411
|
+
"xml/sax/parser",
|
412
|
+
"xml/sax/push_parser",
|
413
|
+
"html/document",
|
414
|
+
"html/element_description",
|
415
|
+
"html/entity_lookup",
|
416
|
+
"html/sax/parser_context",
|
417
|
+
"xslt/stylesheet",
|
418
|
+
].each do |file|
|
419
|
+
require "nokogiri/ffi/#{file}"
|
420
|
+
end
|