nokogiri 1.10.10 → 1.14.3-aarch64-linux
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 +44 -0
- data/LICENSE-DEPENDENCIES.md +1632 -1022
- data/LICENSE.md +1 -1
- data/README.md +185 -96
- data/bin/nokogiri +63 -50
- data/dependencies.yml +33 -66
- data/ext/nokogiri/depend +38 -358
- data/ext/nokogiri/extconf.rb +819 -421
- data/ext/nokogiri/gumbo.c +594 -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 +114 -0
- data/ext/nokogiri/html4_sax_push_parser.c +95 -0
- data/ext/nokogiri/include/libexslt/exslt.h +108 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +63 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +204 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +172 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +128 -0
- data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
- data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
- data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/dict.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +232 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +153 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +499 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
- data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +186 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1244 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +656 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +218 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +91 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1312 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +463 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +368 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +947 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +77 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +226 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +152 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +503 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +575 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +137 -0
- data/ext/nokogiri/include/libxslt/attributes.h +38 -0
- data/ext/nokogiri/include/libxslt/documents.h +93 -0
- data/ext/nokogiri/include/libxslt/extensions.h +262 -0
- data/ext/nokogiri/include/libxslt/extra.h +72 -0
- data/ext/nokogiri/include/libxslt/functions.h +78 -0
- data/ext/nokogiri/include/libxslt/imports.h +75 -0
- data/ext/nokogiri/include/libxslt/keys.h +53 -0
- data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
- data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
- data/ext/nokogiri/include/libxslt/pattern.h +84 -0
- data/ext/nokogiri/include/libxslt/preproc.h +43 -0
- data/ext/nokogiri/include/libxslt/security.h +104 -0
- data/ext/nokogiri/include/libxslt/templates.h +77 -0
- data/ext/nokogiri/include/libxslt/transform.h +207 -0
- data/ext/nokogiri/include/libxslt/variables.h +118 -0
- data/ext/nokogiri/include/libxslt/xslt.h +110 -0
- data/ext/nokogiri/include/libxslt/xsltInternals.h +1982 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +179 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +64 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +310 -0
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +228 -104
- data/ext/nokogiri/nokogiri.h +204 -90
- data/ext/nokogiri/test_global_handlers.c +40 -0
- data/ext/nokogiri/xml_attr.c +17 -17
- data/ext/nokogiri/xml_attribute_decl.c +22 -22
- data/ext/nokogiri/xml_cdata.c +15 -20
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +306 -225
- data/ext/nokogiri/xml_document_fragment.c +12 -16
- data/ext/nokogiri/xml_dtd.c +64 -58
- data/ext/nokogiri/xml_element_content.c +33 -28
- data/ext/nokogiri/xml_element_decl.c +26 -26
- data/ext/nokogiri/xml_encoding_handler.c +45 -20
- data/ext/nokogiri/xml_entity_decl.c +37 -35
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +136 -61
- data/ext/nokogiri/xml_node.c +1344 -672
- data/ext/nokogiri/xml_node_set.c +178 -168
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +316 -190
- data/ext/nokogiri/xml_relax_ng.c +52 -30
- data/ext/nokogiri/xml_sax_parser.c +130 -124
- data/ext/nokogiri/xml_sax_parser_context.c +110 -89
- data/ext/nokogiri/xml_sax_push_parser.c +36 -29
- data/ext/nokogiri/xml_schema.c +98 -50
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- data/ext/nokogiri/xml_text.c +14 -18
- data/ext/nokogiri/xml_xpath_context.c +263 -148
- data/ext/nokogiri/xslt_stylesheet.c +271 -178
- data/gumbo-parser/CHANGES.md +63 -0
- data/gumbo-parser/Makefile +111 -0
- data/gumbo-parser/THANKS +27 -0
- data/lib/nokogiri/2.7/nokogiri.so +0 -0
- data/lib/nokogiri/3.0/nokogiri.so +0 -0
- data/lib/nokogiri/3.1/nokogiri.so +0 -0
- data/lib/nokogiri/3.2/nokogiri.so +0 -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 +5 -3
- data/lib/nokogiri/css/tokenizer.rex +3 -2
- data/lib/nokogiri/css/xpath_visitor.rb +223 -94
- 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 +572 -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 +98 -0
- data/lib/nokogiri/html5.rb +389 -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 +3 -1
- data/lib/nokogiri/xml/builder.rb +75 -34
- 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 +93 -48
- data/lib/nokogiri/xml/dtd.rb +4 -2
- 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 +2 -0
- data/lib/nokogiri/xml/namespace.rb +45 -0
- data/lib/nokogiri/xml/node/save_options.rb +15 -8
- data/lib/nokogiri/xml/node.rb +1067 -406
- data/lib/nokogiri/xml/node_set.rb +135 -59
- 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 +27 -26
- 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 +112 -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 +29 -20
- data/lib/nokogiri.rb +48 -72
- data/lib/xsd/xmlparser/nokogiri.rb +29 -25
- metadata +146 -307
- 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 -14
- 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-Remove-script-macro-support.patch +0 -40
- data/patches/libxml2/0003-Update-entities-to-remove-handling-of-ssi.patch +0 -44
- data/patches/libxml2/0004-libxml2.la-is-in-top_builddir.patch +0 -25
- data/patches/libxml2/0005-Fix-infinite-loop-in-xmlStringLenDecodeEntities.patch +0 -32
- data/ports/archives/libxml2-2.9.10.tar.gz +0 -0
- data/ports/archives/libxslt-1.1.34.tar.gz +0 -0
data/ext/nokogiri/xml_reader.c
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
2
|
|
3
|
-
|
3
|
+
VALUE cNokogiriXmlReader;
|
4
|
+
|
5
|
+
static void
|
6
|
+
dealloc(xmlTextReaderPtr reader)
|
4
7
|
{
|
5
|
-
NOKOGIRI_DEBUG_START(reader);
|
6
8
|
xmlFreeTextReader(reader);
|
7
|
-
NOKOGIRI_DEBUG_END(reader);
|
8
9
|
}
|
9
10
|
|
10
|
-
static int
|
11
|
+
static int
|
12
|
+
has_attributes(xmlTextReaderPtr reader)
|
11
13
|
{
|
12
14
|
/*
|
13
15
|
* this implementation of xmlTextReaderHasAttributes explicitly includes
|
@@ -16,47 +18,40 @@ static int has_attributes(xmlTextReaderPtr reader)
|
|
16
18
|
*/
|
17
19
|
xmlNodePtr node ;
|
18
20
|
node = xmlTextReaderCurrentNode(reader);
|
19
|
-
if (node == NULL)
|
20
|
-
return(0);
|
21
|
+
if (node == NULL) {
|
22
|
+
return (0);
|
23
|
+
}
|
21
24
|
|
22
25
|
if ((node->type == XML_ELEMENT_NODE) &&
|
23
|
-
((node->properties != NULL) || (node->nsDef != NULL)))
|
24
|
-
return(1);
|
25
|
-
|
26
|
+
((node->properties != NULL) || (node->nsDef != NULL))) {
|
27
|
+
return (1);
|
28
|
+
}
|
29
|
+
return (0);
|
26
30
|
}
|
27
31
|
|
28
|
-
|
32
|
+
// TODO: merge this function into the `namespaces` method implementation
|
33
|
+
static void
|
34
|
+
Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
|
29
35
|
{
|
30
36
|
xmlNsPtr ns;
|
31
|
-
|
32
|
-
char *key ;
|
33
|
-
size_t keylen ;
|
37
|
+
VALUE key;
|
34
38
|
|
35
|
-
if (node->type != XML_ELEMENT_NODE) return ;
|
39
|
+
if (node->type != XML_ELEMENT_NODE) { return ; }
|
36
40
|
|
37
41
|
ns = node->nsDef;
|
38
42
|
while (ns != NULL) {
|
39
43
|
|
40
|
-
|
41
|
-
if (keylen > XMLNS_BUFFER_LEN) {
|
42
|
-
key = (char*)malloc(keylen) ;
|
43
|
-
} else {
|
44
|
-
key = buffer ;
|
45
|
-
}
|
46
|
-
|
44
|
+
key = rb_enc_str_new_cstr(XMLNS_PREFIX, rb_utf8_encoding());
|
47
45
|
if (ns->prefix) {
|
48
|
-
|
49
|
-
|
50
|
-
sprintf(key, "%s", XMLNS_PREFIX);
|
46
|
+
rb_str_cat_cstr(key, ":");
|
47
|
+
rb_str_cat_cstr(key, (const char *)ns->prefix);
|
51
48
|
}
|
52
49
|
|
50
|
+
key = rb_str_conv_enc(key, rb_utf8_encoding(), rb_default_internal_encoding());
|
53
51
|
rb_hash_aset(attr_hash,
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
if (key != buffer) {
|
58
|
-
free(key);
|
59
|
-
}
|
52
|
+
key,
|
53
|
+
(ns->href ? NOKOGIRI_STR_NEW2(ns->href) : Qnil)
|
54
|
+
);
|
60
55
|
ns = ns->next ;
|
61
56
|
}
|
62
57
|
}
|
@@ -68,15 +63,16 @@ static void Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
|
|
68
63
|
*
|
69
64
|
* Was an attribute generated from the default value in the DTD or schema?
|
70
65
|
*/
|
71
|
-
static VALUE
|
66
|
+
static VALUE
|
67
|
+
default_eh(VALUE self)
|
72
68
|
{
|
73
69
|
xmlTextReaderPtr reader;
|
74
70
|
int eh;
|
75
71
|
|
76
72
|
Data_Get_Struct(self, xmlTextReader, reader);
|
77
73
|
eh = xmlTextReaderIsDefault(reader);
|
78
|
-
if(eh == 0) return Qfalse;
|
79
|
-
if(eh == 1) return Qtrue;
|
74
|
+
if (eh == 0) { return Qfalse; }
|
75
|
+
if (eh == 1) { return Qtrue; }
|
80
76
|
|
81
77
|
return Qnil;
|
82
78
|
}
|
@@ -87,15 +83,16 @@ static VALUE default_eh(VALUE self)
|
|
87
83
|
*
|
88
84
|
* Does this node have a text value?
|
89
85
|
*/
|
90
|
-
static VALUE
|
86
|
+
static VALUE
|
87
|
+
value_eh(VALUE self)
|
91
88
|
{
|
92
89
|
xmlTextReaderPtr reader;
|
93
90
|
int eh;
|
94
91
|
|
95
92
|
Data_Get_Struct(self, xmlTextReader, reader);
|
96
93
|
eh = xmlTextReaderHasValue(reader);
|
97
|
-
if(eh == 0) return Qfalse;
|
98
|
-
if(eh == 1) return Qtrue;
|
94
|
+
if (eh == 0) { return Qfalse; }
|
95
|
+
if (eh == 1) { return Qtrue; }
|
99
96
|
|
100
97
|
return Qnil;
|
101
98
|
}
|
@@ -106,15 +103,16 @@ static VALUE value_eh(VALUE self)
|
|
106
103
|
*
|
107
104
|
* Does this node have attributes?
|
108
105
|
*/
|
109
|
-
static VALUE
|
106
|
+
static VALUE
|
107
|
+
attributes_eh(VALUE self)
|
110
108
|
{
|
111
109
|
xmlTextReaderPtr reader;
|
112
110
|
int eh;
|
113
111
|
|
114
112
|
Data_Get_Struct(self, xmlTextReader, reader);
|
115
113
|
eh = has_attributes(reader);
|
116
|
-
if(eh == 0) return Qfalse;
|
117
|
-
if(eh == 1) return Qtrue;
|
114
|
+
if (eh == 0) { return Qfalse; }
|
115
|
+
if (eh == 1) { return Qtrue; }
|
118
116
|
|
119
117
|
return Qnil;
|
120
118
|
}
|
@@ -125,52 +123,136 @@ static VALUE attributes_eh(VALUE self)
|
|
125
123
|
*
|
126
124
|
* Get a hash of namespaces for this Node
|
127
125
|
*/
|
128
|
-
static VALUE
|
126
|
+
static VALUE
|
127
|
+
rb_xml_reader_namespaces(VALUE rb_reader)
|
129
128
|
{
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
VALUE rb_namespaces = rb_hash_new() ;
|
130
|
+
xmlTextReaderPtr c_reader;
|
131
|
+
xmlNodePtr c_node;
|
132
|
+
VALUE rb_errors;
|
133
133
|
|
134
|
-
Data_Get_Struct(
|
134
|
+
Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
|
135
|
+
|
136
|
+
if (! has_attributes(c_reader)) {
|
137
|
+
return rb_namespaces ;
|
138
|
+
}
|
135
139
|
|
136
|
-
|
140
|
+
rb_errors = rb_funcall(rb_reader, rb_intern("errors"), 0);
|
137
141
|
|
138
|
-
|
139
|
-
|
142
|
+
xmlSetStructuredErrorFunc((void *)rb_errors, Nokogiri_error_array_pusher);
|
143
|
+
c_node = xmlTextReaderExpand(c_reader);
|
144
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
140
145
|
|
141
|
-
|
142
|
-
|
146
|
+
if (c_node == NULL) {
|
147
|
+
if (RARRAY_LEN(rb_errors) > 0) {
|
148
|
+
VALUE rb_error = rb_ary_entry(rb_errors, 0);
|
149
|
+
VALUE exception_message = rb_funcall(rb_error, rb_intern("to_s"), 0);
|
150
|
+
rb_exc_raise(rb_class_new_instance(1, &exception_message, cNokogiriXmlSyntaxError));
|
151
|
+
}
|
152
|
+
return Qnil;
|
153
|
+
}
|
143
154
|
|
144
|
-
Nokogiri_xml_node_namespaces(
|
155
|
+
Nokogiri_xml_node_namespaces(c_node, rb_namespaces);
|
145
156
|
|
146
|
-
return
|
157
|
+
return rb_namespaces ;
|
147
158
|
}
|
148
159
|
|
149
160
|
/*
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
161
|
+
:call-seq: attribute_nodes() → Array<Nokogiri::XML::Attr>
|
162
|
+
|
163
|
+
Get the attributes of the current node as an Array of XML:Attr
|
164
|
+
|
165
|
+
⚠ This method is deprecated and unsafe to use. It will be removed in a future version of Nokogiri.
|
166
|
+
|
167
|
+
See related: #attribute_hash, #attributes
|
154
168
|
*/
|
155
|
-
static VALUE
|
169
|
+
static VALUE
|
170
|
+
rb_xml_reader_attribute_nodes(VALUE rb_reader)
|
156
171
|
{
|
157
|
-
xmlTextReaderPtr
|
158
|
-
xmlNodePtr
|
159
|
-
VALUE
|
172
|
+
xmlTextReaderPtr c_reader;
|
173
|
+
xmlNodePtr c_node;
|
174
|
+
VALUE attr_nodes;
|
175
|
+
int j;
|
160
176
|
|
161
|
-
|
177
|
+
// TODO: deprecated, remove in Nokogiri v1.15, see https://github.com/sparklemotion/nokogiri/issues/2598
|
178
|
+
// After removal, we can also remove all the "node_has_a_document" special handling from xml_node.c
|
179
|
+
NOKO_WARN_DEPRECATION("Reader#attribute_nodes is deprecated and will be removed in a future version of Nokogiri. Please use Reader#attribute_hash instead.");
|
180
|
+
|
181
|
+
Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
|
162
182
|
|
163
|
-
|
183
|
+
if (! has_attributes(c_reader)) {
|
184
|
+
return rb_ary_new() ;
|
185
|
+
}
|
164
186
|
|
165
|
-
|
166
|
-
|
187
|
+
c_node = xmlTextReaderExpand(c_reader);
|
188
|
+
if (c_node == NULL) {
|
189
|
+
return Qnil;
|
190
|
+
}
|
167
191
|
|
168
|
-
|
169
|
-
if(ptr == NULL) return Qnil;
|
192
|
+
attr_nodes = noko_xml_node_attrs(c_node);
|
170
193
|
|
171
|
-
|
194
|
+
/* ensure that the Reader won't be GCed as long as a node is referenced */
|
195
|
+
for (j = 0 ; j < RARRAY_LEN(attr_nodes) ; j++) {
|
196
|
+
rb_iv_set(rb_ary_entry(attr_nodes, j), "@reader", rb_reader);
|
197
|
+
}
|
172
198
|
|
173
|
-
return
|
199
|
+
return attr_nodes;
|
200
|
+
}
|
201
|
+
|
202
|
+
/*
|
203
|
+
:call-seq: attribute_hash() → Hash<String ⇒ String>
|
204
|
+
|
205
|
+
Get the attributes of the current node as a Hash of names and values.
|
206
|
+
|
207
|
+
See related: #attributes and #namespaces
|
208
|
+
*/
|
209
|
+
static VALUE
|
210
|
+
rb_xml_reader_attribute_hash(VALUE rb_reader)
|
211
|
+
{
|
212
|
+
VALUE rb_attributes = rb_hash_new();
|
213
|
+
xmlTextReaderPtr c_reader;
|
214
|
+
xmlNodePtr c_node;
|
215
|
+
xmlAttrPtr c_property;
|
216
|
+
VALUE rb_errors;
|
217
|
+
|
218
|
+
Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
|
219
|
+
|
220
|
+
if (!has_attributes(c_reader)) {
|
221
|
+
return rb_attributes;
|
222
|
+
}
|
223
|
+
|
224
|
+
rb_errors = rb_funcall(rb_reader, rb_intern("errors"), 0);
|
225
|
+
|
226
|
+
xmlSetStructuredErrorFunc((void *)rb_errors, Nokogiri_error_array_pusher);
|
227
|
+
c_node = xmlTextReaderExpand(c_reader);
|
228
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
229
|
+
|
230
|
+
if (c_node == NULL) {
|
231
|
+
if (RARRAY_LEN(rb_errors) > 0) {
|
232
|
+
VALUE rb_error = rb_ary_entry(rb_errors, 0);
|
233
|
+
VALUE exception_message = rb_funcall(rb_error, rb_intern("to_s"), 0);
|
234
|
+
rb_exc_raise(rb_class_new_instance(1, &exception_message, cNokogiriXmlSyntaxError));
|
235
|
+
}
|
236
|
+
return Qnil;
|
237
|
+
}
|
238
|
+
|
239
|
+
c_property = c_node->properties;
|
240
|
+
while (c_property != NULL) {
|
241
|
+
VALUE rb_name = NOKOGIRI_STR_NEW2(c_property->name);
|
242
|
+
VALUE rb_value = Qnil;
|
243
|
+
xmlChar *c_value = xmlNodeGetContent((xmlNode *)c_property);
|
244
|
+
|
245
|
+
if (c_value) {
|
246
|
+
rb_value = NOKOGIRI_STR_NEW2(c_value);
|
247
|
+
xmlFree(c_value);
|
248
|
+
}
|
249
|
+
|
250
|
+
rb_hash_aset(rb_attributes, rb_name, rb_value);
|
251
|
+
|
252
|
+
c_property = c_property->next;
|
253
|
+
}
|
254
|
+
|
255
|
+
return rb_attributes;
|
174
256
|
}
|
175
257
|
|
176
258
|
/*
|
@@ -179,7 +261,8 @@ static VALUE attribute_nodes(VALUE self)
|
|
179
261
|
*
|
180
262
|
* Get the value of attribute at +index+
|
181
263
|
*/
|
182
|
-
static VALUE
|
264
|
+
static VALUE
|
265
|
+
attribute_at(VALUE self, VALUE index)
|
183
266
|
{
|
184
267
|
xmlTextReaderPtr reader;
|
185
268
|
xmlChar *value;
|
@@ -187,14 +270,14 @@ static VALUE attribute_at(VALUE self, VALUE index)
|
|
187
270
|
|
188
271
|
Data_Get_Struct(self, xmlTextReader, reader);
|
189
272
|
|
190
|
-
if(NIL_P(index)) return Qnil;
|
273
|
+
if (NIL_P(index)) { return Qnil; }
|
191
274
|
index = rb_Integer(index);
|
192
275
|
|
193
276
|
value = xmlTextReaderGetAttributeNo(
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
if(value == NULL) return Qnil;
|
277
|
+
reader,
|
278
|
+
(int)NUM2INT(index)
|
279
|
+
);
|
280
|
+
if (value == NULL) { return Qnil; }
|
198
281
|
|
199
282
|
rb_value = NOKOGIRI_STR_NEW2(value);
|
200
283
|
xmlFree(value);
|
@@ -207,7 +290,8 @@ static VALUE attribute_at(VALUE self, VALUE index)
|
|
207
290
|
*
|
208
291
|
* Get the value of attribute named +name+
|
209
292
|
*/
|
210
|
-
static VALUE
|
293
|
+
static VALUE
|
294
|
+
reader_attribute(VALUE self, VALUE name)
|
211
295
|
{
|
212
296
|
xmlTextReaderPtr reader;
|
213
297
|
xmlChar *value ;
|
@@ -215,11 +299,11 @@ static VALUE reader_attribute(VALUE self, VALUE name)
|
|
215
299
|
|
216
300
|
Data_Get_Struct(self, xmlTextReader, reader);
|
217
301
|
|
218
|
-
if(NIL_P(name)) return Qnil;
|
302
|
+
if (NIL_P(name)) { return Qnil; }
|
219
303
|
name = StringValue(name) ;
|
220
304
|
|
221
|
-
value = xmlTextReaderGetAttribute(reader, (xmlChar*)StringValueCStr(name));
|
222
|
-
if(value == NULL) return Qnil;
|
305
|
+
value = xmlTextReaderGetAttribute(reader, (xmlChar *)StringValueCStr(name));
|
306
|
+
if (value == NULL) { return Qnil; }
|
223
307
|
|
224
308
|
rb_value = NOKOGIRI_STR_NEW2(value);
|
225
309
|
xmlFree(value);
|
@@ -232,16 +316,17 @@ static VALUE reader_attribute(VALUE self, VALUE name)
|
|
232
316
|
*
|
233
317
|
* Get the number of attributes for the current node
|
234
318
|
*/
|
235
|
-
static VALUE
|
319
|
+
static VALUE
|
320
|
+
attribute_count(VALUE self)
|
236
321
|
{
|
237
322
|
xmlTextReaderPtr reader;
|
238
323
|
int count;
|
239
324
|
|
240
325
|
Data_Get_Struct(self, xmlTextReader, reader);
|
241
326
|
count = xmlTextReaderAttributeCount(reader);
|
242
|
-
if(count == -1) return Qnil;
|
327
|
+
if (count == -1) { return Qnil; }
|
243
328
|
|
244
|
-
return INT2NUM(
|
329
|
+
return INT2NUM(count);
|
245
330
|
}
|
246
331
|
|
247
332
|
/*
|
@@ -250,16 +335,17 @@ static VALUE attribute_count(VALUE self)
|
|
250
335
|
*
|
251
336
|
* Get the depth of the node
|
252
337
|
*/
|
253
|
-
static VALUE
|
338
|
+
static VALUE
|
339
|
+
depth(VALUE self)
|
254
340
|
{
|
255
341
|
xmlTextReaderPtr reader;
|
256
342
|
int depth;
|
257
343
|
|
258
344
|
Data_Get_Struct(self, xmlTextReader, reader);
|
259
345
|
depth = xmlTextReaderDepth(reader);
|
260
|
-
if(depth == -1) return Qnil;
|
346
|
+
if (depth == -1) { return Qnil; }
|
261
347
|
|
262
|
-
return INT2NUM(
|
348
|
+
return INT2NUM(depth);
|
263
349
|
}
|
264
350
|
|
265
351
|
/*
|
@@ -268,14 +354,15 @@ static VALUE depth(VALUE self)
|
|
268
354
|
*
|
269
355
|
* Get the XML version of the document being read
|
270
356
|
*/
|
271
|
-
static VALUE
|
357
|
+
static VALUE
|
358
|
+
xml_version(VALUE self)
|
272
359
|
{
|
273
360
|
xmlTextReaderPtr reader;
|
274
361
|
const char *version;
|
275
362
|
|
276
363
|
Data_Get_Struct(self, xmlTextReader, reader);
|
277
364
|
version = (const char *)xmlTextReaderConstXmlVersion(reader);
|
278
|
-
if(version == NULL) return Qnil;
|
365
|
+
if (version == NULL) { return Qnil; }
|
279
366
|
|
280
367
|
return NOKOGIRI_STR_NEW2(version);
|
281
368
|
}
|
@@ -286,14 +373,15 @@ static VALUE xml_version(VALUE self)
|
|
286
373
|
*
|
287
374
|
* Get the xml:lang scope within which the node resides.
|
288
375
|
*/
|
289
|
-
static VALUE
|
376
|
+
static VALUE
|
377
|
+
lang(VALUE self)
|
290
378
|
{
|
291
379
|
xmlTextReaderPtr reader;
|
292
380
|
const char *lang;
|
293
381
|
|
294
382
|
Data_Get_Struct(self, xmlTextReader, reader);
|
295
383
|
lang = (const char *)xmlTextReaderConstXmlLang(reader);
|
296
|
-
if(lang == NULL) return Qnil;
|
384
|
+
if (lang == NULL) { return Qnil; }
|
297
385
|
|
298
386
|
return NOKOGIRI_STR_NEW2(lang);
|
299
387
|
}
|
@@ -304,14 +392,15 @@ static VALUE lang(VALUE self)
|
|
304
392
|
*
|
305
393
|
* Get the text value of the node if present. Returns a utf-8 encoded string.
|
306
394
|
*/
|
307
|
-
static VALUE
|
395
|
+
static VALUE
|
396
|
+
value(VALUE self)
|
308
397
|
{
|
309
398
|
xmlTextReaderPtr reader;
|
310
399
|
const char *value;
|
311
400
|
|
312
401
|
Data_Get_Struct(self, xmlTextReader, reader);
|
313
402
|
value = (const char *)xmlTextReaderConstValue(reader);
|
314
|
-
if(value == NULL) return Qnil;
|
403
|
+
if (value == NULL) { return Qnil; }
|
315
404
|
|
316
405
|
return NOKOGIRI_STR_NEW2(value);
|
317
406
|
}
|
@@ -322,14 +411,15 @@ static VALUE value(VALUE self)
|
|
322
411
|
*
|
323
412
|
* Get the shorthand reference to the namespace associated with the node.
|
324
413
|
*/
|
325
|
-
static VALUE
|
414
|
+
static VALUE
|
415
|
+
prefix(VALUE self)
|
326
416
|
{
|
327
417
|
xmlTextReaderPtr reader;
|
328
418
|
const char *prefix;
|
329
419
|
|
330
420
|
Data_Get_Struct(self, xmlTextReader, reader);
|
331
421
|
prefix = (const char *)xmlTextReaderConstPrefix(reader);
|
332
|
-
if(prefix == NULL) return Qnil;
|
422
|
+
if (prefix == NULL) { return Qnil; }
|
333
423
|
|
334
424
|
return NOKOGIRI_STR_NEW2(prefix);
|
335
425
|
}
|
@@ -340,14 +430,15 @@ static VALUE prefix(VALUE self)
|
|
340
430
|
*
|
341
431
|
* Get the URI defining the namespace associated with the node
|
342
432
|
*/
|
343
|
-
static VALUE
|
433
|
+
static VALUE
|
434
|
+
namespace_uri(VALUE self)
|
344
435
|
{
|
345
436
|
xmlTextReaderPtr reader;
|
346
437
|
const char *uri;
|
347
438
|
|
348
439
|
Data_Get_Struct(self, xmlTextReader, reader);
|
349
440
|
uri = (const char *)xmlTextReaderConstNamespaceUri(reader);
|
350
|
-
if(uri == NULL) return Qnil;
|
441
|
+
if (uri == NULL) { return Qnil; }
|
351
442
|
|
352
443
|
return NOKOGIRI_STR_NEW2(uri);
|
353
444
|
}
|
@@ -358,14 +449,15 @@ static VALUE namespace_uri(VALUE self)
|
|
358
449
|
*
|
359
450
|
* Get the local name of the node
|
360
451
|
*/
|
361
|
-
static VALUE
|
452
|
+
static VALUE
|
453
|
+
local_name(VALUE self)
|
362
454
|
{
|
363
455
|
xmlTextReaderPtr reader;
|
364
456
|
const char *name;
|
365
457
|
|
366
458
|
Data_Get_Struct(self, xmlTextReader, reader);
|
367
459
|
name = (const char *)xmlTextReaderConstLocalName(reader);
|
368
|
-
if(name == NULL) return Qnil;
|
460
|
+
if (name == NULL) { return Qnil; }
|
369
461
|
|
370
462
|
return NOKOGIRI_STR_NEW2(name);
|
371
463
|
}
|
@@ -376,14 +468,15 @@ static VALUE local_name(VALUE self)
|
|
376
468
|
*
|
377
469
|
* Get the name of the node. Returns a utf-8 encoded string.
|
378
470
|
*/
|
379
|
-
static VALUE
|
471
|
+
static VALUE
|
472
|
+
name(VALUE self)
|
380
473
|
{
|
381
474
|
xmlTextReaderPtr reader;
|
382
475
|
const char *name;
|
383
476
|
|
384
477
|
Data_Get_Struct(self, xmlTextReader, reader);
|
385
478
|
name = (const char *)xmlTextReaderConstName(reader);
|
386
|
-
if(name == NULL) return Qnil;
|
479
|
+
if (name == NULL) { return Qnil; }
|
387
480
|
|
388
481
|
return NOKOGIRI_STR_NEW2(name);
|
389
482
|
}
|
@@ -394,16 +487,24 @@ static VALUE name(VALUE self)
|
|
394
487
|
*
|
395
488
|
* Get the xml:base of the node
|
396
489
|
*/
|
397
|
-
static VALUE
|
490
|
+
static VALUE
|
491
|
+
rb_xml_reader_base_uri(VALUE rb_reader)
|
398
492
|
{
|
399
|
-
|
400
|
-
|
493
|
+
VALUE rb_base_uri;
|
494
|
+
xmlTextReaderPtr c_reader;
|
495
|
+
xmlChar *c_base_uri;
|
401
496
|
|
402
|
-
Data_Get_Struct(
|
403
|
-
|
404
|
-
|
497
|
+
Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
|
498
|
+
|
499
|
+
c_base_uri = xmlTextReaderBaseUri(c_reader);
|
500
|
+
if (c_base_uri == NULL) {
|
501
|
+
return Qnil;
|
502
|
+
}
|
405
503
|
|
406
|
-
|
504
|
+
rb_base_uri = NOKOGIRI_STR_NEW2(c_base_uri);
|
505
|
+
xmlFree(c_base_uri);
|
506
|
+
|
507
|
+
return rb_base_uri;
|
407
508
|
}
|
408
509
|
|
409
510
|
/*
|
@@ -412,11 +513,12 @@ static VALUE base_uri(VALUE self)
|
|
412
513
|
*
|
413
514
|
* Get the state of the reader
|
414
515
|
*/
|
415
|
-
static VALUE
|
516
|
+
static VALUE
|
517
|
+
state(VALUE self)
|
416
518
|
{
|
417
519
|
xmlTextReaderPtr reader;
|
418
520
|
Data_Get_Struct(self, xmlTextReader, reader);
|
419
|
-
return INT2NUM(
|
521
|
+
return INT2NUM(xmlTextReaderReadState(reader));
|
420
522
|
}
|
421
523
|
|
422
524
|
/*
|
@@ -425,11 +527,12 @@ static VALUE state(VALUE self)
|
|
425
527
|
*
|
426
528
|
* Get the type of readers current node
|
427
529
|
*/
|
428
|
-
static VALUE
|
530
|
+
static VALUE
|
531
|
+
node_type(VALUE self)
|
429
532
|
{
|
430
533
|
xmlTextReaderPtr reader;
|
431
534
|
Data_Get_Struct(self, xmlTextReader, reader);
|
432
|
-
return INT2NUM(
|
535
|
+
return INT2NUM(xmlTextReaderNodeType(reader));
|
433
536
|
}
|
434
537
|
|
435
538
|
/*
|
@@ -438,7 +541,8 @@ static VALUE node_type(VALUE self)
|
|
438
541
|
*
|
439
542
|
* Move the Reader forward through the XML document.
|
440
543
|
*/
|
441
|
-
static VALUE
|
544
|
+
static VALUE
|
545
|
+
read_more(VALUE self)
|
442
546
|
{
|
443
547
|
xmlTextReaderPtr reader;
|
444
548
|
xmlErrorPtr error;
|
@@ -453,14 +557,15 @@ static VALUE read_more(VALUE self)
|
|
453
557
|
ret = xmlTextReaderRead(reader);
|
454
558
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
455
559
|
|
456
|
-
if(ret == 1) return self;
|
457
|
-
if(ret == 0) return Qnil;
|
560
|
+
if (ret == 1) { return self; }
|
561
|
+
if (ret == 0) { return Qnil; }
|
458
562
|
|
459
563
|
error = xmlGetLastError();
|
460
|
-
if(error)
|
564
|
+
if (error) {
|
461
565
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
462
|
-
else
|
566
|
+
} else {
|
463
567
|
rb_raise(rb_eRuntimeError, "Error pulling: %d", ret);
|
568
|
+
}
|
464
569
|
|
465
570
|
return Qnil;
|
466
571
|
}
|
@@ -472,10 +577,11 @@ static VALUE read_more(VALUE self)
|
|
472
577
|
* Read the contents of the current node, including child nodes and markup.
|
473
578
|
* Returns a utf-8 encoded string.
|
474
579
|
*/
|
475
|
-
static VALUE
|
580
|
+
static VALUE
|
581
|
+
inner_xml(VALUE self)
|
476
582
|
{
|
477
583
|
xmlTextReaderPtr reader;
|
478
|
-
xmlChar*
|
584
|
+
xmlChar *value;
|
479
585
|
VALUE str;
|
480
586
|
|
481
587
|
Data_Get_Struct(self, xmlTextReader, reader);
|
@@ -483,8 +589,8 @@ static VALUE inner_xml(VALUE self)
|
|
483
589
|
value = xmlTextReaderReadInnerXml(reader);
|
484
590
|
|
485
591
|
str = Qnil;
|
486
|
-
if(value) {
|
487
|
-
str = NOKOGIRI_STR_NEW2((char*)value);
|
592
|
+
if (value) {
|
593
|
+
str = NOKOGIRI_STR_NEW2((char *)value);
|
488
594
|
xmlFree(value);
|
489
595
|
}
|
490
596
|
|
@@ -498,7 +604,8 @@ static VALUE inner_xml(VALUE self)
|
|
498
604
|
* Read the current node and its contents, including child nodes and markup.
|
499
605
|
* Returns a utf-8 encoded string.
|
500
606
|
*/
|
501
|
-
static VALUE
|
607
|
+
static VALUE
|
608
|
+
outer_xml(VALUE self)
|
502
609
|
{
|
503
610
|
xmlTextReaderPtr reader;
|
504
611
|
xmlChar *value;
|
@@ -508,8 +615,8 @@ static VALUE outer_xml(VALUE self)
|
|
508
615
|
|
509
616
|
value = xmlTextReaderReadOuterXml(reader);
|
510
617
|
|
511
|
-
if(value) {
|
512
|
-
str = NOKOGIRI_STR_NEW2((char*)value);
|
618
|
+
if (value) {
|
619
|
+
str = NOKOGIRI_STR_NEW2((char *)value);
|
513
620
|
xmlFree(value);
|
514
621
|
}
|
515
622
|
return str;
|
@@ -521,31 +628,32 @@ static VALUE outer_xml(VALUE self)
|
|
521
628
|
*
|
522
629
|
* Create a new reader that parses +string+
|
523
630
|
*/
|
524
|
-
static VALUE
|
631
|
+
static VALUE
|
632
|
+
from_memory(int argc, VALUE *argv, VALUE klass)
|
525
633
|
{
|
526
634
|
VALUE rb_buffer, rb_url, encoding, rb_options;
|
527
635
|
xmlTextReaderPtr reader;
|
528
|
-
const char *
|
529
|
-
const char *
|
636
|
+
const char *c_url = NULL;
|
637
|
+
const char *c_encoding = NULL;
|
530
638
|
int c_options = 0;
|
531
639
|
VALUE rb_reader, args[3];
|
532
640
|
|
533
641
|
rb_scan_args(argc, argv, "13", &rb_buffer, &rb_url, &encoding, &rb_options);
|
534
642
|
|
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);
|
643
|
+
if (!RTEST(rb_buffer)) { rb_raise(rb_eArgError, "string cannot be nil"); }
|
644
|
+
if (RTEST(rb_url)) { c_url = StringValueCStr(rb_url); }
|
645
|
+
if (RTEST(encoding)) { c_encoding = StringValueCStr(encoding); }
|
646
|
+
if (RTEST(rb_options)) { c_options = (int)NUM2INT(rb_options); }
|
539
647
|
|
540
648
|
reader = xmlReaderForMemory(
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
if(reader == NULL) {
|
649
|
+
StringValuePtr(rb_buffer),
|
650
|
+
(int)RSTRING_LEN(rb_buffer),
|
651
|
+
c_url,
|
652
|
+
c_encoding,
|
653
|
+
c_options
|
654
|
+
);
|
655
|
+
|
656
|
+
if (reader == NULL) {
|
549
657
|
xmlFreeTextReader(reader);
|
550
658
|
rb_raise(rb_eRuntimeError, "couldn't create a parser");
|
551
659
|
}
|
@@ -565,32 +673,33 @@ static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
|
|
565
673
|
*
|
566
674
|
* Create a new reader that parses +io+
|
567
675
|
*/
|
568
|
-
static VALUE
|
676
|
+
static VALUE
|
677
|
+
from_io(int argc, VALUE *argv, VALUE klass)
|
569
678
|
{
|
570
679
|
VALUE rb_io, rb_url, encoding, rb_options;
|
571
680
|
xmlTextReaderPtr reader;
|
572
|
-
const char *
|
573
|
-
const char *
|
681
|
+
const char *c_url = NULL;
|
682
|
+
const char *c_encoding = NULL;
|
574
683
|
int c_options = 0;
|
575
684
|
VALUE rb_reader, args[3];
|
576
685
|
|
577
686
|
rb_scan_args(argc, argv, "13", &rb_io, &rb_url, &encoding, &rb_options);
|
578
687
|
|
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);
|
688
|
+
if (!RTEST(rb_io)) { rb_raise(rb_eArgError, "io cannot be nil"); }
|
689
|
+
if (RTEST(rb_url)) { c_url = StringValueCStr(rb_url); }
|
690
|
+
if (RTEST(encoding)) { c_encoding = StringValueCStr(encoding); }
|
691
|
+
if (RTEST(rb_options)) { c_options = (int)NUM2INT(rb_options); }
|
583
692
|
|
584
693
|
reader = xmlReaderForIO(
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
if(reader == NULL) {
|
694
|
+
(xmlInputReadCallback)noko_io_read,
|
695
|
+
(xmlInputCloseCallback)noko_io_close,
|
696
|
+
(void *)rb_io,
|
697
|
+
c_url,
|
698
|
+
c_encoding,
|
699
|
+
c_options
|
700
|
+
);
|
701
|
+
|
702
|
+
if (reader == NULL) {
|
594
703
|
xmlFreeTextReader(reader);
|
595
704
|
rb_raise(rb_eRuntimeError, "couldn't create a parser");
|
596
705
|
}
|
@@ -610,59 +719,76 @@ static VALUE from_io(int argc, VALUE *argv, VALUE klass)
|
|
610
719
|
*
|
611
720
|
* Returns true if the current node is empty, otherwise false.
|
612
721
|
*/
|
613
|
-
static VALUE
|
722
|
+
static VALUE
|
723
|
+
empty_element_p(VALUE self)
|
614
724
|
{
|
615
725
|
xmlTextReaderPtr reader;
|
616
726
|
|
617
727
|
Data_Get_Struct(self, xmlTextReader, reader);
|
618
728
|
|
619
|
-
if(xmlTextReaderIsEmptyElement(reader))
|
729
|
+
if (xmlTextReaderIsEmptyElement(reader)) {
|
620
730
|
return Qtrue;
|
731
|
+
}
|
621
732
|
|
622
733
|
return Qfalse;
|
623
734
|
}
|
624
735
|
|
625
|
-
VALUE
|
626
|
-
|
627
|
-
void init_xml_reader()
|
736
|
+
static VALUE
|
737
|
+
rb_xml_reader_encoding(VALUE rb_reader)
|
628
738
|
{
|
629
|
-
|
630
|
-
|
739
|
+
xmlTextReaderPtr c_reader;
|
740
|
+
const char *parser_encoding;
|
741
|
+
VALUE constructor_encoding;
|
742
|
+
|
743
|
+
constructor_encoding = rb_iv_get(rb_reader, "@encoding");
|
744
|
+
if (RTEST(constructor_encoding)) {
|
745
|
+
return constructor_encoding;
|
746
|
+
}
|
631
747
|
|
748
|
+
Data_Get_Struct(rb_reader, xmlTextReader, c_reader);
|
749
|
+
parser_encoding = (const char *)xmlTextReaderConstEncoding(c_reader);
|
750
|
+
if (parser_encoding == NULL) { return Qnil; }
|
751
|
+
return NOKOGIRI_STR_NEW2(parser_encoding);
|
752
|
+
}
|
753
|
+
|
754
|
+
void
|
755
|
+
noko_init_xml_reader(void)
|
756
|
+
{
|
632
757
|
/*
|
633
758
|
* The Reader parser allows you to effectively pull parse an XML document.
|
634
759
|
* Once instantiated, call Nokogiri::XML::Reader#each to iterate over each
|
635
760
|
* node. Note that you may only iterate over the document once!
|
636
761
|
*/
|
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
|
-
|
762
|
+
cNokogiriXmlReader = rb_define_class_under(mNokogiriXml, "Reader", rb_cObject);
|
763
|
+
|
764
|
+
rb_undef_alloc_func(cNokogiriXmlReader);
|
765
|
+
|
766
|
+
rb_define_singleton_method(cNokogiriXmlReader, "from_memory", from_memory, -1);
|
767
|
+
rb_define_singleton_method(cNokogiriXmlReader, "from_io", from_io, -1);
|
768
|
+
|
769
|
+
rb_define_method(cNokogiriXmlReader, "attribute", reader_attribute, 1);
|
770
|
+
rb_define_method(cNokogiriXmlReader, "attribute_at", attribute_at, 1);
|
771
|
+
rb_define_method(cNokogiriXmlReader, "attribute_count", attribute_count, 0);
|
772
|
+
rb_define_method(cNokogiriXmlReader, "attribute_nodes", rb_xml_reader_attribute_nodes, 0);
|
773
|
+
rb_define_method(cNokogiriXmlReader, "attribute_hash", rb_xml_reader_attribute_hash, 0);
|
774
|
+
rb_define_method(cNokogiriXmlReader, "attributes?", attributes_eh, 0);
|
775
|
+
rb_define_method(cNokogiriXmlReader, "base_uri", rb_xml_reader_base_uri, 0);
|
776
|
+
rb_define_method(cNokogiriXmlReader, "default?", default_eh, 0);
|
777
|
+
rb_define_method(cNokogiriXmlReader, "depth", depth, 0);
|
778
|
+
rb_define_method(cNokogiriXmlReader, "empty_element?", empty_element_p, 0);
|
779
|
+
rb_define_method(cNokogiriXmlReader, "encoding", rb_xml_reader_encoding, 0);
|
780
|
+
rb_define_method(cNokogiriXmlReader, "inner_xml", inner_xml, 0);
|
781
|
+
rb_define_method(cNokogiriXmlReader, "lang", lang, 0);
|
782
|
+
rb_define_method(cNokogiriXmlReader, "local_name", local_name, 0);
|
783
|
+
rb_define_method(cNokogiriXmlReader, "name", name, 0);
|
784
|
+
rb_define_method(cNokogiriXmlReader, "namespace_uri", namespace_uri, 0);
|
785
|
+
rb_define_method(cNokogiriXmlReader, "namespaces", rb_xml_reader_namespaces, 0);
|
786
|
+
rb_define_method(cNokogiriXmlReader, "node_type", node_type, 0);
|
787
|
+
rb_define_method(cNokogiriXmlReader, "outer_xml", outer_xml, 0);
|
788
|
+
rb_define_method(cNokogiriXmlReader, "prefix", prefix, 0);
|
789
|
+
rb_define_method(cNokogiriXmlReader, "read", read_more, 0);
|
790
|
+
rb_define_method(cNokogiriXmlReader, "state", state, 0);
|
791
|
+
rb_define_method(cNokogiriXmlReader, "value", value, 0);
|
792
|
+
rb_define_method(cNokogiriXmlReader, "value?", value_eh, 0);
|
793
|
+
rb_define_method(cNokogiriXmlReader, "xml_version", xml_version, 0);
|
668
794
|
}
|