caring-nokogiri 1.4.1.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +27 -0
- data/CHANGELOG.ja.rdoc +330 -0
- data/CHANGELOG.rdoc +324 -0
- data/Manifest.txt +269 -0
- data/README.ja.rdoc +105 -0
- data/README.rdoc +118 -0
- data/Rakefile +248 -0
- data/bin/nokogiri +49 -0
- data/ext/nokogiri/extconf.rb +147 -0
- data/ext/nokogiri/html_document.c +145 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +272 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +32 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser_context.c +92 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/nokogiri.c +95 -0
- data/ext/nokogiri/nokogiri.h +145 -0
- data/ext/nokogiri/xml_attr.c +92 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +67 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +54 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +52 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +388 -0
- data/ext/nokogiri/xml_document.h +24 -0
- data/ext/nokogiri/xml_document_fragment.c +46 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +192 -0
- data/ext/nokogiri/xml_dtd.h +10 -0
- 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_entity_decl.c +97 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +50 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +31 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_namespace.c +74 -0
- data/ext/nokogiri/xml_namespace.h +12 -0
- data/ext/nokogiri/xml_node.c +1060 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +397 -0
- data/ext/nokogiri/xml_node_set.h +9 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +593 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +159 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +286 -0
- data/ext/nokogiri/xml_sax_parser.h +43 -0
- data/ext/nokogiri/xml_sax_parser_context.c +155 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +91 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +156 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +261 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +48 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath.c +53 -0
- data/ext/nokogiri/xml_xpath.h +11 -0
- data/ext/nokogiri/xml_xpath_context.c +239 -0
- data/ext/nokogiri/xml_xpath_context.h +9 -0
- data/ext/nokogiri/xslt_stylesheet.c +131 -0
- data/ext/nokogiri/xslt_stylesheet.h +9 -0
- data/lib/nokogiri.rb +116 -0
- data/lib/nokogiri/css.rb +25 -0
- data/lib/nokogiri/css/generated_parser.rb +646 -0
- data/lib/nokogiri/css/generated_tokenizer.rb +143 -0
- data/lib/nokogiri/css/node.rb +99 -0
- data/lib/nokogiri/css/parser.rb +82 -0
- data/lib/nokogiri/css/parser.y +227 -0
- data/lib/nokogiri/css/syntax_error.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rex +54 -0
- data/lib/nokogiri/css/xpath_visitor.rb +162 -0
- data/lib/nokogiri/decorators/slop.rb +33 -0
- data/lib/nokogiri/ffi/html/document.rb +28 -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_context.rb +38 -0
- data/lib/nokogiri/ffi/io_callbacks.rb +42 -0
- data/lib/nokogiri/ffi/libxml.rb +356 -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_attribute.rb +27 -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 +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 +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 +15 -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/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 +135 -0
- data/lib/nokogiri/ffi/xml/document_fragment.rb +21 -0
- data/lib/nokogiri/ffi/xml/dtd.rb +69 -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 +27 -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 +444 -0
- data/lib/nokogiri/ffi/xml/node_set.rb +133 -0
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
- data/lib/nokogiri/ffi/xml/reader.rb +227 -0
- data/lib/nokogiri/ffi/xml/relax_ng.rb +85 -0
- data/lib/nokogiri/ffi/xml/sax/parser.rb +142 -0
- data/lib/nokogiri/ffi/xml/sax/parser_context.rb +67 -0
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +39 -0
- data/lib/nokogiri/ffi/xml/schema.rb +92 -0
- data/lib/nokogiri/ffi/xml/syntax_error.rb +91 -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/html.rb +35 -0
- data/lib/nokogiri/html/builder.rb +35 -0
- data/lib/nokogiri/html/document.rb +88 -0
- 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 +13 -0
- data/lib/nokogiri/html/sax/parser.rb +48 -0
- data/lib/nokogiri/html/sax/parser_context.rb +16 -0
- data/lib/nokogiri/syntax_error.rb +4 -0
- data/lib/nokogiri/version.rb +33 -0
- data/lib/nokogiri/version_warning.rb +11 -0
- data/lib/nokogiri/xml.rb +67 -0
- data/lib/nokogiri/xml/attr.rb +14 -0
- data/lib/nokogiri/xml/attribute_decl.rb +18 -0
- data/lib/nokogiri/xml/builder.rb +405 -0
- data/lib/nokogiri/xml/cdata.rb +11 -0
- data/lib/nokogiri/xml/character_data.rb +7 -0
- data/lib/nokogiri/xml/document.rb +131 -0
- data/lib/nokogiri/xml/document_fragment.rb +73 -0
- data/lib/nokogiri/xml/dtd.rb +11 -0
- 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 +15 -0
- data/lib/nokogiri/xml/fragment_handler.rb +73 -0
- data/lib/nokogiri/xml/namespace.rb +13 -0
- data/lib/nokogiri/xml/node.rb +665 -0
- data/lib/nokogiri/xml/node/save_options.rb +42 -0
- data/lib/nokogiri/xml/node_set.rb +307 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/parse_options.rb +85 -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 +8 -0
- data/lib/nokogiri/xml/reader.rb +74 -0
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +4 -0
- data/lib/nokogiri/xml/sax/document.rb +160 -0
- data/lib/nokogiri/xml/sax/parser.rb +115 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
- data/lib/nokogiri/xml/schema.rb +61 -0
- data/lib/nokogiri/xml/syntax_error.rb +38 -0
- data/lib/nokogiri/xml/xpath.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +8 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xslt.rb +48 -0
- data/lib/nokogiri/xslt/stylesheet.rb +25 -0
- data/lib/xsd/xmlparser/nokogiri.rb +71 -0
- data/tasks/test.rb +100 -0
- data/test/css/test_nthiness.rb +159 -0
- data/test/css/test_parser.rb +277 -0
- data/test/css/test_tokenizer.rb +183 -0
- data/test/css/test_xpath_visitor.rb +76 -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/dont_hurt_em_why.xml +422 -0
- data/test/files/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -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/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/files/valid_bar.xml +2 -0
- data/test/helper.rb +136 -0
- data/test/html/sax/test_parser.rb +64 -0
- data/test/html/sax/test_parser_context.rb +48 -0
- data/test/html/test_builder.rb +164 -0
- data/test/html/test_document.rb +390 -0
- data/test/html/test_document_encoding.rb +77 -0
- data/test/html/test_document_fragment.rb +142 -0
- data/test/html/test_element_description.rb +94 -0
- data/test/html/test_named_characters.rb +14 -0
- data/test/html/test_node.rb +228 -0
- data/test/html/test_node_encoding.rb +27 -0
- data/test/test_convert_xpath.rb +135 -0
- data/test/test_css_cache.rb +45 -0
- data/test/test_gc.rb +15 -0
- data/test/test_memory_leak.rb +77 -0
- data/test/test_nokogiri.rb +138 -0
- data/test/test_reader.rb +358 -0
- data/test/test_xslt_transforms.rb +131 -0
- data/test/xml/node/test_save_options.rb +20 -0
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +307 -0
- data/test/xml/sax/test_parser_context.rb +56 -0
- data/test/xml/sax/test_push_parser.rb +106 -0
- data/test/xml/test_attr.rb +38 -0
- data/test/xml/test_attribute_decl.rb +82 -0
- data/test/xml/test_builder.rb +167 -0
- data/test/xml/test_cdata.rb +38 -0
- data/test/xml/test_comment.rb +29 -0
- data/test/xml/test_document.rb +607 -0
- data/test/xml/test_document_encoding.rb +26 -0
- data/test/xml/test_document_fragment.rb +144 -0
- data/test/xml/test_dtd.rb +82 -0
- data/test/xml/test_dtd_encoding.rb +33 -0
- 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 +83 -0
- data/test/xml/test_entity_reference.rb +21 -0
- data/test/xml/test_namespace.rb +68 -0
- data/test/xml/test_node.rb +889 -0
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +107 -0
- data/test/xml/test_node_set.rb +531 -0
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +30 -0
- data/test/xml/test_reader_encoding.rb +126 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +89 -0
- data/test/xml/test_syntax_error.rb +27 -0
- data/test/xml/test_text.rb +30 -0
- data/test/xml/test_unparented_node.rb +381 -0
- data/test/xml/test_xpath.rb +106 -0
- metadata +428 -0
@@ -0,0 +1,356 @@
|
|
1
|
+
# :stopdoc:
|
2
|
+
module Nokogiri
|
3
|
+
module LibXML
|
4
|
+
extend FFI::Library
|
5
|
+
if RUBY_PLATFORM =~ /java/ && java.lang.System.getProperty('os.name') =~ /windows/i
|
6
|
+
raise(RuntimeError, "Nokogiri requires JRuby 1.4.0RC1 or later on Windows") if JRUBY_VERSION < "1.4.0RC1"
|
7
|
+
ffi_lib 'libxml2', 'libxslt', 'libexslt', 'msvcrt'
|
8
|
+
else
|
9
|
+
ffi_lib 'xml2', 'xslt', 'exslt'
|
10
|
+
end
|
11
|
+
|
12
|
+
# globals.c
|
13
|
+
attach_function :__xmlParserVersion, [], :pointer
|
14
|
+
attach_function :__xmlIndentTreeOutput, [], :pointer
|
15
|
+
attach_function :__xmlTreeIndentString, [], :pointer
|
16
|
+
attach_function :xmlDeregisterNodeDefault, [:pointer], :pointer
|
17
|
+
end
|
18
|
+
|
19
|
+
LIBXML_PARSER_VERSION = LibXML.__xmlParserVersion().read_pointer.read_string
|
20
|
+
LIBXML_VERSION = LIBXML_PARSER_VERSION.scan(/^(.*)(..)(..)$/).first.collect{|j|j.to_i}.join(".")
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'nokogiri/version'
|
24
|
+
|
25
|
+
Nokogiri::VERSION_INFO['libxml'] = {}
|
26
|
+
Nokogiri::VERSION_INFO['libxml']['loaded'] = Nokogiri::LIBXML_VERSION
|
27
|
+
Nokogiri::VERSION_INFO['libxml']['binding'] = 'ffi'
|
28
|
+
if RUBY_PLATFORM =~ /java/
|
29
|
+
Nokogiri::VERSION_INFO['libxml']['platform'] = 'jruby'
|
30
|
+
raise(RuntimeError, "Nokogiri requires JRuby 1.3.0 or later") if JRUBY_VERSION < "1.3.0"
|
31
|
+
else
|
32
|
+
Nokogiri::VERSION_INFO['libxml']['platform'] = 'ruby'
|
33
|
+
end
|
34
|
+
|
35
|
+
module Nokogiri
|
36
|
+
module LibXML
|
37
|
+
XML_CHAR_ENCODING_ERROR = -1
|
38
|
+
|
39
|
+
# useful callback signatures
|
40
|
+
callback :syntax_error_handler, [:pointer, :pointer], :void
|
41
|
+
callback :generic_error_handler, [:pointer, :string], :void
|
42
|
+
callback :io_write_callback, [:pointer, :string, :int], :int
|
43
|
+
callback :io_read_callback, [:pointer, :pointer, :int], :int
|
44
|
+
callback :io_close_callback, [:pointer], :int
|
45
|
+
callback :hash_copier_callback, [:pointer, :pointer, :string], :void
|
46
|
+
callback :xpath_callback, [:pointer, :int], :void
|
47
|
+
callback :xpath_lookup_callback, [:pointer, :string, :pointer], :xpath_callback
|
48
|
+
callback :start_document_sax_func, [:pointer], :void
|
49
|
+
callback :end_document_sax_func, [:pointer], :void
|
50
|
+
callback :start_element_sax_func, [:pointer, :string, :pointer], :void
|
51
|
+
callback :end_element_sax_func, [:pointer, :string], :void
|
52
|
+
callback :characters_sax_func, [:pointer, :string, :int], :void
|
53
|
+
callback :comment_sax_func, [:pointer, :string], :void
|
54
|
+
callback :warning_sax_func, [:pointer, :string], :void
|
55
|
+
callback :error_sax_func, [:pointer, :string], :void
|
56
|
+
callback :cdata_block_sax_func, [:pointer, :string, :int], :void
|
57
|
+
callback :start_element_ns_sax2_func, [:pointer, :pointer, :pointer, :pointer, :int, :pointer, :int, :int, :pointer], :void
|
58
|
+
callback :end_element_ns_sax2_func, [:pointer, :pointer, :pointer, :pointer], :void
|
59
|
+
|
60
|
+
# HTMLparser.c
|
61
|
+
attach_function :htmlReadMemory, [:string, :int, :string, :string, :int], :pointer
|
62
|
+
attach_function :htmlReadIO, [:io_read_callback, :io_close_callback, :pointer, :string, :string, :int], :pointer
|
63
|
+
attach_function :htmlNewDoc, [:string, :string], :pointer
|
64
|
+
attach_function :htmlTagLookup, [:string], :pointer
|
65
|
+
attach_function :htmlEntityLookup, [:string], :pointer
|
66
|
+
attach_function :htmlSAXParseFile, [:string, :pointer, :pointer, :pointer], :pointer # second arg 'encoding' should be a string, but we assign it as a pointer elsewhere
|
67
|
+
attach_function :htmlSAXParseDoc, [:pointer, :pointer, :pointer, :pointer], :pointer # second arg 'encoding' should be a string, but we assign it as a pointer elsewhere
|
68
|
+
attach_function :htmlCreateMemoryParserCtxt, [:pointer, :int], :pointer
|
69
|
+
attach_function :htmlCreateFileParserCtxt, [:pointer, :pointer], :pointer
|
70
|
+
attach_function :htmlParseDocument, [:pointer], :int
|
71
|
+
|
72
|
+
# HTMLtree.c
|
73
|
+
attach_function :htmlDocDumpMemory, [:pointer, :pointer, :pointer], :void
|
74
|
+
attach_function :htmlNodeDump, [:pointer, :pointer, :pointer], :int
|
75
|
+
attach_function :htmlGetMetaEncoding, [:pointer], :string # returns const char*
|
76
|
+
attach_function :htmlSetMetaEncoding, [:pointer, :string], :void
|
77
|
+
|
78
|
+
# parser.c
|
79
|
+
attach_function :xmlReadMemory, [:string, :int, :string, :string, :int], :pointer
|
80
|
+
attach_function :xmlInitParser, [], :void
|
81
|
+
attach_function :xmlReadIO, [:io_read_callback, :io_close_callback, :pointer, :string, :string, :int], :pointer
|
82
|
+
attach_function :xmlCreateIOParserCtxt, [:pointer, :pointer, :io_read_callback, :io_close_callback, :pointer, :int], :pointer
|
83
|
+
attach_function :xmlCreateMemoryParserCtxt, [:pointer, :int], :pointer
|
84
|
+
attach_function :xmlCreateFileParserCtxt, [:pointer], :pointer
|
85
|
+
attach_function :xmlSAXUserParseMemory, [:pointer, :pointer, :string, :int], :int
|
86
|
+
attach_function :xmlSAXUserParseFile, [:pointer, :pointer, :string], :int
|
87
|
+
attach_function :xmlParseDocument, [:pointer], :int
|
88
|
+
attach_function :xmlFreeParserCtxt, [:pointer], :void
|
89
|
+
attach_function :xmlCreatePushParserCtxt, [:pointer, :pointer, :string, :int, :string], :pointer
|
90
|
+
attach_function :xmlParseChunk, [:pointer, :string, :int, :int], :int
|
91
|
+
|
92
|
+
# tree.c
|
93
|
+
attach_function :xmlNewDoc, [:string], :pointer
|
94
|
+
attach_function :xmlNewDocFragment, [:pointer], :pointer
|
95
|
+
attach_function :xmlDocGetRootElement, [:pointer], :pointer
|
96
|
+
attach_function :xmlDocSetRootElement, [:pointer, :pointer], :pointer
|
97
|
+
attach_function :xmlCopyDoc, [:pointer, :int], :pointer
|
98
|
+
attach_function :xmlFreeDoc, [:pointer], :void
|
99
|
+
attach_function :xmlSetTreeDoc, [:pointer, :pointer], :void
|
100
|
+
attach_function :xmlNewReference, [:pointer, :string], :pointer
|
101
|
+
attach_function :xmlNewNode, [:pointer, :string], :pointer
|
102
|
+
attach_function :xmlCopyNode, [:pointer, :int], :pointer
|
103
|
+
attach_function :xmlDocCopyNode, [:pointer, :pointer, :int], :pointer
|
104
|
+
attach_function :xmlReplaceNode, [:pointer, :pointer], :pointer
|
105
|
+
attach_function :xmlUnlinkNode, [:pointer], :void
|
106
|
+
attach_function :xmlAddChild, [:pointer, :pointer], :pointer
|
107
|
+
attach_function :xmlAddNextSibling, [:pointer, :pointer], :pointer
|
108
|
+
attach_function :xmlAddPrevSibling, [:pointer, :pointer], :pointer
|
109
|
+
attach_function :xmlIsBlankNode, [:pointer], :int
|
110
|
+
attach_function :xmlHasProp, [:pointer, :string], :pointer
|
111
|
+
attach_function :xmlHasNsProp, [:pointer, :string, :string], :pointer
|
112
|
+
attach_function :xmlGetProp, [:pointer, :string], :pointer # returns char* that must be freed
|
113
|
+
attach_function :xmlSetProp, [:pointer, :string, :string], :pointer
|
114
|
+
attach_function :xmlRemoveProp, [:pointer], :int
|
115
|
+
attach_function :xmlNodeSetContent, [:pointer, :string], :void
|
116
|
+
attach_function :xmlNodeGetContent, [:pointer], :pointer # returns char* that must be freed
|
117
|
+
attach_function :xmlNodeSetName, [:pointer, :string], :void
|
118
|
+
attach_function :xmlGetNodePath, [:pointer], :pointer
|
119
|
+
attach_function :xmlNewCDataBlock, [:pointer, :string, :int], :pointer
|
120
|
+
attach_function :xmlNewDocComment, [:pointer, :string], :pointer
|
121
|
+
attach_function :xmlNewDocPI, [:pointer, :string, :string], :pointer
|
122
|
+
attach_function :xmlNewText, [:string], :pointer
|
123
|
+
attach_function :xmlFreeNode, [:pointer], :void
|
124
|
+
attach_function :xmlFreeNodeList, [:pointer], :void
|
125
|
+
attach_function :xmlEncodeEntitiesReentrant, [:pointer, :string], :pointer # returns char* that must be freed
|
126
|
+
attach_function :xmlStringGetNodeList, [:pointer, :pointer], :pointer # second arg should be a :string, but we only ship the results of xmlEncodeEntitiesReentrant, so let's optimize.
|
127
|
+
attach_function :xmlNewNs, [:pointer, :string, :string], :pointer
|
128
|
+
attach_function :xmlNewNsProp, [:pointer, :pointer, :string, :string], :pointer
|
129
|
+
attach_function :xmlSearchNs, [:pointer, :pointer, :string], :pointer
|
130
|
+
attach_function :xmlSearchNsByHref, [:pointer, :pointer, :string], :pointer
|
131
|
+
attach_function :xmlGetIntSubset, [:pointer], :pointer
|
132
|
+
attach_function :xmlBufferCreate, [], :pointer
|
133
|
+
attach_function :xmlBufferFree, [:pointer], :void
|
134
|
+
attach_function :xmlSplitQName2, [:string, :pointer], :pointer # returns char* that must be freed
|
135
|
+
attach_function :xmlNewDocProp, [:pointer, :string, :string], :pointer
|
136
|
+
attach_function :xmlFreePropList, [:pointer], :void
|
137
|
+
attach_function :xmlCreateIntSubset, [:pointer] * 4, :pointer
|
138
|
+
attach_function :xmlNewDtd, [:pointer] * 4, :pointer
|
139
|
+
|
140
|
+
# valid.c
|
141
|
+
attach_function :xmlNewValidCtxt, [], :pointer
|
142
|
+
attach_function :xmlValidateDtd, [:pointer, :pointer, :pointer], :int
|
143
|
+
attach_function :xmlFreeValidCtxt, [:pointer], :void
|
144
|
+
|
145
|
+
# xmlsave.c
|
146
|
+
attach_function :xmlDocDumpMemory, [:pointer, :pointer, :pointer], :void
|
147
|
+
attach_function :xmlNodeDump, [:pointer, :pointer, :pointer, :int, :int], :int
|
148
|
+
attach_function :xmlSaveToIO, [:io_write_callback, :io_close_callback, :pointer, :string, :int], :pointer
|
149
|
+
attach_function :xmlSaveTree, [:pointer, :pointer], :int
|
150
|
+
attach_function :xmlSaveClose, [:pointer], :int
|
151
|
+
attach_function :xmlSetNs, [:pointer, :pointer], :void
|
152
|
+
|
153
|
+
# entities.c
|
154
|
+
attach_function :xmlEncodeSpecialChars, [:pointer, :string], :pointer # returns char* that must be freed
|
155
|
+
|
156
|
+
# xpath.c
|
157
|
+
attach_function :xmlXPathInit, [], :void
|
158
|
+
attach_function :xmlXPathNewContext, [:pointer], :pointer
|
159
|
+
attach_function :xmlXPathFreeContext, [:pointer], :void
|
160
|
+
attach_function :xmlXPathEvalExpression, [:string, :pointer], :pointer
|
161
|
+
attach_function :xmlXPathRegisterNs, [:pointer, :string, :string], :int
|
162
|
+
attach_function :xmlXPathCmpNodes, [:pointer, :pointer], :int
|
163
|
+
attach_function :xmlXPathNodeSetContains, [:pointer, :pointer], :int
|
164
|
+
attach_function :xmlXPathNodeSetAdd, [:pointer, :pointer], :void
|
165
|
+
attach_function :xmlXPathNodeSetRemove, [:pointer, :int], :void
|
166
|
+
attach_function :xmlXPathNodeSetCreate, [:pointer], :pointer
|
167
|
+
attach_function :xmlXPathNodeSetDel, [:pointer, :pointer], :void
|
168
|
+
attach_function :xmlXPathIntersection, [:pointer, :pointer], :pointer
|
169
|
+
attach_function :xmlXPathFreeNodeSetList, [:pointer], :void
|
170
|
+
attach_function :xmlXPathRegisterFuncLookup, [:pointer, :xpath_lookup_callback, :pointer], :void
|
171
|
+
attach_function :valuePop, [:pointer], :pointer
|
172
|
+
attach_function :valuePush, [:pointer, :pointer], :int
|
173
|
+
attach_function :xmlXPathCastToString, [:pointer], :pointer # returns char* that must be freed
|
174
|
+
attach_function :xmlXPathNodeSetMerge, [:pointer, :pointer], :pointer
|
175
|
+
attach_function :xmlXPathWrapNodeSet, [:pointer], :pointer
|
176
|
+
attach_function :xmlXPathWrapCString, [:pointer], :pointer # should take a :string, but we optimize
|
177
|
+
attach_function :xmlXPathWrapString, [:pointer], :pointer # should take a :string, but we optimize
|
178
|
+
attach_function :xmlXPathNewBoolean, [:int], :pointer
|
179
|
+
attach_function :xmlXPathNewFloat, [:double], :pointer
|
180
|
+
|
181
|
+
class << self
|
182
|
+
# these functions are implemented as C macros
|
183
|
+
def xmlXPathReturnNodeSet(ctx, ns)
|
184
|
+
valuePush(ctx, xmlXPathWrapNodeSet(ns))
|
185
|
+
end
|
186
|
+
def xmlXPathReturnTrue(ctx)
|
187
|
+
valuePush(ctx, xmlXPathNewBoolean(1))
|
188
|
+
end
|
189
|
+
def xmlXPathReturnFalse(ctx)
|
190
|
+
valuePush(ctx, xmlXPathNewBoolean(0))
|
191
|
+
end
|
192
|
+
def xmlXPathReturnString(ctx, str)
|
193
|
+
valuePush(ctx, xmlXPathWrapString(str))
|
194
|
+
end
|
195
|
+
def xmlXPathReturnNumber(ctx, val)
|
196
|
+
valuePush(ctx, xmlXPathNewFloat(val))
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
# xmlstring.c
|
201
|
+
attach_function :xmlStrdup, [:string], :pointer # returns char* that must be freed
|
202
|
+
def self.xmlFree(pointer)
|
203
|
+
# xmlFree is a C preprocessor macro, not an actual function
|
204
|
+
self.free(pointer)
|
205
|
+
end
|
206
|
+
|
207
|
+
# error.c
|
208
|
+
attach_function :xmlSetStructuredErrorFunc, [:pointer, :syntax_error_handler], :void
|
209
|
+
attach_function :xmlSetGenericErrorFunc, [:pointer, :generic_error_handler], :void
|
210
|
+
attach_function :xmlResetLastError, [], :void
|
211
|
+
attach_function :xmlCopyError, [:pointer, :pointer], :int
|
212
|
+
attach_function :xmlGetLastError, [], :pointer
|
213
|
+
attach_function :xmlCtxtGetLastError, [:pointer], :pointer
|
214
|
+
|
215
|
+
# hash.c
|
216
|
+
attach_function :xmlHashScan, [:pointer, :hash_copier_callback, :pointer], :void
|
217
|
+
|
218
|
+
# xmlreader.c
|
219
|
+
attach_function :xmlReaderForMemory, [:pointer, :int, :string, :string, :int], :pointer
|
220
|
+
attach_function :xmlTextReaderGetAttribute, [:pointer, :string], :pointer # returns char* that must be freed
|
221
|
+
attach_function :xmlTextReaderGetAttributeNo, [:pointer, :int], :pointer # returns char* that must be freed
|
222
|
+
attach_function :xmlTextReaderLookupNamespace, [:pointer, :string], :pointer # returns char* that must be freed
|
223
|
+
attach_function :xmlTextReaderRead, [:pointer], :int
|
224
|
+
attach_function :xmlTextReaderReadInnerXml, [:pointer], :pointer
|
225
|
+
attach_function :xmlTextReaderReadOuterXml, [:pointer], :pointer
|
226
|
+
attach_function :xmlTextReaderAttributeCount, [:pointer], :int
|
227
|
+
attach_function :xmlTextReaderCurrentNode, [:pointer], :pointer
|
228
|
+
attach_function :xmlTextReaderExpand, [:pointer], :pointer
|
229
|
+
attach_function :xmlTextReaderIsDefault, [:pointer], :int
|
230
|
+
attach_function :xmlTextReaderDepth, [:pointer], :int
|
231
|
+
attach_function :xmlTextReaderConstXmlLang, [:pointer], :pointer # returns a const char*, but must check for null
|
232
|
+
attach_function :xmlTextReaderConstLocalName, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
233
|
+
attach_function :xmlTextReaderConstName, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
234
|
+
attach_function :xmlTextReaderConstNamespaceUri, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
235
|
+
attach_function :xmlTextReaderConstPrefix, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
236
|
+
attach_function :xmlTextReaderConstValue, [:pointer], :pointer # returns a const char* that is deallocated on the next read()
|
237
|
+
attach_function :xmlTextReaderConstXmlVersion, [:pointer], :pointer # returns a const char* that is deallocated with the reader
|
238
|
+
attach_function :xmlTextReaderReadState, [:pointer], :int
|
239
|
+
attach_function :xmlTextReaderHasValue, [:pointer], :int
|
240
|
+
attach_function :xmlFreeTextReader, [:pointer], :void
|
241
|
+
attach_function :xmlReaderForIO, [:io_read_callback, :io_close_callback, :pointer, :string, :string, :int], :pointer
|
242
|
+
attach_function :xmlTextReaderNodeType, [:pointer], :int
|
243
|
+
|
244
|
+
# xslt.c
|
245
|
+
attach_function :xsltParseStylesheetDoc, [:pointer], :pointer
|
246
|
+
attach_function :xsltFreeStylesheet, [:pointer], :void
|
247
|
+
attach_function :xsltApplyStylesheet, [:pointer, :pointer, :pointer], :pointer
|
248
|
+
attach_function :xsltSaveResultToString, [:pointer, :pointer, :pointer, :pointer], :int
|
249
|
+
attach_function :xsltSetGenericErrorFunc, [:pointer, :generic_error_handler], :void
|
250
|
+
|
251
|
+
# exslt.c
|
252
|
+
attach_function :exsltRegisterAll, [], :void
|
253
|
+
|
254
|
+
# xmlschemas.c
|
255
|
+
attach_function :xmlSchemaNewValidCtxt, [:pointer], :pointer
|
256
|
+
attach_function :xmlSchemaSetValidStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
257
|
+
attach_function :xmlSchemaValidateDoc, [:pointer, :pointer], :void
|
258
|
+
attach_function :xmlSchemaFreeValidCtxt, [:pointer], :void
|
259
|
+
attach_function :xmlSchemaNewMemParserCtxt, [:pointer, :int], :pointer # first arg could be string, but we pass length, so let's optimize
|
260
|
+
attach_function :xmlSchemaSetParserStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
261
|
+
attach_function :xmlSchemaParse, [:pointer], :pointer
|
262
|
+
attach_function :xmlSchemaFreeParserCtxt, [:pointer], :void
|
263
|
+
attach_function :xmlSchemaNewDocParserCtxt, [:pointer], :pointer
|
264
|
+
|
265
|
+
# relaxng.c
|
266
|
+
attach_function :xmlRelaxNGNewValidCtxt, [:pointer], :pointer
|
267
|
+
attach_function :xmlRelaxNGSetValidStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
268
|
+
attach_function :xmlRelaxNGValidateDoc, [:pointer, :pointer], :int
|
269
|
+
attach_function :xmlRelaxNGFreeValidCtxt, [:pointer], :void
|
270
|
+
attach_function :xmlRelaxNGNewMemParserCtxt, [:pointer, :int], :pointer # first arg could be string, but we pass length, so let's optimize
|
271
|
+
attach_function :xmlRelaxNGSetParserStructuredErrors, [:pointer, :syntax_error_handler, :pointer], :void unless Nokogiri.is_2_6_16?
|
272
|
+
attach_function :xmlRelaxNGParse, [:pointer], :pointer
|
273
|
+
attach_function :xmlRelaxNGFreeParserCtxt, [:pointer], :void
|
274
|
+
attach_function :xmlRelaxNGNewDocParserCtxt, [:pointer], :pointer
|
275
|
+
|
276
|
+
# libc
|
277
|
+
attach_function :calloc, [:int, :int], :pointer
|
278
|
+
attach_function :free, [:pointer], :void
|
279
|
+
|
280
|
+
attach_function :xmlParseCharEncoding, [:string], :int
|
281
|
+
attach_function :xmlSwitchEncoding, [:pointer, :int], :void
|
282
|
+
|
283
|
+
# helpers
|
284
|
+
def self.pointer_offset(n)
|
285
|
+
n * FFI.type_size(:pointer) # byte offset of nth pointer in an array of pointers
|
286
|
+
end
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
# :startdoc:
|
291
|
+
|
292
|
+
require 'nokogiri/syntax_error'
|
293
|
+
require 'nokogiri/xml/syntax_error'
|
294
|
+
|
295
|
+
[ "io_callbacks",
|
296
|
+
"structs/common_node",
|
297
|
+
"structs/xml_alloc",
|
298
|
+
"structs/xml_document",
|
299
|
+
"structs/xml_node",
|
300
|
+
"structs/xml_dtd",
|
301
|
+
"structs/xml_notation",
|
302
|
+
"structs/xml_node_set",
|
303
|
+
"structs/xml_xpath_context",
|
304
|
+
"structs/xml_xpath_object",
|
305
|
+
"structs/xml_xpath_parser_context",
|
306
|
+
"structs/xml_buffer",
|
307
|
+
"structs/xml_syntax_error",
|
308
|
+
"structs/xml_attr",
|
309
|
+
"structs/xml_ns",
|
310
|
+
"structs/xml_schema",
|
311
|
+
"structs/xml_relax_ng",
|
312
|
+
"structs/xml_text_reader",
|
313
|
+
"structs/xml_sax_handler",
|
314
|
+
"structs/xml_sax_push_parser_context",
|
315
|
+
"structs/xml_enumeration",
|
316
|
+
"structs/html_elem_desc",
|
317
|
+
"structs/html_entity_desc",
|
318
|
+
"structs/xslt_stylesheet",
|
319
|
+
"structs/xml_parser_context",
|
320
|
+
"structs/xml_attribute",
|
321
|
+
"structs/xml_element",
|
322
|
+
"structs/xml_entity",
|
323
|
+
"structs/xml_element_content",
|
324
|
+
"xml/node",
|
325
|
+
"xml/namespace",
|
326
|
+
"xml/dtd",
|
327
|
+
"xml/attr",
|
328
|
+
"xml/attribute_decl",
|
329
|
+
"xml/element_decl",
|
330
|
+
"xml/element_content",
|
331
|
+
"xml/entity_decl",
|
332
|
+
"xml/document",
|
333
|
+
"xml/document_fragment",
|
334
|
+
"xml/schema",
|
335
|
+
"xml/relax_ng",
|
336
|
+
"xml/text",
|
337
|
+
"xml/cdata",
|
338
|
+
"xml/comment",
|
339
|
+
"xml/processing_instruction",
|
340
|
+
"xml/node_set",
|
341
|
+
"xml/xpath",
|
342
|
+
"xml/xpath_context",
|
343
|
+
"xml/syntax_error",
|
344
|
+
"xml/reader",
|
345
|
+
"xml/entity_reference",
|
346
|
+
"xml/sax/parser_context",
|
347
|
+
"xml/sax/parser",
|
348
|
+
"xml/sax/push_parser",
|
349
|
+
"html/document",
|
350
|
+
"html/element_description",
|
351
|
+
"html/entity_lookup",
|
352
|
+
"html/sax/parser_context",
|
353
|
+
"xslt/stylesheet",
|
354
|
+
].each do |file|
|
355
|
+
require "nokogiri/ffi/#{file}"
|
356
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module LibXML # :nodoc:
|
3
|
+
module CommonNode # :nodoc:
|
4
|
+
|
5
|
+
def document
|
6
|
+
p = self[:doc]
|
7
|
+
p.null? ? nil : LibXML::XmlDocumentCast.new(p)
|
8
|
+
end
|
9
|
+
|
10
|
+
def ruby_node
|
11
|
+
self[:_private] != 0 ? ObjectSpace._id2ref(self[:_private]) : nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def ruby_node= object
|
15
|
+
self[:_private] = object.object_id
|
16
|
+
end
|
17
|
+
|
18
|
+
def keep_reference_from_document! # equivalent to NOKOGIRI_ROOT_NODE
|
19
|
+
doc = self.document
|
20
|
+
raise "no document to add reference to" unless doc
|
21
|
+
LibXML.xmlXPathNodeSetAdd(doc.unlinked_nodes, self)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module LibXML # :nodoc:
|
3
|
+
class HtmlElemDesc < FFI::Struct # :nodoc:
|
4
|
+
|
5
|
+
layout(
|
6
|
+
:name, :string,
|
7
|
+
:startTag, :char,
|
8
|
+
:endTag, :char,
|
9
|
+
:saveEndTag, :char,
|
10
|
+
:empty, :char,
|
11
|
+
:depr, :char,
|
12
|
+
:dtd, :char,
|
13
|
+
:isinline, :char,
|
14
|
+
:desc, :string,
|
15
|
+
:subelts, :pointer,
|
16
|
+
:defaultsubelt, :string,
|
17
|
+
:attrs_opt, :pointer,
|
18
|
+
:attrs_depr, :pointer,
|
19
|
+
:attrs_req, :pointer
|
20
|
+
)
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module LibXML # :nodoc:
|
3
|
+
#
|
4
|
+
# this class only exists to create a xmlFree() finalizer
|
5
|
+
#
|
6
|
+
class XmlAlloc < FFI::ManagedStruct # :nodoc:
|
7
|
+
|
8
|
+
layout :dummy, :int, 0 # to avoid @layout warnings
|
9
|
+
|
10
|
+
def self.release ptr
|
11
|
+
LibXML.xmlFree(ptr)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module LibXML # :nodoc:
|
3
|
+
class XmlAttr < FFI::Struct # :nodoc:
|
4
|
+
|
5
|
+
layout(
|
6
|
+
:_private, :pointer,
|
7
|
+
:type, :int,
|
8
|
+
:name, :string,
|
9
|
+
:children, :pointer,
|
10
|
+
:last, :pointer,
|
11
|
+
:parent, :pointer,
|
12
|
+
:next, :pointer,
|
13
|
+
:prev, :pointer,
|
14
|
+
:doc, :pointer
|
15
|
+
)
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|