nokogiri 1.8.5 → 1.15.3
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.
- checksums.yaml +4 -4
- data/Gemfile +40 -18
- data/LICENSE-DEPENDENCIES.md +1636 -1024
- data/LICENSE.md +5 -28
- data/README.md +203 -90
- data/bin/nokogiri +63 -50
- data/dependencies.yml +33 -61
- data/ext/nokogiri/depend +38 -358
- data/ext/nokogiri/extconf.rb +867 -417
- data/ext/nokogiri/gumbo.c +594 -0
- data/ext/nokogiri/html4_document.c +165 -0
- data/ext/nokogiri/html4_element_description.c +299 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser_context.c +108 -0
- data/ext/nokogiri/html4_sax_push_parser.c +95 -0
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +251 -105
- data/ext/nokogiri/nokogiri.h +215 -90
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +42 -37
- data/ext/nokogiri/xml_attribute_decl.c +22 -22
- data/ext/nokogiri/xml_cdata.c +40 -31
- data/ext/nokogiri/xml_comment.c +20 -27
- data/ext/nokogiri/xml_document.c +401 -237
- data/ext/nokogiri/xml_document_fragment.c +13 -17
- data/ext/nokogiri/xml_dtd.c +64 -58
- data/ext/nokogiri/xml_element_content.c +63 -55
- data/ext/nokogiri/xml_element_decl.c +31 -31
- data/ext/nokogiri/xml_encoding_handler.c +54 -21
- data/ext/nokogiri/xml_entity_decl.c +37 -35
- data/ext/nokogiri/xml_entity_reference.c +17 -19
- data/ext/nokogiri/xml_namespace.c +136 -62
- data/ext/nokogiri/xml_node.c +1387 -678
- data/ext/nokogiri/xml_node_set.c +246 -216
- data/ext/nokogiri/xml_processing_instruction.c +18 -20
- data/ext/nokogiri/xml_reader.c +347 -212
- data/ext/nokogiri/xml_relax_ng.c +86 -77
- data/ext/nokogiri/xml_sax_parser.c +149 -124
- data/ext/nokogiri/xml_sax_parser_context.c +145 -103
- data/ext/nokogiri/xml_sax_push_parser.c +64 -36
- data/ext/nokogiri/xml_schema.c +138 -81
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- data/ext/nokogiri/xml_text.c +36 -26
- data/ext/nokogiri/xml_xpath_context.c +366 -178
- data/ext/nokogiri/xslt_stylesheet.c +335 -189
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +111 -0
- data/gumbo-parser/THANKS +27 -0
- data/gumbo-parser/src/Makefile +34 -0
- data/gumbo-parser/src/README.md +41 -0
- data/gumbo-parser/src/ascii.c +75 -0
- data/gumbo-parser/src/ascii.h +115 -0
- data/gumbo-parser/src/attribute.c +42 -0
- data/gumbo-parser/src/attribute.h +17 -0
- data/gumbo-parser/src/char_ref.c +22225 -0
- data/gumbo-parser/src/char_ref.h +29 -0
- data/gumbo-parser/src/char_ref.rl +2154 -0
- data/gumbo-parser/src/error.c +630 -0
- data/gumbo-parser/src/error.h +148 -0
- data/gumbo-parser/src/foreign_attrs.c +103 -0
- data/gumbo-parser/src/foreign_attrs.gperf +27 -0
- data/gumbo-parser/src/insertion_mode.h +33 -0
- data/gumbo-parser/src/macros.h +91 -0
- data/gumbo-parser/src/nokogiri_gumbo.h +944 -0
- data/gumbo-parser/src/parser.c +4891 -0
- data/gumbo-parser/src/parser.h +41 -0
- data/gumbo-parser/src/replacement.h +33 -0
- data/gumbo-parser/src/string_buffer.c +103 -0
- data/gumbo-parser/src/string_buffer.h +68 -0
- data/gumbo-parser/src/string_piece.c +48 -0
- data/gumbo-parser/src/svg_attrs.c +174 -0
- data/gumbo-parser/src/svg_attrs.gperf +77 -0
- data/gumbo-parser/src/svg_tags.c +137 -0
- data/gumbo-parser/src/svg_tags.gperf +55 -0
- data/gumbo-parser/src/tag.c +223 -0
- data/gumbo-parser/src/tag_lookup.c +382 -0
- data/gumbo-parser/src/tag_lookup.gperf +170 -0
- data/gumbo-parser/src/tag_lookup.h +13 -0
- data/gumbo-parser/src/token_buffer.c +79 -0
- data/gumbo-parser/src/token_buffer.h +71 -0
- data/gumbo-parser/src/token_type.h +17 -0
- data/gumbo-parser/src/tokenizer.c +3463 -0
- data/gumbo-parser/src/tokenizer.h +112 -0
- data/gumbo-parser/src/tokenizer_states.h +339 -0
- data/gumbo-parser/src/utf8.c +245 -0
- data/gumbo-parser/src/utf8.h +164 -0
- data/gumbo-parser/src/util.c +66 -0
- data/gumbo-parser/src/util.h +34 -0
- data/gumbo-parser/src/vector.c +111 -0
- data/gumbo-parser/src/vector.h +45 -0
- data/lib/nokogiri/class_resolver.rb +67 -0
- data/lib/nokogiri/css/node.rb +10 -8
- data/lib/nokogiri/css/parser.rb +397 -377
- data/lib/nokogiri/css/parser.y +250 -245
- data/lib/nokogiri/css/parser_extras.rb +54 -49
- data/lib/nokogiri/css/syntax_error.rb +3 -1
- data/lib/nokogiri/css/tokenizer.rb +107 -104
- data/lib/nokogiri/css/tokenizer.rex +3 -2
- data/lib/nokogiri/css/xpath_visitor.rb +224 -95
- data/lib/nokogiri/css.rb +56 -17
- data/lib/nokogiri/decorators/slop.rb +9 -7
- data/lib/nokogiri/encoding_handler.rb +57 -0
- data/lib/nokogiri/extension.rb +32 -0
- data/lib/nokogiri/gumbo.rb +15 -0
- data/lib/nokogiri/html.rb +38 -27
- data/lib/nokogiri/{html → html4}/builder.rb +4 -2
- data/lib/nokogiri/html4/document.rb +214 -0
- data/lib/nokogiri/html4/document_fragment.rb +54 -0
- data/lib/nokogiri/{html → html4}/element_description.rb +3 -1
- data/lib/nokogiri/html4/element_description_defaults.rb +2040 -0
- data/lib/nokogiri/html4/encoding_reader.rb +121 -0
- data/lib/nokogiri/{html → html4}/entity_lookup.rb +4 -2
- data/lib/nokogiri/{html → html4}/sax/parser.rb +17 -16
- data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
- data/lib/nokogiri/{html → html4}/sax/push_parser.rb +12 -11
- data/lib/nokogiri/html4.rb +47 -0
- data/lib/nokogiri/html5/document.rb +168 -0
- data/lib/nokogiri/html5/document_fragment.rb +90 -0
- data/lib/nokogiri/html5/node.rb +103 -0
- data/lib/nokogiri/html5.rb +392 -0
- data/lib/nokogiri/jruby/dependencies.rb +3 -0
- data/lib/nokogiri/jruby/nokogiri_jars.rb +43 -0
- data/lib/nokogiri/syntax_error.rb +2 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +223 -0
- data/lib/nokogiri/version.rb +3 -108
- data/lib/nokogiri/xml/attr.rb +55 -3
- data/lib/nokogiri/xml/attribute_decl.rb +6 -2
- data/lib/nokogiri/xml/builder.rb +98 -54
- data/lib/nokogiri/xml/cdata.rb +3 -1
- data/lib/nokogiri/xml/character_data.rb +2 -0
- data/lib/nokogiri/xml/document.rb +312 -126
- data/lib/nokogiri/xml/document_fragment.rb +104 -48
- data/lib/nokogiri/xml/dtd.rb +4 -2
- data/lib/nokogiri/xml/element_content.rb +12 -2
- data/lib/nokogiri/xml/element_decl.rb +6 -2
- data/lib/nokogiri/xml/entity_decl.rb +7 -3
- data/lib/nokogiri/xml/entity_reference.rb +2 -0
- data/lib/nokogiri/xml/namespace.rb +45 -0
- data/lib/nokogiri/xml/node/save_options.rb +23 -8
- data/lib/nokogiri/xml/node.rb +1093 -411
- data/lib/nokogiri/xml/node_set.rb +173 -67
- data/lib/nokogiri/xml/notation.rb +13 -0
- data/lib/nokogiri/xml/parse_options.rb +145 -52
- data/lib/nokogiri/xml/pp/character_data.rb +9 -6
- data/lib/nokogiri/xml/pp/node.rb +42 -30
- data/lib/nokogiri/xml/pp.rb +4 -2
- data/lib/nokogiri/xml/processing_instruction.rb +4 -1
- data/lib/nokogiri/xml/reader.rb +21 -28
- data/lib/nokogiri/xml/relax_ng.rb +8 -2
- data/lib/nokogiri/xml/sax/document.rb +45 -49
- data/lib/nokogiri/xml/sax/parser.rb +39 -36
- data/lib/nokogiri/xml/sax/parser_context.rb +8 -3
- data/lib/nokogiri/xml/sax/push_parser.rb +6 -5
- data/lib/nokogiri/xml/sax.rb +6 -4
- data/lib/nokogiri/xml/schema.rb +19 -9
- data/lib/nokogiri/xml/searchable.rb +120 -72
- data/lib/nokogiri/xml/syntax_error.rb +6 -4
- data/lib/nokogiri/xml/text.rb +2 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +4 -2
- data/lib/nokogiri/xml/xpath.rb +15 -4
- data/lib/nokogiri/xml/xpath_context.rb +3 -3
- data/lib/nokogiri/xml.rb +38 -37
- data/lib/nokogiri/xslt/stylesheet.rb +3 -1
- data/lib/nokogiri/xslt.rb +101 -22
- data/lib/nokogiri.rb +59 -75
- data/lib/xsd/xmlparser/nokogiri.rb +29 -25
- data/patches/libxml2/0001-Remove-script-macro-support.patch +40 -0
- data/patches/libxml2/0002-Update-entities-to-remove-handling-of-ssi.patch +44 -0
- data/patches/libxml2/0003-libxml2.la-is-in-top_builddir.patch +25 -0
- data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
- data/patches/libxml2/0010-update-config.guess-and-config.sub-for-libxml2.patch +224 -0
- data/patches/libxml2/0011-rip-out-libxml2-s-libc_single_threaded-support.patch +30 -0
- data/patches/libxslt/0001-update-config.guess-and-config.sub-for-libxslt.patch +224 -0
- data/ports/archives/libxml2-2.11.4.tar.xz +0 -0
- data/ports/archives/libxslt-1.1.38.tar.xz +0 -0
- metadata +126 -399
- data/.autotest +0 -22
- data/.cross_rubies +0 -8
- data/.editorconfig +0 -17
- data/.gemtest +0 -0
- data/.travis.yml +0 -63
- data/CHANGELOG.md +0 -1368
- data/CONTRIBUTING.md +0 -42
- data/C_CODING_STYLE.rdoc +0 -33
- data/Gemfile-libxml-ruby +0 -3
- data/Manifest.txt +0 -370
- data/ROADMAP.md +0 -111
- data/Rakefile +0 -348
- data/SECURITY.md +0 -19
- data/STANDARD_RESPONSES.md +0 -47
- data/Y_U_NO_GEMSPEC.md +0 -155
- data/appveyor.yml +0 -29
- data/build_all +0 -44
- data/ext/nokogiri/html_document.c +0 -170
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.c +0 -279
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.c +0 -32
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.c +0 -116
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.c +0 -87
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.c +0 -61
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -15
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -13
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
- data/lib/nokogiri/html/document.rb +0 -335
- data/lib/nokogiri/html/document_fragment.rb +0 -49
- data/lib/nokogiri/html/element_description_defaults.rb +0 -671
- data/lib/nokogiri/html/sax/parser_context.rb +0 -16
- data/patches/libxml2/0001-Revert-Do-not-URI-escape-in-server-side-includes.patch +0 -78
- data/patches/libxml2/0002-Fix-nullptr-deref-with-XPath-logic-ops.patch +0 -54
- data/patches/libxml2/0003-Fix-infinite-loop-in-LZMA-decompression.patch +0 -50
- data/patches/sort-patches-by-date +0 -25
- data/ports/archives/libxml2-2.9.8.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.32.tar.gz +0 -0
- data/suppressions/README.txt +0 -1
- data/suppressions/nokogiri_ruby-2.supp +0 -10
- data/tasks/test.rb +0 -100
- data/test/css/test_nthiness.rb +0 -226
- data/test/css/test_parser.rb +0 -386
- data/test/css/test_tokenizer.rb +0 -215
- data/test/css/test_xpath_visitor.rb +0 -96
- data/test/decorators/test_slop.rb +0 -23
- data/test/files/2ch.html +0 -108
- data/test/files/GH_1042.html +0 -18
- data/test/files/address_book.rlx +0 -12
- data/test/files/address_book.xml +0 -10
- data/test/files/atom.xml +0 -344
- data/test/files/bar/bar.xsd +0 -4
- data/test/files/bogus.xml +0 -0
- data/test/files/dont_hurt_em_why.xml +0 -422
- data/test/files/encoding.html +0 -82
- data/test/files/encoding.xhtml +0 -84
- data/test/files/exslt.xml +0 -8
- data/test/files/exslt.xslt +0 -35
- data/test/files/foo/foo.xsd +0 -4
- data/test/files/metacharset.html +0 -10
- data/test/files/namespace_pressure_test.xml +0 -1684
- data/test/files/noencoding.html +0 -47
- data/test/files/po.xml +0 -32
- data/test/files/po.xsd +0 -66
- data/test/files/saml/saml20assertion_schema.xsd +0 -283
- data/test/files/saml/saml20protocol_schema.xsd +0 -302
- data/test/files/saml/xenc_schema.xsd +0 -146
- data/test/files/saml/xmldsig_schema.xsd +0 -318
- data/test/files/shift_jis.html +0 -10
- data/test/files/shift_jis.xml +0 -5
- data/test/files/shift_jis_no_charset.html +0 -9
- data/test/files/slow-xpath.xml +0 -25509
- data/test/files/snuggles.xml +0 -3
- data/test/files/staff.dtd +0 -10
- data/test/files/staff.xml +0 -59
- data/test/files/staff.xslt +0 -32
- data/test/files/test_document_url/bar.xml +0 -2
- data/test/files/test_document_url/document.dtd +0 -4
- data/test/files/test_document_url/document.xml +0 -6
- data/test/files/tlm.html +0 -851
- data/test/files/to_be_xincluded.xml +0 -2
- data/test/files/valid_bar.xml +0 -2
- data/test/files/xinclude.xml +0 -4
- data/test/helper.rb +0 -271
- data/test/html/sax/test_parser.rb +0 -168
- data/test/html/sax/test_parser_context.rb +0 -46
- data/test/html/sax/test_parser_text.rb +0 -163
- data/test/html/sax/test_push_parser.rb +0 -87
- data/test/html/test_attributes.rb +0 -85
- data/test/html/test_builder.rb +0 -164
- data/test/html/test_document.rb +0 -712
- data/test/html/test_document_encoding.rb +0 -143
- data/test/html/test_document_fragment.rb +0 -310
- data/test/html/test_element_description.rb +0 -105
- data/test/html/test_named_characters.rb +0 -14
- data/test/html/test_node.rb +0 -212
- data/test/html/test_node_encoding.rb +0 -91
- data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +0 -14
- data/test/namespaces/test_namespaces_aliased_default.rb +0 -24
- data/test/namespaces/test_namespaces_in_builder_doc.rb +0 -75
- data/test/namespaces/test_namespaces_in_cloned_doc.rb +0 -31
- data/test/namespaces/test_namespaces_in_created_doc.rb +0 -75
- data/test/namespaces/test_namespaces_in_parsed_doc.rb +0 -80
- data/test/namespaces/test_namespaces_preservation.rb +0 -31
- data/test/test_convert_xpath.rb +0 -135
- data/test/test_css_cache.rb +0 -47
- data/test/test_encoding_handler.rb +0 -48
- data/test/test_memory_leak.rb +0 -156
- data/test/test_nokogiri.rb +0 -138
- data/test/test_soap4r_sax.rb +0 -52
- data/test/test_xslt_transforms.rb +0 -314
- data/test/xml/node/test_save_options.rb +0 -28
- data/test/xml/node/test_subclass.rb +0 -44
- data/test/xml/sax/test_parser.rb +0 -402
- data/test/xml/sax/test_parser_context.rb +0 -115
- data/test/xml/sax/test_parser_text.rb +0 -202
- data/test/xml/sax/test_push_parser.rb +0 -265
- data/test/xml/test_attr.rb +0 -74
- data/test/xml/test_attribute_decl.rb +0 -86
- data/test/xml/test_builder.rb +0 -341
- data/test/xml/test_c14n.rb +0 -180
- data/test/xml/test_cdata.rb +0 -54
- data/test/xml/test_comment.rb +0 -40
- data/test/xml/test_document.rb +0 -982
- data/test/xml/test_document_encoding.rb +0 -31
- data/test/xml/test_document_fragment.rb +0 -298
- data/test/xml/test_dtd.rb +0 -187
- data/test/xml/test_dtd_encoding.rb +0 -31
- data/test/xml/test_element_content.rb +0 -56
- data/test/xml/test_element_decl.rb +0 -73
- data/test/xml/test_entity_decl.rb +0 -122
- data/test/xml/test_entity_reference.rb +0 -262
- data/test/xml/test_namespace.rb +0 -96
- data/test/xml/test_node.rb +0 -1325
- data/test/xml/test_node_attributes.rb +0 -115
- data/test/xml/test_node_encoding.rb +0 -75
- data/test/xml/test_node_inheritance.rb +0 -32
- data/test/xml/test_node_reparenting.rb +0 -592
- data/test/xml/test_node_set.rb +0 -809
- data/test/xml/test_parse_options.rb +0 -64
- data/test/xml/test_processing_instruction.rb +0 -30
- data/test/xml/test_reader.rb +0 -620
- data/test/xml/test_reader_encoding.rb +0 -134
- data/test/xml/test_relax_ng.rb +0 -60
- data/test/xml/test_schema.rb +0 -142
- data/test/xml/test_syntax_error.rb +0 -36
- data/test/xml/test_text.rb +0 -60
- data/test/xml/test_unparented_node.rb +0 -483
- data/test/xml/test_xinclude.rb +0 -83
- data/test/xml/test_xpath.rb +0 -470
- data/test/xslt/test_custom_functions.rb +0 -133
- data/test/xslt/test_exception_handling.rb +0 -37
data/ext/nokogiri/xml_reader.c
CHANGED
@@ -1,13 +1,24 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
2
|
|
3
|
-
|
3
|
+
VALUE cNokogiriXmlReader;
|
4
|
+
|
5
|
+
static void
|
6
|
+
xml_reader_deallocate(void *data)
|
4
7
|
{
|
5
|
-
|
8
|
+
xmlTextReaderPtr reader = data;
|
6
9
|
xmlFreeTextReader(reader);
|
7
|
-
NOKOGIRI_DEBUG_END(reader);
|
8
10
|
}
|
9
11
|
|
10
|
-
static
|
12
|
+
static const rb_data_type_t xml_reader_type = {
|
13
|
+
.wrap_struct_name = "Nokogiri::XML::Reader",
|
14
|
+
.function = {
|
15
|
+
.dfree = xml_reader_deallocate,
|
16
|
+
},
|
17
|
+
.flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
|
18
|
+
};
|
19
|
+
|
20
|
+
static int
|
21
|
+
has_attributes(xmlTextReaderPtr reader)
|
11
22
|
{
|
12
23
|
/*
|
13
24
|
* this implementation of xmlTextReaderHasAttributes explicitly includes
|
@@ -16,47 +27,40 @@ static int has_attributes(xmlTextReaderPtr reader)
|
|
16
27
|
*/
|
17
28
|
xmlNodePtr node ;
|
18
29
|
node = xmlTextReaderCurrentNode(reader);
|
19
|
-
if (node == NULL)
|
20
|
-
return(0);
|
30
|
+
if (node == NULL) {
|
31
|
+
return (0);
|
32
|
+
}
|
21
33
|
|
22
34
|
if ((node->type == XML_ELEMENT_NODE) &&
|
23
|
-
((node->properties != NULL) || (node->nsDef != NULL)))
|
24
|
-
return(1);
|
25
|
-
|
35
|
+
((node->properties != NULL) || (node->nsDef != NULL))) {
|
36
|
+
return (1);
|
37
|
+
}
|
38
|
+
return (0);
|
26
39
|
}
|
27
40
|
|
28
|
-
|
41
|
+
// TODO: merge this function into the `namespaces` method implementation
|
42
|
+
static void
|
43
|
+
Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
|
29
44
|
{
|
30
45
|
xmlNsPtr ns;
|
31
|
-
|
32
|
-
char *key ;
|
33
|
-
size_t keylen ;
|
46
|
+
VALUE key;
|
34
47
|
|
35
|
-
if (node->type != XML_ELEMENT_NODE) return ;
|
48
|
+
if (node->type != XML_ELEMENT_NODE) { return ; }
|
36
49
|
|
37
50
|
ns = node->nsDef;
|
38
51
|
while (ns != NULL) {
|
39
52
|
|
40
|
-
|
41
|
-
if (keylen > XMLNS_BUFFER_LEN) {
|
42
|
-
key = (char*)malloc(keylen) ;
|
43
|
-
} else {
|
44
|
-
key = buffer ;
|
45
|
-
}
|
46
|
-
|
53
|
+
key = rb_enc_str_new_cstr(XMLNS_PREFIX, rb_utf8_encoding());
|
47
54
|
if (ns->prefix) {
|
48
|
-
|
49
|
-
|
50
|
-
sprintf(key, "%s", XMLNS_PREFIX);
|
55
|
+
rb_str_cat_cstr(key, ":");
|
56
|
+
rb_str_cat_cstr(key, (const char *)ns->prefix);
|
51
57
|
}
|
52
58
|
|
59
|
+
key = rb_str_conv_enc(key, rb_utf8_encoding(), rb_default_internal_encoding());
|
53
60
|
rb_hash_aset(attr_hash,
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
if (key != buffer) {
|
58
|
-
free(key);
|
59
|
-
}
|
61
|
+
key,
|
62
|
+
(ns->href ? NOKOGIRI_STR_NEW2(ns->href) : Qnil)
|
63
|
+
);
|
60
64
|
ns = ns->next ;
|
61
65
|
}
|
62
66
|
}
|
@@ -68,15 +72,16 @@ static void Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
|
|
68
72
|
*
|
69
73
|
* Was an attribute generated from the default value in the DTD or schema?
|
70
74
|
*/
|
71
|
-
static VALUE
|
75
|
+
static VALUE
|
76
|
+
default_eh(VALUE self)
|
72
77
|
{
|
73
78
|
xmlTextReaderPtr reader;
|
74
79
|
int eh;
|
75
80
|
|
76
|
-
|
81
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
77
82
|
eh = xmlTextReaderIsDefault(reader);
|
78
|
-
if(eh == 0) return Qfalse;
|
79
|
-
if(eh == 1) return Qtrue;
|
83
|
+
if (eh == 0) { return Qfalse; }
|
84
|
+
if (eh == 1) { return Qtrue; }
|
80
85
|
|
81
86
|
return Qnil;
|
82
87
|
}
|
@@ -87,15 +92,16 @@ static VALUE default_eh(VALUE self)
|
|
87
92
|
*
|
88
93
|
* Does this node have a text value?
|
89
94
|
*/
|
90
|
-
static VALUE
|
95
|
+
static VALUE
|
96
|
+
value_eh(VALUE self)
|
91
97
|
{
|
92
98
|
xmlTextReaderPtr reader;
|
93
99
|
int eh;
|
94
100
|
|
95
|
-
|
101
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
96
102
|
eh = xmlTextReaderHasValue(reader);
|
97
|
-
if(eh == 0) return Qfalse;
|
98
|
-
if(eh == 1) return Qtrue;
|
103
|
+
if (eh == 0) { return Qfalse; }
|
104
|
+
if (eh == 1) { return Qtrue; }
|
99
105
|
|
100
106
|
return Qnil;
|
101
107
|
}
|
@@ -106,15 +112,16 @@ static VALUE value_eh(VALUE self)
|
|
106
112
|
*
|
107
113
|
* Does this node have attributes?
|
108
114
|
*/
|
109
|
-
static VALUE
|
115
|
+
static VALUE
|
116
|
+
attributes_eh(VALUE self)
|
110
117
|
{
|
111
118
|
xmlTextReaderPtr reader;
|
112
119
|
int eh;
|
113
120
|
|
114
|
-
|
121
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
115
122
|
eh = has_attributes(reader);
|
116
|
-
if(eh == 0) return Qfalse;
|
117
|
-
if(eh == 1) return Qtrue;
|
123
|
+
if (eh == 0) { return Qfalse; }
|
124
|
+
if (eh == 1) { return Qtrue; }
|
118
125
|
|
119
126
|
return Qnil;
|
120
127
|
}
|
@@ -125,52 +132,136 @@ static VALUE attributes_eh(VALUE self)
|
|
125
132
|
*
|
126
133
|
* Get a hash of namespaces for this Node
|
127
134
|
*/
|
128
|
-
static VALUE
|
135
|
+
static VALUE
|
136
|
+
rb_xml_reader_namespaces(VALUE rb_reader)
|
129
137
|
{
|
130
|
-
|
131
|
-
|
132
|
-
|
138
|
+
VALUE rb_namespaces = rb_hash_new() ;
|
139
|
+
xmlTextReaderPtr c_reader;
|
140
|
+
xmlNodePtr c_node;
|
141
|
+
VALUE rb_errors;
|
142
|
+
|
143
|
+
TypedData_Get_Struct(rb_reader, xmlTextReader, &xml_reader_type, c_reader);
|
133
144
|
|
134
|
-
|
145
|
+
if (! has_attributes(c_reader)) {
|
146
|
+
return rb_namespaces ;
|
147
|
+
}
|
135
148
|
|
136
|
-
|
149
|
+
rb_errors = rb_funcall(rb_reader, rb_intern("errors"), 0);
|
137
150
|
|
138
|
-
|
139
|
-
|
151
|
+
xmlSetStructuredErrorFunc((void *)rb_errors, Nokogiri_error_array_pusher);
|
152
|
+
c_node = xmlTextReaderExpand(c_reader);
|
153
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
140
154
|
|
141
|
-
|
142
|
-
|
155
|
+
if (c_node == NULL) {
|
156
|
+
if (RARRAY_LEN(rb_errors) > 0) {
|
157
|
+
VALUE rb_error = rb_ary_entry(rb_errors, 0);
|
158
|
+
VALUE exception_message = rb_funcall(rb_error, rb_intern("to_s"), 0);
|
159
|
+
rb_exc_raise(rb_class_new_instance(1, &exception_message, cNokogiriXmlSyntaxError));
|
160
|
+
}
|
161
|
+
return Qnil;
|
162
|
+
}
|
143
163
|
|
144
|
-
Nokogiri_xml_node_namespaces(
|
164
|
+
Nokogiri_xml_node_namespaces(c_node, rb_namespaces);
|
145
165
|
|
146
|
-
return
|
166
|
+
return rb_namespaces ;
|
147
167
|
}
|
148
168
|
|
149
169
|
/*
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
170
|
+
:call-seq: attribute_nodes() → Array<Nokogiri::XML::Attr>
|
171
|
+
|
172
|
+
Get the attributes of the current node as an Array of XML:Attr
|
173
|
+
|
174
|
+
⚠ This method is deprecated and unsafe to use. It will be removed in a future version of Nokogiri.
|
175
|
+
|
176
|
+
See related: #attribute_hash, #attributes
|
154
177
|
*/
|
155
|
-
static VALUE
|
178
|
+
static VALUE
|
179
|
+
rb_xml_reader_attribute_nodes(VALUE rb_reader)
|
156
180
|
{
|
157
|
-
xmlTextReaderPtr
|
158
|
-
xmlNodePtr
|
159
|
-
VALUE
|
181
|
+
xmlTextReaderPtr c_reader;
|
182
|
+
xmlNodePtr c_node;
|
183
|
+
VALUE attr_nodes;
|
184
|
+
int j;
|
160
185
|
|
161
|
-
|
186
|
+
// TODO: deprecated, remove in Nokogiri v1.15, see https://github.com/sparklemotion/nokogiri/issues/2598
|
187
|
+
// After removal, we can also remove all the "node_has_a_document" special handling from xml_node.c
|
188
|
+
NOKO_WARN_DEPRECATION("Reader#attribute_nodes is deprecated and will be removed in a future version of Nokogiri. Please use Reader#attribute_hash instead.");
|
162
189
|
|
163
|
-
|
190
|
+
TypedData_Get_Struct(rb_reader, xmlTextReader, &xml_reader_type, c_reader);
|
164
191
|
|
165
|
-
if (! has_attributes(
|
166
|
-
return
|
192
|
+
if (! has_attributes(c_reader)) {
|
193
|
+
return rb_ary_new() ;
|
194
|
+
}
|
195
|
+
|
196
|
+
c_node = xmlTextReaderExpand(c_reader);
|
197
|
+
if (c_node == NULL) {
|
198
|
+
return Qnil;
|
199
|
+
}
|
167
200
|
|
168
|
-
|
169
|
-
if(ptr == NULL) return Qnil;
|
201
|
+
attr_nodes = noko_xml_node_attrs(c_node);
|
170
202
|
|
171
|
-
|
203
|
+
/* ensure that the Reader won't be GCed as long as a node is referenced */
|
204
|
+
for (j = 0 ; j < RARRAY_LEN(attr_nodes) ; j++) {
|
205
|
+
rb_iv_set(rb_ary_entry(attr_nodes, j), "@reader", rb_reader);
|
206
|
+
}
|
172
207
|
|
173
|
-
return
|
208
|
+
return attr_nodes;
|
209
|
+
}
|
210
|
+
|
211
|
+
/*
|
212
|
+
:call-seq: attribute_hash() → Hash<String ⇒ String>
|
213
|
+
|
214
|
+
Get the attributes of the current node as a Hash of names and values.
|
215
|
+
|
216
|
+
See related: #attributes and #namespaces
|
217
|
+
*/
|
218
|
+
static VALUE
|
219
|
+
rb_xml_reader_attribute_hash(VALUE rb_reader)
|
220
|
+
{
|
221
|
+
VALUE rb_attributes = rb_hash_new();
|
222
|
+
xmlTextReaderPtr c_reader;
|
223
|
+
xmlNodePtr c_node;
|
224
|
+
xmlAttrPtr c_property;
|
225
|
+
VALUE rb_errors;
|
226
|
+
|
227
|
+
TypedData_Get_Struct(rb_reader, xmlTextReader, &xml_reader_type, c_reader);
|
228
|
+
|
229
|
+
if (!has_attributes(c_reader)) {
|
230
|
+
return rb_attributes;
|
231
|
+
}
|
232
|
+
|
233
|
+
rb_errors = rb_funcall(rb_reader, rb_intern("errors"), 0);
|
234
|
+
|
235
|
+
xmlSetStructuredErrorFunc((void *)rb_errors, Nokogiri_error_array_pusher);
|
236
|
+
c_node = xmlTextReaderExpand(c_reader);
|
237
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
238
|
+
|
239
|
+
if (c_node == NULL) {
|
240
|
+
if (RARRAY_LEN(rb_errors) > 0) {
|
241
|
+
VALUE rb_error = rb_ary_entry(rb_errors, 0);
|
242
|
+
VALUE exception_message = rb_funcall(rb_error, rb_intern("to_s"), 0);
|
243
|
+
rb_exc_raise(rb_class_new_instance(1, &exception_message, cNokogiriXmlSyntaxError));
|
244
|
+
}
|
245
|
+
return Qnil;
|
246
|
+
}
|
247
|
+
|
248
|
+
c_property = c_node->properties;
|
249
|
+
while (c_property != NULL) {
|
250
|
+
VALUE rb_name = NOKOGIRI_STR_NEW2(c_property->name);
|
251
|
+
VALUE rb_value = Qnil;
|
252
|
+
xmlChar *c_value = xmlNodeGetContent((xmlNode *)c_property);
|
253
|
+
|
254
|
+
if (c_value) {
|
255
|
+
rb_value = NOKOGIRI_STR_NEW2(c_value);
|
256
|
+
xmlFree(c_value);
|
257
|
+
}
|
258
|
+
|
259
|
+
rb_hash_aset(rb_attributes, rb_name, rb_value);
|
260
|
+
|
261
|
+
c_property = c_property->next;
|
262
|
+
}
|
263
|
+
|
264
|
+
return rb_attributes;
|
174
265
|
}
|
175
266
|
|
176
267
|
/*
|
@@ -179,22 +270,23 @@ static VALUE attribute_nodes(VALUE self)
|
|
179
270
|
*
|
180
271
|
* Get the value of attribute at +index+
|
181
272
|
*/
|
182
|
-
static VALUE
|
273
|
+
static VALUE
|
274
|
+
attribute_at(VALUE self, VALUE index)
|
183
275
|
{
|
184
276
|
xmlTextReaderPtr reader;
|
185
277
|
xmlChar *value;
|
186
278
|
VALUE rb_value;
|
187
279
|
|
188
|
-
|
280
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
189
281
|
|
190
|
-
if(NIL_P(index)) return Qnil;
|
282
|
+
if (NIL_P(index)) { return Qnil; }
|
191
283
|
index = rb_Integer(index);
|
192
284
|
|
193
285
|
value = xmlTextReaderGetAttributeNo(
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
if(value == NULL) return Qnil;
|
286
|
+
reader,
|
287
|
+
(int)NUM2INT(index)
|
288
|
+
);
|
289
|
+
if (value == NULL) { return Qnil; }
|
198
290
|
|
199
291
|
rb_value = NOKOGIRI_STR_NEW2(value);
|
200
292
|
xmlFree(value);
|
@@ -207,19 +299,20 @@ static VALUE attribute_at(VALUE self, VALUE index)
|
|
207
299
|
*
|
208
300
|
* Get the value of attribute named +name+
|
209
301
|
*/
|
210
|
-
static VALUE
|
302
|
+
static VALUE
|
303
|
+
reader_attribute(VALUE self, VALUE name)
|
211
304
|
{
|
212
305
|
xmlTextReaderPtr reader;
|
213
306
|
xmlChar *value ;
|
214
307
|
VALUE rb_value;
|
215
308
|
|
216
|
-
|
309
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
217
310
|
|
218
|
-
if(NIL_P(name)) return Qnil;
|
311
|
+
if (NIL_P(name)) { return Qnil; }
|
219
312
|
name = StringValue(name) ;
|
220
313
|
|
221
|
-
value = xmlTextReaderGetAttribute(reader, (xmlChar*)StringValueCStr(name));
|
222
|
-
if(value == NULL) return Qnil;
|
314
|
+
value = xmlTextReaderGetAttribute(reader, (xmlChar *)StringValueCStr(name));
|
315
|
+
if (value == NULL) { return Qnil; }
|
223
316
|
|
224
317
|
rb_value = NOKOGIRI_STR_NEW2(value);
|
225
318
|
xmlFree(value);
|
@@ -232,16 +325,17 @@ static VALUE reader_attribute(VALUE self, VALUE name)
|
|
232
325
|
*
|
233
326
|
* Get the number of attributes for the current node
|
234
327
|
*/
|
235
|
-
static VALUE
|
328
|
+
static VALUE
|
329
|
+
attribute_count(VALUE self)
|
236
330
|
{
|
237
331
|
xmlTextReaderPtr reader;
|
238
332
|
int count;
|
239
333
|
|
240
|
-
|
334
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
241
335
|
count = xmlTextReaderAttributeCount(reader);
|
242
|
-
if(count == -1) return Qnil;
|
336
|
+
if (count == -1) { return Qnil; }
|
243
337
|
|
244
|
-
return INT2NUM(
|
338
|
+
return INT2NUM(count);
|
245
339
|
}
|
246
340
|
|
247
341
|
/*
|
@@ -250,16 +344,17 @@ static VALUE attribute_count(VALUE self)
|
|
250
344
|
*
|
251
345
|
* Get the depth of the node
|
252
346
|
*/
|
253
|
-
static VALUE
|
347
|
+
static VALUE
|
348
|
+
depth(VALUE self)
|
254
349
|
{
|
255
350
|
xmlTextReaderPtr reader;
|
256
351
|
int depth;
|
257
352
|
|
258
|
-
|
353
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
259
354
|
depth = xmlTextReaderDepth(reader);
|
260
|
-
if(depth == -1) return Qnil;
|
355
|
+
if (depth == -1) { return Qnil; }
|
261
356
|
|
262
|
-
return INT2NUM(
|
357
|
+
return INT2NUM(depth);
|
263
358
|
}
|
264
359
|
|
265
360
|
/*
|
@@ -268,14 +363,15 @@ static VALUE depth(VALUE self)
|
|
268
363
|
*
|
269
364
|
* Get the XML version of the document being read
|
270
365
|
*/
|
271
|
-
static VALUE
|
366
|
+
static VALUE
|
367
|
+
xml_version(VALUE self)
|
272
368
|
{
|
273
369
|
xmlTextReaderPtr reader;
|
274
370
|
const char *version;
|
275
371
|
|
276
|
-
|
372
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
277
373
|
version = (const char *)xmlTextReaderConstXmlVersion(reader);
|
278
|
-
if(version == NULL) return Qnil;
|
374
|
+
if (version == NULL) { return Qnil; }
|
279
375
|
|
280
376
|
return NOKOGIRI_STR_NEW2(version);
|
281
377
|
}
|
@@ -286,14 +382,15 @@ static VALUE xml_version(VALUE self)
|
|
286
382
|
*
|
287
383
|
* Get the xml:lang scope within which the node resides.
|
288
384
|
*/
|
289
|
-
static VALUE
|
385
|
+
static VALUE
|
386
|
+
lang(VALUE self)
|
290
387
|
{
|
291
388
|
xmlTextReaderPtr reader;
|
292
389
|
const char *lang;
|
293
390
|
|
294
|
-
|
391
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
295
392
|
lang = (const char *)xmlTextReaderConstXmlLang(reader);
|
296
|
-
if(lang == NULL) return Qnil;
|
393
|
+
if (lang == NULL) { return Qnil; }
|
297
394
|
|
298
395
|
return NOKOGIRI_STR_NEW2(lang);
|
299
396
|
}
|
@@ -304,14 +401,15 @@ static VALUE lang(VALUE self)
|
|
304
401
|
*
|
305
402
|
* Get the text value of the node if present. Returns a utf-8 encoded string.
|
306
403
|
*/
|
307
|
-
static VALUE
|
404
|
+
static VALUE
|
405
|
+
value(VALUE self)
|
308
406
|
{
|
309
407
|
xmlTextReaderPtr reader;
|
310
408
|
const char *value;
|
311
409
|
|
312
|
-
|
410
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
313
411
|
value = (const char *)xmlTextReaderConstValue(reader);
|
314
|
-
if(value == NULL) return Qnil;
|
412
|
+
if (value == NULL) { return Qnil; }
|
315
413
|
|
316
414
|
return NOKOGIRI_STR_NEW2(value);
|
317
415
|
}
|
@@ -322,14 +420,15 @@ static VALUE value(VALUE self)
|
|
322
420
|
*
|
323
421
|
* Get the shorthand reference to the namespace associated with the node.
|
324
422
|
*/
|
325
|
-
static VALUE
|
423
|
+
static VALUE
|
424
|
+
prefix(VALUE self)
|
326
425
|
{
|
327
426
|
xmlTextReaderPtr reader;
|
328
427
|
const char *prefix;
|
329
428
|
|
330
|
-
|
429
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
331
430
|
prefix = (const char *)xmlTextReaderConstPrefix(reader);
|
332
|
-
if(prefix == NULL) return Qnil;
|
431
|
+
if (prefix == NULL) { return Qnil; }
|
333
432
|
|
334
433
|
return NOKOGIRI_STR_NEW2(prefix);
|
335
434
|
}
|
@@ -340,14 +439,15 @@ static VALUE prefix(VALUE self)
|
|
340
439
|
*
|
341
440
|
* Get the URI defining the namespace associated with the node
|
342
441
|
*/
|
343
|
-
static VALUE
|
442
|
+
static VALUE
|
443
|
+
namespace_uri(VALUE self)
|
344
444
|
{
|
345
445
|
xmlTextReaderPtr reader;
|
346
446
|
const char *uri;
|
347
447
|
|
348
|
-
|
448
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
349
449
|
uri = (const char *)xmlTextReaderConstNamespaceUri(reader);
|
350
|
-
if(uri == NULL) return Qnil;
|
450
|
+
if (uri == NULL) { return Qnil; }
|
351
451
|
|
352
452
|
return NOKOGIRI_STR_NEW2(uri);
|
353
453
|
}
|
@@ -358,14 +458,15 @@ static VALUE namespace_uri(VALUE self)
|
|
358
458
|
*
|
359
459
|
* Get the local name of the node
|
360
460
|
*/
|
361
|
-
static VALUE
|
461
|
+
static VALUE
|
462
|
+
local_name(VALUE self)
|
362
463
|
{
|
363
464
|
xmlTextReaderPtr reader;
|
364
465
|
const char *name;
|
365
466
|
|
366
|
-
|
467
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
367
468
|
name = (const char *)xmlTextReaderConstLocalName(reader);
|
368
|
-
if(name == NULL) return Qnil;
|
469
|
+
if (name == NULL) { return Qnil; }
|
369
470
|
|
370
471
|
return NOKOGIRI_STR_NEW2(name);
|
371
472
|
}
|
@@ -376,14 +477,15 @@ static VALUE local_name(VALUE self)
|
|
376
477
|
*
|
377
478
|
* Get the name of the node. Returns a utf-8 encoded string.
|
378
479
|
*/
|
379
|
-
static VALUE
|
480
|
+
static VALUE
|
481
|
+
name(VALUE self)
|
380
482
|
{
|
381
483
|
xmlTextReaderPtr reader;
|
382
484
|
const char *name;
|
383
485
|
|
384
|
-
|
486
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
385
487
|
name = (const char *)xmlTextReaderConstName(reader);
|
386
|
-
if(name == NULL) return Qnil;
|
488
|
+
if (name == NULL) { return Qnil; }
|
387
489
|
|
388
490
|
return NOKOGIRI_STR_NEW2(name);
|
389
491
|
}
|
@@ -394,16 +496,24 @@ static VALUE name(VALUE self)
|
|
394
496
|
*
|
395
497
|
* Get the xml:base of the node
|
396
498
|
*/
|
397
|
-
static VALUE
|
499
|
+
static VALUE
|
500
|
+
rb_xml_reader_base_uri(VALUE rb_reader)
|
398
501
|
{
|
399
|
-
|
400
|
-
|
502
|
+
VALUE rb_base_uri;
|
503
|
+
xmlTextReaderPtr c_reader;
|
504
|
+
xmlChar *c_base_uri;
|
505
|
+
|
506
|
+
TypedData_Get_Struct(rb_reader, xmlTextReader, &xml_reader_type, c_reader);
|
507
|
+
|
508
|
+
c_base_uri = xmlTextReaderBaseUri(c_reader);
|
509
|
+
if (c_base_uri == NULL) {
|
510
|
+
return Qnil;
|
511
|
+
}
|
401
512
|
|
402
|
-
|
403
|
-
|
404
|
-
if (base_uri == NULL) return Qnil;
|
513
|
+
rb_base_uri = NOKOGIRI_STR_NEW2(c_base_uri);
|
514
|
+
xmlFree(c_base_uri);
|
405
515
|
|
406
|
-
return
|
516
|
+
return rb_base_uri;
|
407
517
|
}
|
408
518
|
|
409
519
|
/*
|
@@ -412,11 +522,12 @@ static VALUE base_uri(VALUE self)
|
|
412
522
|
*
|
413
523
|
* Get the state of the reader
|
414
524
|
*/
|
415
|
-
static VALUE
|
525
|
+
static VALUE
|
526
|
+
state(VALUE self)
|
416
527
|
{
|
417
528
|
xmlTextReaderPtr reader;
|
418
|
-
|
419
|
-
return INT2NUM(
|
529
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
530
|
+
return INT2NUM(xmlTextReaderReadState(reader));
|
420
531
|
}
|
421
532
|
|
422
533
|
/*
|
@@ -425,11 +536,12 @@ static VALUE state(VALUE self)
|
|
425
536
|
*
|
426
537
|
* Get the type of readers current node
|
427
538
|
*/
|
428
|
-
static VALUE
|
539
|
+
static VALUE
|
540
|
+
node_type(VALUE self)
|
429
541
|
{
|
430
542
|
xmlTextReaderPtr reader;
|
431
|
-
|
432
|
-
return INT2NUM(
|
543
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
544
|
+
return INT2NUM(xmlTextReaderNodeType(reader));
|
433
545
|
}
|
434
546
|
|
435
547
|
/*
|
@@ -438,14 +550,15 @@ static VALUE node_type(VALUE self)
|
|
438
550
|
*
|
439
551
|
* Move the Reader forward through the XML document.
|
440
552
|
*/
|
441
|
-
static VALUE
|
553
|
+
static VALUE
|
554
|
+
read_more(VALUE self)
|
442
555
|
{
|
443
556
|
xmlTextReaderPtr reader;
|
444
557
|
xmlErrorPtr error;
|
445
558
|
VALUE error_list;
|
446
559
|
int ret;
|
447
560
|
|
448
|
-
|
561
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
449
562
|
|
450
563
|
error_list = rb_funcall(self, rb_intern("errors"), 0);
|
451
564
|
|
@@ -453,14 +566,15 @@ static VALUE read_more(VALUE self)
|
|
453
566
|
ret = xmlTextReaderRead(reader);
|
454
567
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
455
568
|
|
456
|
-
if(ret == 1) return self;
|
457
|
-
if(ret == 0) return Qnil;
|
569
|
+
if (ret == 1) { return self; }
|
570
|
+
if (ret == 0) { return Qnil; }
|
458
571
|
|
459
572
|
error = xmlGetLastError();
|
460
|
-
if(error)
|
573
|
+
if (error) {
|
461
574
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
462
|
-
else
|
575
|
+
} else {
|
463
576
|
rb_raise(rb_eRuntimeError, "Error pulling: %d", ret);
|
577
|
+
}
|
464
578
|
|
465
579
|
return Qnil;
|
466
580
|
}
|
@@ -472,19 +586,20 @@ static VALUE read_more(VALUE self)
|
|
472
586
|
* Read the contents of the current node, including child nodes and markup.
|
473
587
|
* Returns a utf-8 encoded string.
|
474
588
|
*/
|
475
|
-
static VALUE
|
589
|
+
static VALUE
|
590
|
+
inner_xml(VALUE self)
|
476
591
|
{
|
477
592
|
xmlTextReaderPtr reader;
|
478
|
-
xmlChar*
|
593
|
+
xmlChar *value;
|
479
594
|
VALUE str;
|
480
595
|
|
481
|
-
|
596
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
482
597
|
|
483
598
|
value = xmlTextReaderReadInnerXml(reader);
|
484
599
|
|
485
600
|
str = Qnil;
|
486
|
-
if(value) {
|
487
|
-
str = NOKOGIRI_STR_NEW2((char*)value);
|
601
|
+
if (value) {
|
602
|
+
str = NOKOGIRI_STR_NEW2((char *)value);
|
488
603
|
xmlFree(value);
|
489
604
|
}
|
490
605
|
|
@@ -498,18 +613,19 @@ static VALUE inner_xml(VALUE self)
|
|
498
613
|
* Read the current node and its contents, including child nodes and markup.
|
499
614
|
* Returns a utf-8 encoded string.
|
500
615
|
*/
|
501
|
-
static VALUE
|
616
|
+
static VALUE
|
617
|
+
outer_xml(VALUE self)
|
502
618
|
{
|
503
619
|
xmlTextReaderPtr reader;
|
504
620
|
xmlChar *value;
|
505
621
|
VALUE str = Qnil;
|
506
622
|
|
507
|
-
|
623
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
508
624
|
|
509
625
|
value = xmlTextReaderReadOuterXml(reader);
|
510
626
|
|
511
|
-
if(value) {
|
512
|
-
str = NOKOGIRI_STR_NEW2((char*)value);
|
627
|
+
if (value) {
|
628
|
+
str = NOKOGIRI_STR_NEW2((char *)value);
|
513
629
|
xmlFree(value);
|
514
630
|
}
|
515
631
|
return str;
|
@@ -521,36 +637,37 @@ static VALUE outer_xml(VALUE self)
|
|
521
637
|
*
|
522
638
|
* Create a new reader that parses +string+
|
523
639
|
*/
|
524
|
-
static VALUE
|
640
|
+
static VALUE
|
641
|
+
from_memory(int argc, VALUE *argv, VALUE klass)
|
525
642
|
{
|
526
643
|
VALUE rb_buffer, rb_url, encoding, rb_options;
|
527
644
|
xmlTextReaderPtr reader;
|
528
|
-
const char *
|
529
|
-
const char *
|
645
|
+
const char *c_url = NULL;
|
646
|
+
const char *c_encoding = NULL;
|
530
647
|
int c_options = 0;
|
531
648
|
VALUE rb_reader, args[3];
|
532
649
|
|
533
650
|
rb_scan_args(argc, argv, "13", &rb_buffer, &rb_url, &encoding, &rb_options);
|
534
651
|
|
535
|
-
if (!RTEST(rb_buffer)) rb_raise(rb_eArgError, "string cannot be nil");
|
536
|
-
if (RTEST(rb_url)) c_url = StringValueCStr(rb_url);
|
537
|
-
if (RTEST(encoding)) c_encoding = StringValueCStr(encoding);
|
538
|
-
if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options);
|
652
|
+
if (!RTEST(rb_buffer)) { rb_raise(rb_eArgError, "string cannot be nil"); }
|
653
|
+
if (RTEST(rb_url)) { c_url = StringValueCStr(rb_url); }
|
654
|
+
if (RTEST(encoding)) { c_encoding = StringValueCStr(encoding); }
|
655
|
+
if (RTEST(rb_options)) { c_options = (int)NUM2INT(rb_options); }
|
539
656
|
|
540
657
|
reader = xmlReaderForMemory(
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
if(reader == NULL) {
|
658
|
+
StringValuePtr(rb_buffer),
|
659
|
+
(int)RSTRING_LEN(rb_buffer),
|
660
|
+
c_url,
|
661
|
+
c_encoding,
|
662
|
+
c_options
|
663
|
+
);
|
664
|
+
|
665
|
+
if (reader == NULL) {
|
549
666
|
xmlFreeTextReader(reader);
|
550
667
|
rb_raise(rb_eRuntimeError, "couldn't create a parser");
|
551
668
|
}
|
552
669
|
|
553
|
-
rb_reader =
|
670
|
+
rb_reader = TypedData_Wrap_Struct(klass, &xml_reader_type, reader);
|
554
671
|
args[0] = rb_buffer;
|
555
672
|
args[1] = rb_url;
|
556
673
|
args[2] = encoding;
|
@@ -565,37 +682,38 @@ static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
|
|
565
682
|
*
|
566
683
|
* Create a new reader that parses +io+
|
567
684
|
*/
|
568
|
-
static VALUE
|
685
|
+
static VALUE
|
686
|
+
from_io(int argc, VALUE *argv, VALUE klass)
|
569
687
|
{
|
570
688
|
VALUE rb_io, rb_url, encoding, rb_options;
|
571
689
|
xmlTextReaderPtr reader;
|
572
|
-
const char *
|
573
|
-
const char *
|
690
|
+
const char *c_url = NULL;
|
691
|
+
const char *c_encoding = NULL;
|
574
692
|
int c_options = 0;
|
575
693
|
VALUE rb_reader, args[3];
|
576
694
|
|
577
695
|
rb_scan_args(argc, argv, "13", &rb_io, &rb_url, &encoding, &rb_options);
|
578
696
|
|
579
|
-
if (!RTEST(rb_io)) rb_raise(rb_eArgError, "io cannot be nil");
|
580
|
-
if (RTEST(rb_url)) c_url = StringValueCStr(rb_url);
|
581
|
-
if (RTEST(encoding)) c_encoding = StringValueCStr(encoding);
|
582
|
-
if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options);
|
697
|
+
if (!RTEST(rb_io)) { rb_raise(rb_eArgError, "io cannot be nil"); }
|
698
|
+
if (RTEST(rb_url)) { c_url = StringValueCStr(rb_url); }
|
699
|
+
if (RTEST(encoding)) { c_encoding = StringValueCStr(encoding); }
|
700
|
+
if (RTEST(rb_options)) { c_options = (int)NUM2INT(rb_options); }
|
583
701
|
|
584
702
|
reader = xmlReaderForIO(
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
if(reader == NULL) {
|
703
|
+
(xmlInputReadCallback)noko_io_read,
|
704
|
+
(xmlInputCloseCallback)noko_io_close,
|
705
|
+
(void *)rb_io,
|
706
|
+
c_url,
|
707
|
+
c_encoding,
|
708
|
+
c_options
|
709
|
+
);
|
710
|
+
|
711
|
+
if (reader == NULL) {
|
594
712
|
xmlFreeTextReader(reader);
|
595
713
|
rb_raise(rb_eRuntimeError, "couldn't create a parser");
|
596
714
|
}
|
597
715
|
|
598
|
-
rb_reader =
|
716
|
+
rb_reader = TypedData_Wrap_Struct(klass, &xml_reader_type, reader);
|
599
717
|
args[0] = rb_io;
|
600
718
|
args[1] = rb_url;
|
601
719
|
args[2] = encoding;
|
@@ -610,59 +728,76 @@ static VALUE from_io(int argc, VALUE *argv, VALUE klass)
|
|
610
728
|
*
|
611
729
|
* Returns true if the current node is empty, otherwise false.
|
612
730
|
*/
|
613
|
-
static VALUE
|
731
|
+
static VALUE
|
732
|
+
empty_element_p(VALUE self)
|
614
733
|
{
|
615
734
|
xmlTextReaderPtr reader;
|
616
735
|
|
617
|
-
|
736
|
+
TypedData_Get_Struct(self, xmlTextReader, &xml_reader_type, reader);
|
618
737
|
|
619
|
-
if(xmlTextReaderIsEmptyElement(reader))
|
738
|
+
if (xmlTextReaderIsEmptyElement(reader)) {
|
620
739
|
return Qtrue;
|
740
|
+
}
|
621
741
|
|
622
742
|
return Qfalse;
|
623
743
|
}
|
624
744
|
|
625
|
-
VALUE
|
626
|
-
|
627
|
-
void init_xml_reader()
|
745
|
+
static VALUE
|
746
|
+
rb_xml_reader_encoding(VALUE rb_reader)
|
628
747
|
{
|
629
|
-
|
630
|
-
|
748
|
+
xmlTextReaderPtr c_reader;
|
749
|
+
const char *parser_encoding;
|
750
|
+
VALUE constructor_encoding;
|
751
|
+
|
752
|
+
constructor_encoding = rb_iv_get(rb_reader, "@encoding");
|
753
|
+
if (RTEST(constructor_encoding)) {
|
754
|
+
return constructor_encoding;
|
755
|
+
}
|
631
756
|
|
757
|
+
TypedData_Get_Struct(rb_reader, xmlTextReader, &xml_reader_type, c_reader);
|
758
|
+
parser_encoding = (const char *)xmlTextReaderConstEncoding(c_reader);
|
759
|
+
if (parser_encoding == NULL) { return Qnil; }
|
760
|
+
return NOKOGIRI_STR_NEW2(parser_encoding);
|
761
|
+
}
|
762
|
+
|
763
|
+
void
|
764
|
+
noko_init_xml_reader(void)
|
765
|
+
{
|
632
766
|
/*
|
633
767
|
* The Reader parser allows you to effectively pull parse an XML document.
|
634
768
|
* Once instantiated, call Nokogiri::XML::Reader#each to iterate over each
|
635
769
|
* node. Note that you may only iterate over the document once!
|
636
770
|
*/
|
637
|
-
|
638
|
-
|
639
|
-
cNokogiriXmlReader
|
640
|
-
|
641
|
-
rb_define_singleton_method(
|
642
|
-
rb_define_singleton_method(
|
643
|
-
|
644
|
-
rb_define_method(
|
645
|
-
rb_define_method(
|
646
|
-
rb_define_method(
|
647
|
-
rb_define_method(
|
648
|
-
rb_define_method(
|
649
|
-
rb_define_method(
|
650
|
-
rb_define_method(
|
651
|
-
rb_define_method(
|
652
|
-
rb_define_method(
|
653
|
-
rb_define_method(
|
654
|
-
rb_define_method(
|
655
|
-
rb_define_method(
|
656
|
-
rb_define_method(
|
657
|
-
rb_define_method(
|
658
|
-
rb_define_method(
|
659
|
-
rb_define_method(
|
660
|
-
rb_define_method(
|
661
|
-
rb_define_method(
|
662
|
-
rb_define_method(
|
663
|
-
rb_define_method(
|
664
|
-
rb_define_method(
|
665
|
-
rb_define_method(
|
666
|
-
|
667
|
-
|
771
|
+
cNokogiriXmlReader = rb_define_class_under(mNokogiriXml, "Reader", rb_cObject);
|
772
|
+
|
773
|
+
rb_undef_alloc_func(cNokogiriXmlReader);
|
774
|
+
|
775
|
+
rb_define_singleton_method(cNokogiriXmlReader, "from_memory", from_memory, -1);
|
776
|
+
rb_define_singleton_method(cNokogiriXmlReader, "from_io", from_io, -1);
|
777
|
+
|
778
|
+
rb_define_method(cNokogiriXmlReader, "attribute", reader_attribute, 1);
|
779
|
+
rb_define_method(cNokogiriXmlReader, "attribute_at", attribute_at, 1);
|
780
|
+
rb_define_method(cNokogiriXmlReader, "attribute_count", attribute_count, 0);
|
781
|
+
rb_define_method(cNokogiriXmlReader, "attribute_nodes", rb_xml_reader_attribute_nodes, 0);
|
782
|
+
rb_define_method(cNokogiriXmlReader, "attribute_hash", rb_xml_reader_attribute_hash, 0);
|
783
|
+
rb_define_method(cNokogiriXmlReader, "attributes?", attributes_eh, 0);
|
784
|
+
rb_define_method(cNokogiriXmlReader, "base_uri", rb_xml_reader_base_uri, 0);
|
785
|
+
rb_define_method(cNokogiriXmlReader, "default?", default_eh, 0);
|
786
|
+
rb_define_method(cNokogiriXmlReader, "depth", depth, 0);
|
787
|
+
rb_define_method(cNokogiriXmlReader, "empty_element?", empty_element_p, 0);
|
788
|
+
rb_define_method(cNokogiriXmlReader, "encoding", rb_xml_reader_encoding, 0);
|
789
|
+
rb_define_method(cNokogiriXmlReader, "inner_xml", inner_xml, 0);
|
790
|
+
rb_define_method(cNokogiriXmlReader, "lang", lang, 0);
|
791
|
+
rb_define_method(cNokogiriXmlReader, "local_name", local_name, 0);
|
792
|
+
rb_define_method(cNokogiriXmlReader, "name", name, 0);
|
793
|
+
rb_define_method(cNokogiriXmlReader, "namespace_uri", namespace_uri, 0);
|
794
|
+
rb_define_method(cNokogiriXmlReader, "namespaces", rb_xml_reader_namespaces, 0);
|
795
|
+
rb_define_method(cNokogiriXmlReader, "node_type", node_type, 0);
|
796
|
+
rb_define_method(cNokogiriXmlReader, "outer_xml", outer_xml, 0);
|
797
|
+
rb_define_method(cNokogiriXmlReader, "prefix", prefix, 0);
|
798
|
+
rb_define_method(cNokogiriXmlReader, "read", read_more, 0);
|
799
|
+
rb_define_method(cNokogiriXmlReader, "state", state, 0);
|
800
|
+
rb_define_method(cNokogiriXmlReader, "value", value, 0);
|
801
|
+
rb_define_method(cNokogiriXmlReader, "value?", value_eh, 0);
|
802
|
+
rb_define_method(cNokogiriXmlReader, "xml_version", xml_version, 0);
|
668
803
|
}
|