nokogiri 1.5.10 → 1.13.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/Gemfile +5 -0
- data/LICENSE-DEPENDENCIES.md +1903 -0
- data/LICENSE.md +9 -0
- data/README.md +280 -0
- data/bin/nokogiri +84 -31
- data/dependencies.yml +73 -0
- data/ext/nokogiri/depend +38 -358
- data/ext/nokogiri/extconf.rb +956 -100
- data/ext/nokogiri/gumbo.c +584 -0
- data/ext/nokogiri/html4_document.c +166 -0
- data/ext/nokogiri/html4_element_description.c +294 -0
- data/ext/nokogiri/html4_entity_lookup.c +37 -0
- data/ext/nokogiri/html4_sax_parser_context.c +120 -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 +232 -87
- data/ext/nokogiri/nokogiri.h +188 -129
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +49 -40
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +24 -23
- data/ext/nokogiri/xml_comment.c +29 -21
- data/ext/nokogiri/xml_document.c +327 -223
- data/ext/nokogiri/xml_document_fragment.c +12 -16
- data/ext/nokogiri/xml_dtd.c +56 -50
- data/ext/nokogiri/xml_element_content.c +31 -26
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +45 -20
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +74 -32
- data/ext/nokogiri/xml_node.c +1290 -680
- data/ext/nokogiri/xml_node_set.c +239 -208
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +227 -189
- data/ext/nokogiri/xml_relax_ng.c +52 -28
- data/ext/nokogiri/xml_sax_parser.c +123 -125
- data/ext/nokogiri/xml_sax_parser_context.c +138 -79
- data/ext/nokogiri/xml_sax_push_parser.c +88 -35
- data/ext/nokogiri/xml_schema.c +112 -33
- data/ext/nokogiri/xml_syntax_error.c +50 -23
- data/ext/nokogiri/xml_text.c +14 -18
- data/ext/nokogiri/xml_xpath_context.c +227 -140
- data/ext/nokogiri/xslt_stylesheet.c +162 -168
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +101 -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 +626 -0
- data/gumbo-parser/src/error.h +148 -0
- data/gumbo-parser/src/foreign_attrs.c +104 -0
- data/gumbo-parser/src/foreign_attrs.gperf +27 -0
- data/gumbo-parser/src/gumbo.h +943 -0
- data/gumbo-parser/src/insertion_mode.h +33 -0
- data/gumbo-parser/src/macros.h +91 -0
- data/gumbo-parser/src/parser.c +4875 -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 +222 -0
- data/gumbo-parser/src/tag_lookup.c +382 -0
- data/gumbo-parser/src/tag_lookup.gperf +169 -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 +68 -0
- data/gumbo-parser/src/util.h +30 -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 -58
- data/lib/nokogiri/css/parser.rb +327 -288
- data/lib/nokogiri/css/parser.y +67 -45
- data/lib/nokogiri/css/parser_extras.rb +52 -49
- data/lib/nokogiri/css/syntax_error.rb +3 -1
- data/lib/nokogiri/css/tokenizer.rb +107 -104
- data/lib/nokogiri/css/tokenizer.rex +7 -6
- data/lib/nokogiri/css/xpath_visitor.rb +263 -75
- data/lib/nokogiri/css.rb +50 -17
- data/lib/nokogiri/decorators/slop.rb +17 -8
- data/lib/nokogiri/extension.rb +31 -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 +331 -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 +578 -0
- data/lib/nokogiri/{html → html4}/entity_lookup.rb +4 -2
- data/lib/nokogiri/{html → html4}/sax/parser.rb +24 -15
- data/lib/nokogiri/html4/sax/parser_context.rb +20 -0
- data/lib/nokogiri/html4/sax/push_parser.rb +37 -0
- data/lib/nokogiri/html4.rb +46 -0
- data/lib/nokogiri/html5/document.rb +88 -0
- data/lib/nokogiri/html5/document_fragment.rb +83 -0
- data/lib/nokogiri/html5/node.rb +96 -0
- data/lib/nokogiri/html5.rb +477 -0
- data/lib/nokogiri/jruby/dependencies.rb +21 -0
- data/lib/nokogiri/syntax_error.rb +2 -0
- data/lib/nokogiri/version/constant.rb +6 -0
- data/lib/nokogiri/version/info.rb +221 -0
- data/lib/nokogiri/version.rb +3 -90
- data/lib/nokogiri/xml/attr.rb +6 -3
- data/lib/nokogiri/xml/attribute_decl.rb +3 -1
- data/lib/nokogiri/xml/builder.rb +96 -54
- data/lib/nokogiri/xml/cdata.rb +3 -1
- data/lib/nokogiri/xml/character_data.rb +2 -0
- data/lib/nokogiri/xml/document.rb +234 -95
- data/lib/nokogiri/xml/document_fragment.rb +86 -36
- data/lib/nokogiri/xml/dtd.rb +16 -4
- data/lib/nokogiri/xml/element_content.rb +2 -0
- data/lib/nokogiri/xml/element_decl.rb +3 -1
- data/lib/nokogiri/xml/entity_decl.rb +4 -2
- data/lib/nokogiri/xml/entity_reference.rb +20 -0
- data/lib/nokogiri/xml/namespace.rb +3 -0
- data/lib/nokogiri/xml/node/save_options.rb +8 -4
- data/lib/nokogiri/xml/node.rb +947 -502
- data/lib/nokogiri/xml/node_set.rb +168 -159
- data/lib/nokogiri/xml/notation.rb +13 -0
- data/lib/nokogiri/xml/parse_options.rb +40 -5
- data/lib/nokogiri/xml/pp/character_data.rb +9 -6
- data/lib/nokogiri/xml/pp/node.rb +25 -26
- data/lib/nokogiri/xml/pp.rb +4 -2
- data/lib/nokogiri/xml/processing_instruction.rb +3 -1
- data/lib/nokogiri/xml/reader.rb +23 -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 +43 -41
- 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 +259 -0
- data/lib/nokogiri/xml/syntax_error.rb +25 -1
- 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 -36
- data/lib/nokogiri/xslt/stylesheet.rb +3 -1
- data/lib/nokogiri/xslt.rb +18 -16
- data/lib/nokogiri.rb +69 -69
- data/lib/xsd/xmlparser/nokogiri.rb +26 -24
- 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/0004-use-glibc-strlen.patch +53 -0
- data/patches/libxml2/0005-avoid-isnan-isinf.patch +81 -0
- data/patches/libxml2/0006-update-automake-files-for-arm64.patch +2511 -0
- data/patches/libxml2/0007-Fix-XPath-recursion-limit.patch +31 -0
- data/patches/libxml2/0008-htmlParseComment-handle-abruptly-closed-comments.patch +61 -0
- data/patches/libxml2/0009-allow-wildcard-namespaces.patch +77 -0
- data/patches/libxslt/0001-update-automake-files-for-arm64.patch +2511 -0
- data/patches/libxslt/0002-Fix-xml2-config-check-in-configure-script.patch +19 -0
- data/ports/archives/libxml2-2.9.12.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
- metadata +382 -460
- data/.autotest +0 -26
- data/.gemtest +0 -0
- data/CHANGELOG.ja.rdoc +0 -785
- data/CHANGELOG.rdoc +0 -783
- data/C_CODING_STYLE.rdoc +0 -33
- data/Manifest.txt +0 -303
- data/README.ja.rdoc +0 -106
- data/README.rdoc +0 -175
- data/ROADMAP.md +0 -90
- data/Rakefile +0 -228
- data/STANDARD_RESPONSES.md +0 -47
- data/Y_U_NO_GEMSPEC.md +0 -155
- data/build_all +0 -105
- 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 -56
- 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 -13
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -14
- 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 -254
- data/lib/nokogiri/html/document_fragment.rb +0 -41
- data/lib/nokogiri/html/element_description_defaults.rb +0 -671
- data/lib/nokogiri/html/sax/parser_context.rb +0 -16
- data/lib/nokogiri/html/sax/push_parser.rb +0 -16
- data/tasks/cross_compile.rb +0 -150
- data/tasks/nokogiri.org.rb +0 -24
- data/tasks/test.rb +0 -95
- data/test/css/test_nthiness.rb +0 -159
- data/test/css/test_parser.rb +0 -341
- data/test/css/test_tokenizer.rb +0 -198
- data/test/css/test_xpath_visitor.rb +0 -91
- data/test/decorators/test_slop.rb +0 -16
- data/test/files/2ch.html +0 -108
- data/test/files/address_book.rlx +0 -12
- data/test/files/address_book.xml +0 -10
- data/test/files/bar/bar.xsd +0 -4
- 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/noencoding.html +0 -47
- data/test/files/po.xml +0 -32
- data/test/files/po.xsd +0 -66
- data/test/files/shift_jis.html +0 -10
- data/test/files/shift_jis.xml +0 -5
- 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 -850
- 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 -154
- data/test/html/sax/test_parser.rb +0 -141
- data/test/html/sax/test_parser_context.rb +0 -46
- data/test/html/test_builder.rb +0 -164
- data/test/html/test_document.rb +0 -552
- data/test/html/test_document_encoding.rb +0 -138
- data/test/html/test_document_fragment.rb +0 -261
- 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 -196
- data/test/html/test_node_encoding.rb +0 -27
- data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +0 -14
- data/test/namespaces/test_namespaces_in_builder_doc.rb +0 -75
- data/test/namespaces/test_namespaces_in_created_doc.rb +0 -75
- data/test/namespaces/test_namespaces_in_parsed_doc.rb +0 -66
- data/test/test_convert_xpath.rb +0 -135
- data/test/test_css_cache.rb +0 -45
- data/test/test_encoding_handler.rb +0 -46
- data/test/test_memory_leak.rb +0 -156
- data/test/test_nokogiri.rb +0 -132
- data/test/test_reader.rb +0 -555
- data/test/test_soap4r_sax.rb +0 -52
- data/test/test_xslt_transforms.rb +0 -254
- 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 -366
- data/test/xml/sax/test_parser_context.rb +0 -106
- data/test/xml/sax/test_push_parser.rb +0 -157
- data/test/xml/test_attr.rb +0 -64
- data/test/xml/test_attribute_decl.rb +0 -86
- data/test/xml/test_builder.rb +0 -306
- data/test/xml/test_c14n.rb +0 -151
- data/test/xml/test_cdata.rb +0 -48
- data/test/xml/test_comment.rb +0 -29
- data/test/xml/test_document.rb +0 -828
- data/test/xml/test_document_encoding.rb +0 -28
- data/test/xml/test_document_fragment.rb +0 -223
- data/test/xml/test_dtd.rb +0 -103
- data/test/xml/test_dtd_encoding.rb +0 -33
- 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 -245
- data/test/xml/test_namespace.rb +0 -95
- data/test/xml/test_node.rb +0 -1137
- data/test/xml/test_node_attributes.rb +0 -96
- data/test/xml/test_node_encoding.rb +0 -107
- data/test/xml/test_node_inheritance.rb +0 -32
- data/test/xml/test_node_reparenting.rb +0 -374
- data/test/xml/test_node_set.rb +0 -755
- data/test/xml/test_parse_options.rb +0 -64
- data/test/xml/test_processing_instruction.rb +0 -30
- data/test/xml/test_reader_encoding.rb +0 -142
- data/test/xml/test_relax_ng.rb +0 -60
- data/test/xml/test_schema.rb +0 -103
- data/test/xml/test_syntax_error.rb +0 -12
- data/test/xml/test_text.rb +0 -45
- data/test/xml/test_unparented_node.rb +0 -422
- data/test/xml/test_xinclude.rb +0 -83
- data/test/xml/test_xpath.rb +0 -295
- data/test/xslt/test_custom_functions.rb +0 -133
- data/test/xslt/test_exception_handling.rb +0 -37
- data/test_all +0 -81
data/ext/nokogiri/xml_reader.c
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
2
|
|
3
|
-
|
3
|
+
VALUE cNokogiriXmlReader;
|
4
|
+
|
5
|
+
static void
|
6
|
+
dealloc(xmlTextReaderPtr reader)
|
4
7
|
{
|
5
8
|
NOKOGIRI_DEBUG_START(reader);
|
6
9
|
xmlFreeTextReader(reader);
|
7
10
|
NOKOGIRI_DEBUG_END(reader);
|
8
11
|
}
|
9
12
|
|
10
|
-
static int
|
13
|
+
static int
|
14
|
+
has_attributes(xmlTextReaderPtr reader)
|
11
15
|
{
|
12
16
|
/*
|
13
17
|
* this implementation of xmlTextReaderHasAttributes explicitly includes
|
@@ -16,47 +20,39 @@ static int has_attributes(xmlTextReaderPtr reader)
|
|
16
20
|
*/
|
17
21
|
xmlNodePtr node ;
|
18
22
|
node = xmlTextReaderCurrentNode(reader);
|
19
|
-
if (node == NULL)
|
20
|
-
return(0);
|
23
|
+
if (node == NULL) {
|
24
|
+
return (0);
|
25
|
+
}
|
21
26
|
|
22
27
|
if ((node->type == XML_ELEMENT_NODE) &&
|
23
|
-
((node->properties != NULL) || (node->nsDef != NULL)))
|
24
|
-
return(1);
|
25
|
-
|
28
|
+
((node->properties != NULL) || (node->nsDef != NULL))) {
|
29
|
+
return (1);
|
30
|
+
}
|
31
|
+
return (0);
|
26
32
|
}
|
27
33
|
|
28
|
-
static void
|
34
|
+
static void
|
35
|
+
Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
|
29
36
|
{
|
30
37
|
xmlNsPtr ns;
|
31
|
-
|
32
|
-
char *key ;
|
33
|
-
size_t keylen ;
|
38
|
+
VALUE key;
|
34
39
|
|
35
|
-
if (node->type != XML_ELEMENT_NODE) return ;
|
40
|
+
if (node->type != XML_ELEMENT_NODE) { return ; }
|
36
41
|
|
37
42
|
ns = node->nsDef;
|
38
43
|
while (ns != NULL) {
|
39
44
|
|
40
|
-
|
41
|
-
if (keylen > XMLNS_BUFFER_LEN) {
|
42
|
-
key = (char*)malloc(keylen) ;
|
43
|
-
} else {
|
44
|
-
key = buffer ;
|
45
|
-
}
|
46
|
-
|
45
|
+
key = rb_enc_str_new_cstr(XMLNS_PREFIX, rb_utf8_encoding());
|
47
46
|
if (ns->prefix) {
|
48
|
-
|
49
|
-
|
50
|
-
sprintf(key, "%s", XMLNS_PREFIX);
|
47
|
+
rb_str_cat_cstr(key, ":");
|
48
|
+
rb_str_cat_cstr(key, (const char *)ns->prefix);
|
51
49
|
}
|
52
50
|
|
51
|
+
key = rb_str_conv_enc(key, rb_utf8_encoding(), rb_default_internal_encoding());
|
53
52
|
rb_hash_aset(attr_hash,
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
if (key != buffer) {
|
58
|
-
free(key);
|
59
|
-
}
|
53
|
+
key,
|
54
|
+
(ns->href ? NOKOGIRI_STR_NEW2(ns->href) : Qnil)
|
55
|
+
);
|
60
56
|
ns = ns->next ;
|
61
57
|
}
|
62
58
|
}
|
@@ -68,15 +64,16 @@ static void Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
|
|
68
64
|
*
|
69
65
|
* Was an attribute generated from the default value in the DTD or schema?
|
70
66
|
*/
|
71
|
-
static VALUE
|
67
|
+
static VALUE
|
68
|
+
default_eh(VALUE self)
|
72
69
|
{
|
73
70
|
xmlTextReaderPtr reader;
|
74
71
|
int eh;
|
75
72
|
|
76
73
|
Data_Get_Struct(self, xmlTextReader, reader);
|
77
74
|
eh = xmlTextReaderIsDefault(reader);
|
78
|
-
if(eh == 0) return Qfalse;
|
79
|
-
if(eh == 1) return Qtrue;
|
75
|
+
if (eh == 0) { return Qfalse; }
|
76
|
+
if (eh == 1) { return Qtrue; }
|
80
77
|
|
81
78
|
return Qnil;
|
82
79
|
}
|
@@ -87,15 +84,16 @@ static VALUE default_eh(VALUE self)
|
|
87
84
|
*
|
88
85
|
* Does this node have a text value?
|
89
86
|
*/
|
90
|
-
static VALUE
|
87
|
+
static VALUE
|
88
|
+
value_eh(VALUE self)
|
91
89
|
{
|
92
90
|
xmlTextReaderPtr reader;
|
93
91
|
int eh;
|
94
92
|
|
95
93
|
Data_Get_Struct(self, xmlTextReader, reader);
|
96
94
|
eh = xmlTextReaderHasValue(reader);
|
97
|
-
if(eh == 0) return Qfalse;
|
98
|
-
if(eh == 1) return Qtrue;
|
95
|
+
if (eh == 0) { return Qfalse; }
|
96
|
+
if (eh == 1) { return Qtrue; }
|
99
97
|
|
100
98
|
return Qnil;
|
101
99
|
}
|
@@ -106,15 +104,16 @@ static VALUE value_eh(VALUE self)
|
|
106
104
|
*
|
107
105
|
* Does this node have attributes?
|
108
106
|
*/
|
109
|
-
static VALUE
|
107
|
+
static VALUE
|
108
|
+
attributes_eh(VALUE self)
|
110
109
|
{
|
111
110
|
xmlTextReaderPtr reader;
|
112
111
|
int eh;
|
113
112
|
|
114
113
|
Data_Get_Struct(self, xmlTextReader, reader);
|
115
114
|
eh = has_attributes(reader);
|
116
|
-
if(eh == 0) return Qfalse;
|
117
|
-
if(eh == 1) return Qtrue;
|
115
|
+
if (eh == 0) { return Qfalse; }
|
116
|
+
if (eh == 1) { return Qtrue; }
|
118
117
|
|
119
118
|
return Qnil;
|
120
119
|
}
|
@@ -125,7 +124,8 @@ static VALUE attributes_eh(VALUE self)
|
|
125
124
|
*
|
126
125
|
* Get a hash of namespaces for this Node
|
127
126
|
*/
|
128
|
-
static VALUE
|
127
|
+
static VALUE
|
128
|
+
namespaces(VALUE self)
|
129
129
|
{
|
130
130
|
xmlTextReaderPtr reader;
|
131
131
|
xmlNodePtr ptr;
|
@@ -135,11 +135,12 @@ static VALUE namespaces(VALUE self)
|
|
135
135
|
|
136
136
|
attr = rb_hash_new() ;
|
137
137
|
|
138
|
-
if (! has_attributes(reader))
|
138
|
+
if (! has_attributes(reader)) {
|
139
139
|
return attr ;
|
140
|
+
}
|
140
141
|
|
141
142
|
ptr = xmlTextReaderExpand(reader);
|
142
|
-
if(ptr == NULL) return Qnil;
|
143
|
+
if (ptr == NULL) { return Qnil; }
|
143
144
|
|
144
145
|
Nokogiri_xml_node_namespaces(ptr, attr);
|
145
146
|
|
@@ -147,30 +148,37 @@ static VALUE namespaces(VALUE self)
|
|
147
148
|
}
|
148
149
|
|
149
150
|
/*
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
* Get a list of attributes for this Node
|
151
|
+
:call-seq: attribute_nodes() → Array<Nokogiri::XML::Attr>
|
152
|
+
|
153
|
+
Get the attributes of the current node as an Array of Attr
|
154
154
|
*/
|
155
|
-
static VALUE
|
155
|
+
static VALUE
|
156
|
+
rb_xml_reader_attribute_nodes(VALUE rb_reader)
|
156
157
|
{
|
157
|
-
xmlTextReaderPtr
|
158
|
-
xmlNodePtr
|
159
|
-
VALUE
|
158
|
+
xmlTextReaderPtr c_reader;
|
159
|
+
xmlNodePtr c_node;
|
160
|
+
VALUE attr_nodes;
|
161
|
+
int j;
|
160
162
|
|
161
|
-
Data_Get_Struct(
|
163
|
+
Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
|
162
164
|
|
163
|
-
|
165
|
+
if (! has_attributes(c_reader)) {
|
166
|
+
return rb_ary_new() ;
|
167
|
+
}
|
164
168
|
|
165
|
-
|
166
|
-
|
169
|
+
c_node = xmlTextReaderExpand(c_reader);
|
170
|
+
if (c_node == NULL) {
|
171
|
+
return Qnil;
|
172
|
+
}
|
167
173
|
|
168
|
-
|
169
|
-
if(ptr == NULL) return Qnil;
|
174
|
+
attr_nodes = noko_xml_node_attrs(c_node);
|
170
175
|
|
171
|
-
|
176
|
+
/* ensure that the Reader won't be GCed as long as a node is referenced */
|
177
|
+
for (j = 0 ; j < RARRAY_LEN(attr_nodes) ; j++) {
|
178
|
+
rb_iv_set(rb_ary_entry(attr_nodes, j), "@reader", rb_reader);
|
179
|
+
}
|
172
180
|
|
173
|
-
return
|
181
|
+
return attr_nodes;
|
174
182
|
}
|
175
183
|
|
176
184
|
/*
|
@@ -179,7 +187,8 @@ static VALUE attribute_nodes(VALUE self)
|
|
179
187
|
*
|
180
188
|
* Get the value of attribute at +index+
|
181
189
|
*/
|
182
|
-
static VALUE
|
190
|
+
static VALUE
|
191
|
+
attribute_at(VALUE self, VALUE index)
|
183
192
|
{
|
184
193
|
xmlTextReaderPtr reader;
|
185
194
|
xmlChar *value;
|
@@ -187,14 +196,14 @@ static VALUE attribute_at(VALUE self, VALUE index)
|
|
187
196
|
|
188
197
|
Data_Get_Struct(self, xmlTextReader, reader);
|
189
198
|
|
190
|
-
if(NIL_P(index)) return Qnil;
|
199
|
+
if (NIL_P(index)) { return Qnil; }
|
191
200
|
index = rb_Integer(index);
|
192
201
|
|
193
202
|
value = xmlTextReaderGetAttributeNo(
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
if(value == NULL) return Qnil;
|
203
|
+
reader,
|
204
|
+
(int)NUM2INT(index)
|
205
|
+
);
|
206
|
+
if (value == NULL) { return Qnil; }
|
198
207
|
|
199
208
|
rb_value = NOKOGIRI_STR_NEW2(value);
|
200
209
|
xmlFree(value);
|
@@ -207,7 +216,8 @@ static VALUE attribute_at(VALUE self, VALUE index)
|
|
207
216
|
*
|
208
217
|
* Get the value of attribute named +name+
|
209
218
|
*/
|
210
|
-
static VALUE
|
219
|
+
static VALUE
|
220
|
+
reader_attribute(VALUE self, VALUE name)
|
211
221
|
{
|
212
222
|
xmlTextReaderPtr reader;
|
213
223
|
xmlChar *value ;
|
@@ -215,24 +225,11 @@ static VALUE reader_attribute(VALUE self, VALUE name)
|
|
215
225
|
|
216
226
|
Data_Get_Struct(self, xmlTextReader, reader);
|
217
227
|
|
218
|
-
if(NIL_P(name)) return Qnil;
|
228
|
+
if (NIL_P(name)) { return Qnil; }
|
219
229
|
name = StringValue(name) ;
|
220
230
|
|
221
|
-
value = xmlTextReaderGetAttribute(reader, (xmlChar*)
|
222
|
-
if(value == NULL) {
|
223
|
-
/* this section is an attempt to workaround older versions of libxml that
|
224
|
-
don't handle namespaces properly in all attribute-and-friends functions */
|
225
|
-
xmlChar *prefix = NULL ;
|
226
|
-
xmlChar *localname = xmlSplitQName2((xmlChar*)StringValuePtr(name), &prefix);
|
227
|
-
if (localname != NULL) {
|
228
|
-
value = xmlTextReaderLookupNamespace(reader, localname);
|
229
|
-
xmlFree(localname) ;
|
230
|
-
} else {
|
231
|
-
value = xmlTextReaderLookupNamespace(reader, prefix);
|
232
|
-
}
|
233
|
-
xmlFree(prefix);
|
234
|
-
}
|
235
|
-
if(value == NULL) return Qnil;
|
231
|
+
value = xmlTextReaderGetAttribute(reader, (xmlChar *)StringValueCStr(name));
|
232
|
+
if (value == NULL) { return Qnil; }
|
236
233
|
|
237
234
|
rb_value = NOKOGIRI_STR_NEW2(value);
|
238
235
|
xmlFree(value);
|
@@ -245,14 +242,15 @@ static VALUE reader_attribute(VALUE self, VALUE name)
|
|
245
242
|
*
|
246
243
|
* Get the number of attributes for the current node
|
247
244
|
*/
|
248
|
-
static VALUE
|
245
|
+
static VALUE
|
246
|
+
attribute_count(VALUE self)
|
249
247
|
{
|
250
248
|
xmlTextReaderPtr reader;
|
251
249
|
int count;
|
252
250
|
|
253
251
|
Data_Get_Struct(self, xmlTextReader, reader);
|
254
252
|
count = xmlTextReaderAttributeCount(reader);
|
255
|
-
if(count == -1) return Qnil;
|
253
|
+
if (count == -1) { return Qnil; }
|
256
254
|
|
257
255
|
return INT2NUM((long)count);
|
258
256
|
}
|
@@ -263,14 +261,15 @@ static VALUE attribute_count(VALUE self)
|
|
263
261
|
*
|
264
262
|
* Get the depth of the node
|
265
263
|
*/
|
266
|
-
static VALUE
|
264
|
+
static VALUE
|
265
|
+
depth(VALUE self)
|
267
266
|
{
|
268
267
|
xmlTextReaderPtr reader;
|
269
268
|
int depth;
|
270
269
|
|
271
270
|
Data_Get_Struct(self, xmlTextReader, reader);
|
272
271
|
depth = xmlTextReaderDepth(reader);
|
273
|
-
if(depth == -1) return Qnil;
|
272
|
+
if (depth == -1) { return Qnil; }
|
274
273
|
|
275
274
|
return INT2NUM((long)depth);
|
276
275
|
}
|
@@ -281,14 +280,15 @@ static VALUE depth(VALUE self)
|
|
281
280
|
*
|
282
281
|
* Get the XML version of the document being read
|
283
282
|
*/
|
284
|
-
static VALUE
|
283
|
+
static VALUE
|
284
|
+
xml_version(VALUE self)
|
285
285
|
{
|
286
286
|
xmlTextReaderPtr reader;
|
287
287
|
const char *version;
|
288
288
|
|
289
289
|
Data_Get_Struct(self, xmlTextReader, reader);
|
290
290
|
version = (const char *)xmlTextReaderConstXmlVersion(reader);
|
291
|
-
if(version == NULL) return Qnil;
|
291
|
+
if (version == NULL) { return Qnil; }
|
292
292
|
|
293
293
|
return NOKOGIRI_STR_NEW2(version);
|
294
294
|
}
|
@@ -299,14 +299,15 @@ static VALUE xml_version(VALUE self)
|
|
299
299
|
*
|
300
300
|
* Get the xml:lang scope within which the node resides.
|
301
301
|
*/
|
302
|
-
static VALUE
|
302
|
+
static VALUE
|
303
|
+
lang(VALUE self)
|
303
304
|
{
|
304
305
|
xmlTextReaderPtr reader;
|
305
306
|
const char *lang;
|
306
307
|
|
307
308
|
Data_Get_Struct(self, xmlTextReader, reader);
|
308
309
|
lang = (const char *)xmlTextReaderConstXmlLang(reader);
|
309
|
-
if(lang == NULL) return Qnil;
|
310
|
+
if (lang == NULL) { return Qnil; }
|
310
311
|
|
311
312
|
return NOKOGIRI_STR_NEW2(lang);
|
312
313
|
}
|
@@ -317,14 +318,15 @@ static VALUE lang(VALUE self)
|
|
317
318
|
*
|
318
319
|
* Get the text value of the node if present. Returns a utf-8 encoded string.
|
319
320
|
*/
|
320
|
-
static VALUE
|
321
|
+
static VALUE
|
322
|
+
value(VALUE self)
|
321
323
|
{
|
322
324
|
xmlTextReaderPtr reader;
|
323
325
|
const char *value;
|
324
326
|
|
325
327
|
Data_Get_Struct(self, xmlTextReader, reader);
|
326
328
|
value = (const char *)xmlTextReaderConstValue(reader);
|
327
|
-
if(value == NULL) return Qnil;
|
329
|
+
if (value == NULL) { return Qnil; }
|
328
330
|
|
329
331
|
return NOKOGIRI_STR_NEW2(value);
|
330
332
|
}
|
@@ -335,14 +337,15 @@ static VALUE value(VALUE self)
|
|
335
337
|
*
|
336
338
|
* Get the shorthand reference to the namespace associated with the node.
|
337
339
|
*/
|
338
|
-
static VALUE
|
340
|
+
static VALUE
|
341
|
+
prefix(VALUE self)
|
339
342
|
{
|
340
343
|
xmlTextReaderPtr reader;
|
341
344
|
const char *prefix;
|
342
345
|
|
343
346
|
Data_Get_Struct(self, xmlTextReader, reader);
|
344
347
|
prefix = (const char *)xmlTextReaderConstPrefix(reader);
|
345
|
-
if(prefix == NULL) return Qnil;
|
348
|
+
if (prefix == NULL) { return Qnil; }
|
346
349
|
|
347
350
|
return NOKOGIRI_STR_NEW2(prefix);
|
348
351
|
}
|
@@ -353,14 +356,15 @@ static VALUE prefix(VALUE self)
|
|
353
356
|
*
|
354
357
|
* Get the URI defining the namespace associated with the node
|
355
358
|
*/
|
356
|
-
static VALUE
|
359
|
+
static VALUE
|
360
|
+
namespace_uri(VALUE self)
|
357
361
|
{
|
358
362
|
xmlTextReaderPtr reader;
|
359
363
|
const char *uri;
|
360
364
|
|
361
365
|
Data_Get_Struct(self, xmlTextReader, reader);
|
362
366
|
uri = (const char *)xmlTextReaderConstNamespaceUri(reader);
|
363
|
-
if(uri == NULL) return Qnil;
|
367
|
+
if (uri == NULL) { return Qnil; }
|
364
368
|
|
365
369
|
return NOKOGIRI_STR_NEW2(uri);
|
366
370
|
}
|
@@ -371,14 +375,15 @@ static VALUE namespace_uri(VALUE self)
|
|
371
375
|
*
|
372
376
|
* Get the local name of the node
|
373
377
|
*/
|
374
|
-
static VALUE
|
378
|
+
static VALUE
|
379
|
+
local_name(VALUE self)
|
375
380
|
{
|
376
381
|
xmlTextReaderPtr reader;
|
377
382
|
const char *name;
|
378
383
|
|
379
384
|
Data_Get_Struct(self, xmlTextReader, reader);
|
380
385
|
name = (const char *)xmlTextReaderConstLocalName(reader);
|
381
|
-
if(name == NULL) return Qnil;
|
386
|
+
if (name == NULL) { return Qnil; }
|
382
387
|
|
383
388
|
return NOKOGIRI_STR_NEW2(name);
|
384
389
|
}
|
@@ -389,14 +394,15 @@ static VALUE local_name(VALUE self)
|
|
389
394
|
*
|
390
395
|
* Get the name of the node. Returns a utf-8 encoded string.
|
391
396
|
*/
|
392
|
-
static VALUE
|
397
|
+
static VALUE
|
398
|
+
name(VALUE self)
|
393
399
|
{
|
394
400
|
xmlTextReaderPtr reader;
|
395
401
|
const char *name;
|
396
402
|
|
397
403
|
Data_Get_Struct(self, xmlTextReader, reader);
|
398
404
|
name = (const char *)xmlTextReaderConstName(reader);
|
399
|
-
if(name == NULL) return Qnil;
|
405
|
+
if (name == NULL) { return Qnil; }
|
400
406
|
|
401
407
|
return NOKOGIRI_STR_NEW2(name);
|
402
408
|
}
|
@@ -407,16 +413,24 @@ static VALUE name(VALUE self)
|
|
407
413
|
*
|
408
414
|
* Get the xml:base of the node
|
409
415
|
*/
|
410
|
-
static VALUE
|
416
|
+
static VALUE
|
417
|
+
rb_xml_reader_base_uri(VALUE rb_reader)
|
411
418
|
{
|
412
|
-
|
413
|
-
|
419
|
+
VALUE rb_base_uri;
|
420
|
+
xmlTextReaderPtr c_reader;
|
421
|
+
xmlChar *c_base_uri;
|
414
422
|
|
415
|
-
Data_Get_Struct(
|
416
|
-
|
417
|
-
|
423
|
+
Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
|
424
|
+
|
425
|
+
c_base_uri = xmlTextReaderBaseUri(c_reader);
|
426
|
+
if (c_base_uri == NULL) {
|
427
|
+
return Qnil;
|
428
|
+
}
|
418
429
|
|
419
|
-
|
430
|
+
rb_base_uri = NOKOGIRI_STR_NEW2(c_base_uri);
|
431
|
+
xmlFree(c_base_uri);
|
432
|
+
|
433
|
+
return rb_base_uri;
|
420
434
|
}
|
421
435
|
|
422
436
|
/*
|
@@ -425,7 +439,8 @@ static VALUE base_uri(VALUE self)
|
|
425
439
|
*
|
426
440
|
* Get the state of the reader
|
427
441
|
*/
|
428
|
-
static VALUE
|
442
|
+
static VALUE
|
443
|
+
state(VALUE self)
|
429
444
|
{
|
430
445
|
xmlTextReaderPtr reader;
|
431
446
|
Data_Get_Struct(self, xmlTextReader, reader);
|
@@ -438,7 +453,8 @@ static VALUE state(VALUE self)
|
|
438
453
|
*
|
439
454
|
* Get the type of readers current node
|
440
455
|
*/
|
441
|
-
static VALUE
|
456
|
+
static VALUE
|
457
|
+
node_type(VALUE self)
|
442
458
|
{
|
443
459
|
xmlTextReaderPtr reader;
|
444
460
|
Data_Get_Struct(self, xmlTextReader, reader);
|
@@ -451,7 +467,8 @@ static VALUE node_type(VALUE self)
|
|
451
467
|
*
|
452
468
|
* Move the Reader forward through the XML document.
|
453
469
|
*/
|
454
|
-
static VALUE
|
470
|
+
static VALUE
|
471
|
+
read_more(VALUE self)
|
455
472
|
{
|
456
473
|
xmlTextReaderPtr reader;
|
457
474
|
xmlErrorPtr error;
|
@@ -466,14 +483,15 @@ static VALUE read_more(VALUE self)
|
|
466
483
|
ret = xmlTextReaderRead(reader);
|
467
484
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
468
485
|
|
469
|
-
if(ret == 1) return self;
|
470
|
-
if(ret == 0) return Qnil;
|
486
|
+
if (ret == 1) { return self; }
|
487
|
+
if (ret == 0) { return Qnil; }
|
471
488
|
|
472
489
|
error = xmlGetLastError();
|
473
|
-
if(error)
|
474
|
-
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(
|
475
|
-
else
|
490
|
+
if (error) {
|
491
|
+
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
492
|
+
} else {
|
476
493
|
rb_raise(rb_eRuntimeError, "Error pulling: %d", ret);
|
494
|
+
}
|
477
495
|
|
478
496
|
return Qnil;
|
479
497
|
}
|
@@ -485,10 +503,11 @@ static VALUE read_more(VALUE self)
|
|
485
503
|
* Read the contents of the current node, including child nodes and markup.
|
486
504
|
* Returns a utf-8 encoded string.
|
487
505
|
*/
|
488
|
-
static VALUE
|
506
|
+
static VALUE
|
507
|
+
inner_xml(VALUE self)
|
489
508
|
{
|
490
509
|
xmlTextReaderPtr reader;
|
491
|
-
xmlChar*
|
510
|
+
xmlChar *value;
|
492
511
|
VALUE str;
|
493
512
|
|
494
513
|
Data_Get_Struct(self, xmlTextReader, reader);
|
@@ -496,8 +515,8 @@ static VALUE inner_xml(VALUE self)
|
|
496
515
|
value = xmlTextReaderReadInnerXml(reader);
|
497
516
|
|
498
517
|
str = Qnil;
|
499
|
-
if(value) {
|
500
|
-
str = NOKOGIRI_STR_NEW2((char*)value);
|
518
|
+
if (value) {
|
519
|
+
str = NOKOGIRI_STR_NEW2((char *)value);
|
501
520
|
xmlFree(value);
|
502
521
|
}
|
503
522
|
|
@@ -511,7 +530,8 @@ static VALUE inner_xml(VALUE self)
|
|
511
530
|
* Read the current node and its contents, including child nodes and markup.
|
512
531
|
* Returns a utf-8 encoded string.
|
513
532
|
*/
|
514
|
-
static VALUE
|
533
|
+
static VALUE
|
534
|
+
outer_xml(VALUE self)
|
515
535
|
{
|
516
536
|
xmlTextReaderPtr reader;
|
517
537
|
xmlChar *value;
|
@@ -521,8 +541,8 @@ static VALUE outer_xml(VALUE self)
|
|
521
541
|
|
522
542
|
value = xmlTextReaderReadOuterXml(reader);
|
523
543
|
|
524
|
-
if(value) {
|
525
|
-
str = NOKOGIRI_STR_NEW2((char*)value);
|
544
|
+
if (value) {
|
545
|
+
str = NOKOGIRI_STR_NEW2((char *)value);
|
526
546
|
xmlFree(value);
|
527
547
|
}
|
528
548
|
return str;
|
@@ -534,31 +554,32 @@ static VALUE outer_xml(VALUE self)
|
|
534
554
|
*
|
535
555
|
* Create a new reader that parses +string+
|
536
556
|
*/
|
537
|
-
static VALUE
|
557
|
+
static VALUE
|
558
|
+
from_memory(int argc, VALUE *argv, VALUE klass)
|
538
559
|
{
|
539
560
|
VALUE rb_buffer, rb_url, encoding, rb_options;
|
540
561
|
xmlTextReaderPtr reader;
|
541
|
-
const char *
|
542
|
-
const char *
|
562
|
+
const char *c_url = NULL;
|
563
|
+
const char *c_encoding = NULL;
|
543
564
|
int c_options = 0;
|
544
565
|
VALUE rb_reader, args[3];
|
545
566
|
|
546
567
|
rb_scan_args(argc, argv, "13", &rb_buffer, &rb_url, &encoding, &rb_options);
|
547
568
|
|
548
|
-
if (!RTEST(rb_buffer)) rb_raise(rb_eArgError, "string cannot be nil");
|
549
|
-
if (RTEST(rb_url)) c_url =
|
550
|
-
if (RTEST(encoding)) c_encoding =
|
551
|
-
if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options);
|
569
|
+
if (!RTEST(rb_buffer)) { rb_raise(rb_eArgError, "string cannot be nil"); }
|
570
|
+
if (RTEST(rb_url)) { c_url = StringValueCStr(rb_url); }
|
571
|
+
if (RTEST(encoding)) { c_encoding = StringValueCStr(encoding); }
|
572
|
+
if (RTEST(rb_options)) { c_options = (int)NUM2INT(rb_options); }
|
552
573
|
|
553
574
|
reader = xmlReaderForMemory(
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
if(reader == NULL) {
|
575
|
+
StringValuePtr(rb_buffer),
|
576
|
+
(int)RSTRING_LEN(rb_buffer),
|
577
|
+
c_url,
|
578
|
+
c_encoding,
|
579
|
+
c_options
|
580
|
+
);
|
581
|
+
|
582
|
+
if (reader == NULL) {
|
562
583
|
xmlFreeTextReader(reader);
|
563
584
|
rb_raise(rb_eRuntimeError, "couldn't create a parser");
|
564
585
|
}
|
@@ -578,32 +599,33 @@ static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
|
|
578
599
|
*
|
579
600
|
* Create a new reader that parses +io+
|
580
601
|
*/
|
581
|
-
static VALUE
|
602
|
+
static VALUE
|
603
|
+
from_io(int argc, VALUE *argv, VALUE klass)
|
582
604
|
{
|
583
605
|
VALUE rb_io, rb_url, encoding, rb_options;
|
584
606
|
xmlTextReaderPtr reader;
|
585
|
-
const char *
|
586
|
-
const char *
|
607
|
+
const char *c_url = NULL;
|
608
|
+
const char *c_encoding = NULL;
|
587
609
|
int c_options = 0;
|
588
610
|
VALUE rb_reader, args[3];
|
589
611
|
|
590
612
|
rb_scan_args(argc, argv, "13", &rb_io, &rb_url, &encoding, &rb_options);
|
591
613
|
|
592
|
-
if (!RTEST(rb_io)) rb_raise(rb_eArgError, "io cannot be nil");
|
593
|
-
if (RTEST(rb_url)) c_url =
|
594
|
-
if (RTEST(encoding)) c_encoding =
|
595
|
-
if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options);
|
614
|
+
if (!RTEST(rb_io)) { rb_raise(rb_eArgError, "io cannot be nil"); }
|
615
|
+
if (RTEST(rb_url)) { c_url = StringValueCStr(rb_url); }
|
616
|
+
if (RTEST(encoding)) { c_encoding = StringValueCStr(encoding); }
|
617
|
+
if (RTEST(rb_options)) { c_options = (int)NUM2INT(rb_options); }
|
596
618
|
|
597
619
|
reader = xmlReaderForIO(
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
if(reader == NULL) {
|
620
|
+
(xmlInputReadCallback)noko_io_read,
|
621
|
+
(xmlInputCloseCallback)noko_io_close,
|
622
|
+
(void *)rb_io,
|
623
|
+
c_url,
|
624
|
+
c_encoding,
|
625
|
+
c_options
|
626
|
+
);
|
627
|
+
|
628
|
+
if (reader == NULL) {
|
607
629
|
xmlFreeTextReader(reader);
|
608
630
|
rb_raise(rb_eRuntimeError, "couldn't create a parser");
|
609
631
|
}
|
@@ -623,59 +645,75 @@ static VALUE from_io(int argc, VALUE *argv, VALUE klass)
|
|
623
645
|
*
|
624
646
|
* Returns true if the current node is empty, otherwise false.
|
625
647
|
*/
|
626
|
-
static VALUE
|
648
|
+
static VALUE
|
649
|
+
empty_element_p(VALUE self)
|
627
650
|
{
|
628
651
|
xmlTextReaderPtr reader;
|
629
652
|
|
630
653
|
Data_Get_Struct(self, xmlTextReader, reader);
|
631
654
|
|
632
|
-
if(xmlTextReaderIsEmptyElement(reader))
|
655
|
+
if (xmlTextReaderIsEmptyElement(reader)) {
|
633
656
|
return Qtrue;
|
657
|
+
}
|
634
658
|
|
635
659
|
return Qfalse;
|
636
660
|
}
|
637
661
|
|
638
|
-
VALUE
|
639
|
-
|
640
|
-
void init_xml_reader()
|
662
|
+
static VALUE
|
663
|
+
rb_xml_reader_encoding(VALUE rb_reader)
|
641
664
|
{
|
642
|
-
|
643
|
-
|
665
|
+
xmlTextReaderPtr c_reader;
|
666
|
+
const char *parser_encoding;
|
667
|
+
VALUE constructor_encoding;
|
644
668
|
|
669
|
+
constructor_encoding = rb_iv_get(rb_reader, "@encoding");
|
670
|
+
if (RTEST(constructor_encoding)) {
|
671
|
+
return constructor_encoding;
|
672
|
+
}
|
673
|
+
|
674
|
+
Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
|
675
|
+
parser_encoding = (const char *)xmlTextReaderConstEncoding(c_reader);
|
676
|
+
if (parser_encoding == NULL) { return Qnil; }
|
677
|
+
return NOKOGIRI_STR_NEW2(parser_encoding);
|
678
|
+
}
|
679
|
+
|
680
|
+
void
|
681
|
+
noko_init_xml_reader()
|
682
|
+
{
|
645
683
|
/*
|
646
684
|
* The Reader parser allows you to effectively pull parse an XML document.
|
647
685
|
* Once instantiated, call Nokogiri::XML::Reader#each to iterate over each
|
648
686
|
* node. Note that you may only iterate over the document once!
|
649
687
|
*/
|
650
|
-
|
651
|
-
|
652
|
-
cNokogiriXmlReader
|
653
|
-
|
654
|
-
rb_define_singleton_method(
|
655
|
-
rb_define_singleton_method(
|
656
|
-
|
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
|
-
rb_define_method(
|
667
|
-
rb_define_method(
|
668
|
-
rb_define_method(
|
669
|
-
rb_define_method(
|
670
|
-
rb_define_method(
|
671
|
-
rb_define_method(
|
672
|
-
rb_define_method(
|
673
|
-
rb_define_method(
|
674
|
-
rb_define_method(
|
675
|
-
rb_define_method(
|
676
|
-
rb_define_method(
|
677
|
-
rb_define_method(
|
678
|
-
rb_define_method(
|
679
|
-
|
680
|
-
|
688
|
+
cNokogiriXmlReader = rb_define_class_under(mNokogiriXml, "Reader", rb_cObject);
|
689
|
+
|
690
|
+
rb_undef_alloc_func(cNokogiriXmlReader);
|
691
|
+
|
692
|
+
rb_define_singleton_method(cNokogiriXmlReader, "from_memory", from_memory, -1);
|
693
|
+
rb_define_singleton_method(cNokogiriXmlReader, "from_io", from_io, -1);
|
694
|
+
|
695
|
+
rb_define_method(cNokogiriXmlReader, "attribute", reader_attribute, 1);
|
696
|
+
rb_define_method(cNokogiriXmlReader, "attribute_at", attribute_at, 1);
|
697
|
+
rb_define_method(cNokogiriXmlReader, "attribute_count", attribute_count, 0);
|
698
|
+
rb_define_method(cNokogiriXmlReader, "attribute_nodes", rb_xml_reader_attribute_nodes, 0);
|
699
|
+
rb_define_method(cNokogiriXmlReader, "attributes?", attributes_eh, 0);
|
700
|
+
rb_define_method(cNokogiriXmlReader, "base_uri", rb_xml_reader_base_uri, 0);
|
701
|
+
rb_define_method(cNokogiriXmlReader, "default?", default_eh, 0);
|
702
|
+
rb_define_method(cNokogiriXmlReader, "depth", depth, 0);
|
703
|
+
rb_define_method(cNokogiriXmlReader, "empty_element?", empty_element_p, 0);
|
704
|
+
rb_define_method(cNokogiriXmlReader, "encoding", rb_xml_reader_encoding, 0);
|
705
|
+
rb_define_method(cNokogiriXmlReader, "inner_xml", inner_xml, 0);
|
706
|
+
rb_define_method(cNokogiriXmlReader, "lang", lang, 0);
|
707
|
+
rb_define_method(cNokogiriXmlReader, "local_name", local_name, 0);
|
708
|
+
rb_define_method(cNokogiriXmlReader, "name", name, 0);
|
709
|
+
rb_define_method(cNokogiriXmlReader, "namespace_uri", namespace_uri, 0);
|
710
|
+
rb_define_method(cNokogiriXmlReader, "namespaces", namespaces, 0);
|
711
|
+
rb_define_method(cNokogiriXmlReader, "node_type", node_type, 0);
|
712
|
+
rb_define_method(cNokogiriXmlReader, "outer_xml", outer_xml, 0);
|
713
|
+
rb_define_method(cNokogiriXmlReader, "prefix", prefix, 0);
|
714
|
+
rb_define_method(cNokogiriXmlReader, "read", read_more, 0);
|
715
|
+
rb_define_method(cNokogiriXmlReader, "state", state, 0);
|
716
|
+
rb_define_method(cNokogiriXmlReader, "value", value, 0);
|
717
|
+
rb_define_method(cNokogiriXmlReader, "value?", value_eh, 0);
|
718
|
+
rb_define_method(cNokogiriXmlReader, "xml_version", xml_version, 0);
|
681
719
|
}
|