nokogiri 1.11.0-arm64-darwin

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.

Files changed (219) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1682 -0
  4. data/LICENSE.md +9 -0
  5. data/README.md +272 -0
  6. data/bin/nokogiri +118 -0
  7. data/dependencies.yml +74 -0
  8. data/ext/nokogiri/depend +477 -0
  9. data/ext/nokogiri/extconf.rb +836 -0
  10. data/ext/nokogiri/html_document.c +171 -0
  11. data/ext/nokogiri/html_document.h +10 -0
  12. data/ext/nokogiri/html_element_description.c +279 -0
  13. data/ext/nokogiri/html_element_description.h +10 -0
  14. data/ext/nokogiri/html_entity_lookup.c +32 -0
  15. data/ext/nokogiri/html_entity_lookup.h +8 -0
  16. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  17. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  18. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  19. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  20. data/ext/nokogiri/include/libexslt/exslt.h +102 -0
  21. data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
  22. data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
  23. data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
  24. data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
  25. data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
  26. data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
  27. data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
  28. data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
  29. data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
  30. data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
  31. data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
  32. data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
  33. data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
  34. data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
  35. data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
  36. data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
  37. data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
  38. data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
  39. data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
  40. data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
  41. data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
  42. data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
  43. data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
  44. data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
  45. data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
  46. data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
  47. data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
  48. data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
  49. data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
  50. data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
  51. data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
  52. data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
  53. data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
  54. data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
  55. data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
  56. data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
  57. data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
  58. data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
  59. data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
  60. data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
  61. data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
  62. data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
  63. data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
  64. data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
  65. data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
  66. data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
  67. data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
  68. data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
  69. data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
  70. data/ext/nokogiri/include/libxslt/attributes.h +38 -0
  71. data/ext/nokogiri/include/libxslt/documents.h +93 -0
  72. data/ext/nokogiri/include/libxslt/extensions.h +262 -0
  73. data/ext/nokogiri/include/libxslt/extra.h +72 -0
  74. data/ext/nokogiri/include/libxslt/functions.h +78 -0
  75. data/ext/nokogiri/include/libxslt/imports.h +75 -0
  76. data/ext/nokogiri/include/libxslt/keys.h +53 -0
  77. data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
  78. data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
  79. data/ext/nokogiri/include/libxslt/pattern.h +84 -0
  80. data/ext/nokogiri/include/libxslt/preproc.h +43 -0
  81. data/ext/nokogiri/include/libxslt/security.h +104 -0
  82. data/ext/nokogiri/include/libxslt/templates.h +77 -0
  83. data/ext/nokogiri/include/libxslt/transform.h +207 -0
  84. data/ext/nokogiri/include/libxslt/variables.h +118 -0
  85. data/ext/nokogiri/include/libxslt/xslt.h +110 -0
  86. data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
  87. data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
  88. data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
  89. data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
  90. data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
  91. data/ext/nokogiri/nokogiri.c +135 -0
  92. data/ext/nokogiri/nokogiri.h +130 -0
  93. data/ext/nokogiri/xml_attr.c +103 -0
  94. data/ext/nokogiri/xml_attr.h +9 -0
  95. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  96. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  97. data/ext/nokogiri/xml_cdata.c +62 -0
  98. data/ext/nokogiri/xml_cdata.h +9 -0
  99. data/ext/nokogiri/xml_comment.c +69 -0
  100. data/ext/nokogiri/xml_comment.h +9 -0
  101. data/ext/nokogiri/xml_document.c +622 -0
  102. data/ext/nokogiri/xml_document.h +23 -0
  103. data/ext/nokogiri/xml_document_fragment.c +48 -0
  104. data/ext/nokogiri/xml_document_fragment.h +10 -0
  105. data/ext/nokogiri/xml_dtd.c +202 -0
  106. data/ext/nokogiri/xml_dtd.h +10 -0
  107. data/ext/nokogiri/xml_element_content.c +123 -0
  108. data/ext/nokogiri/xml_element_content.h +10 -0
  109. data/ext/nokogiri/xml_element_decl.c +69 -0
  110. data/ext/nokogiri/xml_element_decl.h +9 -0
  111. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  112. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  113. data/ext/nokogiri/xml_entity_decl.c +110 -0
  114. data/ext/nokogiri/xml_entity_decl.h +10 -0
  115. data/ext/nokogiri/xml_entity_reference.c +52 -0
  116. data/ext/nokogiri/xml_entity_reference.h +9 -0
  117. data/ext/nokogiri/xml_io.c +63 -0
  118. data/ext/nokogiri/xml_io.h +11 -0
  119. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  120. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  121. data/ext/nokogiri/xml_namespace.c +111 -0
  122. data/ext/nokogiri/xml_namespace.h +14 -0
  123. data/ext/nokogiri/xml_node.c +1773 -0
  124. data/ext/nokogiri/xml_node.h +13 -0
  125. data/ext/nokogiri/xml_node_set.c +486 -0
  126. data/ext/nokogiri/xml_node_set.h +12 -0
  127. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  128. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  129. data/ext/nokogiri/xml_reader.c +657 -0
  130. data/ext/nokogiri/xml_reader.h +10 -0
  131. data/ext/nokogiri/xml_relax_ng.c +179 -0
  132. data/ext/nokogiri/xml_relax_ng.h +9 -0
  133. data/ext/nokogiri/xml_sax_parser.c +305 -0
  134. data/ext/nokogiri/xml_sax_parser.h +39 -0
  135. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  136. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  137. data/ext/nokogiri/xml_sax_push_parser.c +159 -0
  138. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  139. data/ext/nokogiri/xml_schema.c +276 -0
  140. data/ext/nokogiri/xml_schema.h +9 -0
  141. data/ext/nokogiri/xml_syntax_error.c +64 -0
  142. data/ext/nokogiri/xml_syntax_error.h +13 -0
  143. data/ext/nokogiri/xml_text.c +52 -0
  144. data/ext/nokogiri/xml_text.h +9 -0
  145. data/ext/nokogiri/xml_xpath_context.c +374 -0
  146. data/ext/nokogiri/xml_xpath_context.h +10 -0
  147. data/ext/nokogiri/xslt_stylesheet.c +263 -0
  148. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  149. data/lib/nokogiri.rb +144 -0
  150. data/lib/nokogiri/2.5/nokogiri.bundle +0 -0
  151. data/lib/nokogiri/2.6/nokogiri.bundle +0 -0
  152. data/lib/nokogiri/2.7/nokogiri.bundle +0 -0
  153. data/lib/nokogiri/3.0/nokogiri.bundle +0 -0
  154. data/lib/nokogiri/css.rb +28 -0
  155. data/lib/nokogiri/css/node.rb +53 -0
  156. data/lib/nokogiri/css/parser.rb +751 -0
  157. data/lib/nokogiri/css/parser.y +272 -0
  158. data/lib/nokogiri/css/parser_extras.rb +94 -0
  159. data/lib/nokogiri/css/syntax_error.rb +8 -0
  160. data/lib/nokogiri/css/tokenizer.rb +154 -0
  161. data/lib/nokogiri/css/tokenizer.rex +55 -0
  162. data/lib/nokogiri/css/xpath_visitor.rb +260 -0
  163. data/lib/nokogiri/decorators/slop.rb +43 -0
  164. data/lib/nokogiri/html.rb +38 -0
  165. data/lib/nokogiri/html/builder.rb +36 -0
  166. data/lib/nokogiri/html/document.rb +322 -0
  167. data/lib/nokogiri/html/document_fragment.rb +50 -0
  168. data/lib/nokogiri/html/element_description.rb +24 -0
  169. data/lib/nokogiri/html/element_description_defaults.rb +672 -0
  170. data/lib/nokogiri/html/entity_lookup.rb +14 -0
  171. data/lib/nokogiri/html/sax/parser.rb +63 -0
  172. data/lib/nokogiri/html/sax/parser_context.rb +17 -0
  173. data/lib/nokogiri/html/sax/push_parser.rb +37 -0
  174. data/lib/nokogiri/jruby/dependencies.rb +20 -0
  175. data/lib/nokogiri/syntax_error.rb +5 -0
  176. data/lib/nokogiri/version.rb +3 -0
  177. data/lib/nokogiri/version/constant.rb +5 -0
  178. data/lib/nokogiri/version/info.rb +182 -0
  179. data/lib/nokogiri/xml.rb +76 -0
  180. data/lib/nokogiri/xml/attr.rb +15 -0
  181. data/lib/nokogiri/xml/attribute_decl.rb +19 -0
  182. data/lib/nokogiri/xml/builder.rb +447 -0
  183. data/lib/nokogiri/xml/cdata.rb +12 -0
  184. data/lib/nokogiri/xml/character_data.rb +8 -0
  185. data/lib/nokogiri/xml/document.rb +290 -0
  186. data/lib/nokogiri/xml/document_fragment.rb +159 -0
  187. data/lib/nokogiri/xml/dtd.rb +33 -0
  188. data/lib/nokogiri/xml/element_content.rb +37 -0
  189. data/lib/nokogiri/xml/element_decl.rb +14 -0
  190. data/lib/nokogiri/xml/entity_decl.rb +20 -0
  191. data/lib/nokogiri/xml/entity_reference.rb +19 -0
  192. data/lib/nokogiri/xml/namespace.rb +14 -0
  193. data/lib/nokogiri/xml/node.rb +1240 -0
  194. data/lib/nokogiri/xml/node/save_options.rb +62 -0
  195. data/lib/nokogiri/xml/node_set.rb +372 -0
  196. data/lib/nokogiri/xml/notation.rb +7 -0
  197. data/lib/nokogiri/xml/parse_options.rb +127 -0
  198. data/lib/nokogiri/xml/pp.rb +3 -0
  199. data/lib/nokogiri/xml/pp/character_data.rb +19 -0
  200. data/lib/nokogiri/xml/pp/node.rb +57 -0
  201. data/lib/nokogiri/xml/processing_instruction.rb +9 -0
  202. data/lib/nokogiri/xml/reader.rb +116 -0
  203. data/lib/nokogiri/xml/relax_ng.rb +37 -0
  204. data/lib/nokogiri/xml/sax.rb +5 -0
  205. data/lib/nokogiri/xml/sax/document.rb +172 -0
  206. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  207. data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
  208. data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
  209. data/lib/nokogiri/xml/schema.rb +72 -0
  210. data/lib/nokogiri/xml/searchable.rb +239 -0
  211. data/lib/nokogiri/xml/syntax_error.rb +71 -0
  212. data/lib/nokogiri/xml/text.rb +10 -0
  213. data/lib/nokogiri/xml/xpath.rb +11 -0
  214. data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
  215. data/lib/nokogiri/xml/xpath_context.rb +17 -0
  216. data/lib/nokogiri/xslt.rb +57 -0
  217. data/lib/nokogiri/xslt/stylesheet.rb +26 -0
  218. data/lib/xsd/xmlparser/nokogiri.rb +103 -0
  219. metadata +499 -0
@@ -0,0 +1,12 @@
1
+ #ifndef NOKOGIRI_XML_NODE_SET
2
+ #define NOKOGIRI_XML_NODE_SET
3
+
4
+ #include <nokogiri.h>
5
+ void init_xml_node_set();
6
+
7
+ extern VALUE cNokogiriXmlNodeSet ;
8
+ VALUE Nokogiri_wrap_xml_node_set(xmlNodeSetPtr node_set, VALUE document) ;
9
+ VALUE Nokogiri_wrap_xml_node_set_node(xmlNodePtr node, VALUE node_set) ;
10
+ VALUE Nokogiri_wrap_xml_node_set_namespace(xmlNsPtr node, VALUE node_set) ;
11
+
12
+ #endif
@@ -0,0 +1,56 @@
1
+ #include <xml_processing_instruction.h>
2
+
3
+ /*
4
+ * call-seq:
5
+ * new(document, name, content)
6
+ *
7
+ * Create a new ProcessingInstruction element on the +document+ with +name+
8
+ * and +content+
9
+ */
10
+ static VALUE new(int argc, VALUE *argv, VALUE klass)
11
+ {
12
+ xmlDocPtr xml_doc;
13
+ xmlNodePtr node;
14
+ VALUE document;
15
+ VALUE name;
16
+ VALUE content;
17
+ VALUE rest;
18
+ VALUE rb_node;
19
+
20
+ rb_scan_args(argc, argv, "3*", &document, &name, &content, &rest);
21
+
22
+ Data_Get_Struct(document, xmlDoc, xml_doc);
23
+
24
+ node = xmlNewDocPI(
25
+ xml_doc,
26
+ (const xmlChar *)StringValueCStr(name),
27
+ (const xmlChar *)StringValueCStr(content)
28
+ );
29
+
30
+ nokogiri_root_node(node);
31
+
32
+ rb_node = Nokogiri_wrap_xml_node(klass, node);
33
+ rb_obj_call_init(rb_node, argc, argv);
34
+
35
+ if(rb_block_given_p()) rb_yield(rb_node);
36
+
37
+ return rb_node;
38
+ }
39
+
40
+ VALUE cNokogiriXmlProcessingInstruction;
41
+ void init_xml_processing_instruction()
42
+ {
43
+ VALUE nokogiri = rb_define_module("Nokogiri");
44
+ VALUE xml = rb_define_module_under(nokogiri, "XML");
45
+ VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
46
+
47
+ /*
48
+ * ProcessingInstruction represents a ProcessingInstruction node in an xml
49
+ * document.
50
+ */
51
+ VALUE klass = rb_define_class_under(xml, "ProcessingInstruction", node);
52
+
53
+ cNokogiriXmlProcessingInstruction = klass;
54
+
55
+ rb_define_singleton_method(klass, "new", new, -1);
56
+ }
@@ -0,0 +1,9 @@
1
+ #ifndef NOKOGIRI_XML_PROCESSING_INSTRUCTION
2
+ #define NOKOGIRI_XML_PROCESSING_INSTRUCTION
3
+
4
+ #include <nokogiri.h>
5
+
6
+ void init_xml_processing_instruction();
7
+
8
+ extern VALUE cNokogiriXmlProcessingInstruction;
9
+ #endif
@@ -0,0 +1,657 @@
1
+ #include <xml_reader.h>
2
+
3
+ static void dealloc(xmlTextReaderPtr reader)
4
+ {
5
+ NOKOGIRI_DEBUG_START(reader);
6
+ xmlFreeTextReader(reader);
7
+ NOKOGIRI_DEBUG_END(reader);
8
+ }
9
+
10
+ static int has_attributes(xmlTextReaderPtr reader)
11
+ {
12
+ /*
13
+ * this implementation of xmlTextReaderHasAttributes explicitly includes
14
+ * namespaces and properties, because some earlier versions ignore
15
+ * namespaces.
16
+ */
17
+ xmlNodePtr node ;
18
+ node = xmlTextReaderCurrentNode(reader);
19
+ if (node == NULL)
20
+ return(0);
21
+
22
+ if ((node->type == XML_ELEMENT_NODE) &&
23
+ ((node->properties != NULL) || (node->nsDef != NULL)))
24
+ return(1);
25
+ return(0);
26
+ }
27
+
28
+ static void Nokogiri_xml_node_namespaces(xmlNodePtr node, VALUE attr_hash)
29
+ {
30
+ xmlNsPtr ns;
31
+ VALUE key;
32
+
33
+ if (node->type != XML_ELEMENT_NODE) return ;
34
+
35
+ ns = node->nsDef;
36
+ while (ns != NULL) {
37
+
38
+ key = rb_enc_str_new_cstr(XMLNS_PREFIX, rb_utf8_encoding());
39
+ if (ns->prefix) {
40
+ rb_str_cat_cstr(key, ":");
41
+ rb_str_cat_cstr(key, (const char*)ns->prefix);
42
+ }
43
+
44
+ key = rb_str_conv_enc(key, rb_utf8_encoding(), rb_default_internal_encoding());
45
+ rb_hash_aset(attr_hash,
46
+ key,
47
+ (ns->href ? NOKOGIRI_STR_NEW2(ns->href) : Qnil)
48
+ );
49
+ ns = ns->next ;
50
+ }
51
+ }
52
+
53
+
54
+ /*
55
+ * call-seq:
56
+ * default?
57
+ *
58
+ * Was an attribute generated from the default value in the DTD or schema?
59
+ */
60
+ static VALUE default_eh(VALUE self)
61
+ {
62
+ xmlTextReaderPtr reader;
63
+ int eh;
64
+
65
+ Data_Get_Struct(self, xmlTextReader, reader);
66
+ eh = xmlTextReaderIsDefault(reader);
67
+ if(eh == 0) return Qfalse;
68
+ if(eh == 1) return Qtrue;
69
+
70
+ return Qnil;
71
+ }
72
+
73
+ /*
74
+ * call-seq:
75
+ * value?
76
+ *
77
+ * Does this node have a text value?
78
+ */
79
+ static VALUE value_eh(VALUE self)
80
+ {
81
+ xmlTextReaderPtr reader;
82
+ int eh;
83
+
84
+ Data_Get_Struct(self, xmlTextReader, reader);
85
+ eh = xmlTextReaderHasValue(reader);
86
+ if(eh == 0) return Qfalse;
87
+ if(eh == 1) return Qtrue;
88
+
89
+ return Qnil;
90
+ }
91
+
92
+ /*
93
+ * call-seq:
94
+ * attributes?
95
+ *
96
+ * Does this node have attributes?
97
+ */
98
+ static VALUE attributes_eh(VALUE self)
99
+ {
100
+ xmlTextReaderPtr reader;
101
+ int eh;
102
+
103
+ Data_Get_Struct(self, xmlTextReader, reader);
104
+ eh = has_attributes(reader);
105
+ if(eh == 0) return Qfalse;
106
+ if(eh == 1) return Qtrue;
107
+
108
+ return Qnil;
109
+ }
110
+
111
+ /*
112
+ * call-seq:
113
+ * namespaces
114
+ *
115
+ * Get a hash of namespaces for this Node
116
+ */
117
+ static VALUE namespaces(VALUE self)
118
+ {
119
+ xmlTextReaderPtr reader;
120
+ xmlNodePtr ptr;
121
+ VALUE attr ;
122
+
123
+ Data_Get_Struct(self, xmlTextReader, reader);
124
+
125
+ attr = rb_hash_new() ;
126
+
127
+ if (! has_attributes(reader))
128
+ return attr ;
129
+
130
+ ptr = xmlTextReaderExpand(reader);
131
+ if(ptr == NULL) return Qnil;
132
+
133
+ Nokogiri_xml_node_namespaces(ptr, attr);
134
+
135
+ return attr ;
136
+ }
137
+
138
+ /*
139
+ * call-seq:
140
+ * attribute_nodes
141
+ *
142
+ * Get a list of attributes for this Node
143
+ */
144
+ static VALUE attribute_nodes(VALUE self)
145
+ {
146
+ xmlTextReaderPtr reader;
147
+ xmlNodePtr ptr;
148
+ VALUE attr ;
149
+
150
+ Data_Get_Struct(self, xmlTextReader, reader);
151
+
152
+ attr = rb_ary_new() ;
153
+
154
+ if (! has_attributes(reader))
155
+ return attr ;
156
+
157
+ ptr = xmlTextReaderExpand(reader);
158
+ if(ptr == NULL) return Qnil;
159
+
160
+ Nokogiri_xml_node_properties(ptr, attr);
161
+
162
+ return attr ;
163
+ }
164
+
165
+ /*
166
+ * call-seq:
167
+ * attribute_at(index)
168
+ *
169
+ * Get the value of attribute at +index+
170
+ */
171
+ static VALUE attribute_at(VALUE self, VALUE index)
172
+ {
173
+ xmlTextReaderPtr reader;
174
+ xmlChar *value;
175
+ VALUE rb_value;
176
+
177
+ Data_Get_Struct(self, xmlTextReader, reader);
178
+
179
+ if(NIL_P(index)) return Qnil;
180
+ index = rb_Integer(index);
181
+
182
+ value = xmlTextReaderGetAttributeNo(
183
+ reader,
184
+ (int)NUM2INT(index)
185
+ );
186
+ if(value == NULL) return Qnil;
187
+
188
+ rb_value = NOKOGIRI_STR_NEW2(value);
189
+ xmlFree(value);
190
+ return rb_value;
191
+ }
192
+
193
+ /*
194
+ * call-seq:
195
+ * attribute(name)
196
+ *
197
+ * Get the value of attribute named +name+
198
+ */
199
+ static VALUE reader_attribute(VALUE self, VALUE name)
200
+ {
201
+ xmlTextReaderPtr reader;
202
+ xmlChar *value ;
203
+ VALUE rb_value;
204
+
205
+ Data_Get_Struct(self, xmlTextReader, reader);
206
+
207
+ if(NIL_P(name)) return Qnil;
208
+ name = StringValue(name) ;
209
+
210
+ value = xmlTextReaderGetAttribute(reader, (xmlChar*)StringValueCStr(name));
211
+ if(value == NULL) return Qnil;
212
+
213
+ rb_value = NOKOGIRI_STR_NEW2(value);
214
+ xmlFree(value);
215
+ return rb_value;
216
+ }
217
+
218
+ /*
219
+ * call-seq:
220
+ * attribute_count
221
+ *
222
+ * Get the number of attributes for the current node
223
+ */
224
+ static VALUE attribute_count(VALUE self)
225
+ {
226
+ xmlTextReaderPtr reader;
227
+ int count;
228
+
229
+ Data_Get_Struct(self, xmlTextReader, reader);
230
+ count = xmlTextReaderAttributeCount(reader);
231
+ if(count == -1) return Qnil;
232
+
233
+ return INT2NUM((long)count);
234
+ }
235
+
236
+ /*
237
+ * call-seq:
238
+ * depth
239
+ *
240
+ * Get the depth of the node
241
+ */
242
+ static VALUE depth(VALUE self)
243
+ {
244
+ xmlTextReaderPtr reader;
245
+ int depth;
246
+
247
+ Data_Get_Struct(self, xmlTextReader, reader);
248
+ depth = xmlTextReaderDepth(reader);
249
+ if(depth == -1) return Qnil;
250
+
251
+ return INT2NUM((long)depth);
252
+ }
253
+
254
+ /*
255
+ * call-seq:
256
+ * xml_version
257
+ *
258
+ * Get the XML version of the document being read
259
+ */
260
+ static VALUE xml_version(VALUE self)
261
+ {
262
+ xmlTextReaderPtr reader;
263
+ const char *version;
264
+
265
+ Data_Get_Struct(self, xmlTextReader, reader);
266
+ version = (const char *)xmlTextReaderConstXmlVersion(reader);
267
+ if(version == NULL) return Qnil;
268
+
269
+ return NOKOGIRI_STR_NEW2(version);
270
+ }
271
+
272
+ /*
273
+ * call-seq:
274
+ * lang
275
+ *
276
+ * Get the xml:lang scope within which the node resides.
277
+ */
278
+ static VALUE lang(VALUE self)
279
+ {
280
+ xmlTextReaderPtr reader;
281
+ const char *lang;
282
+
283
+ Data_Get_Struct(self, xmlTextReader, reader);
284
+ lang = (const char *)xmlTextReaderConstXmlLang(reader);
285
+ if(lang == NULL) return Qnil;
286
+
287
+ return NOKOGIRI_STR_NEW2(lang);
288
+ }
289
+
290
+ /*
291
+ * call-seq:
292
+ * value
293
+ *
294
+ * Get the text value of the node if present. Returns a utf-8 encoded string.
295
+ */
296
+ static VALUE value(VALUE self)
297
+ {
298
+ xmlTextReaderPtr reader;
299
+ const char *value;
300
+
301
+ Data_Get_Struct(self, xmlTextReader, reader);
302
+ value = (const char *)xmlTextReaderConstValue(reader);
303
+ if(value == NULL) return Qnil;
304
+
305
+ return NOKOGIRI_STR_NEW2(value);
306
+ }
307
+
308
+ /*
309
+ * call-seq:
310
+ * prefix
311
+ *
312
+ * Get the shorthand reference to the namespace associated with the node.
313
+ */
314
+ static VALUE prefix(VALUE self)
315
+ {
316
+ xmlTextReaderPtr reader;
317
+ const char *prefix;
318
+
319
+ Data_Get_Struct(self, xmlTextReader, reader);
320
+ prefix = (const char *)xmlTextReaderConstPrefix(reader);
321
+ if(prefix == NULL) return Qnil;
322
+
323
+ return NOKOGIRI_STR_NEW2(prefix);
324
+ }
325
+
326
+ /*
327
+ * call-seq:
328
+ * namespace_uri
329
+ *
330
+ * Get the URI defining the namespace associated with the node
331
+ */
332
+ static VALUE namespace_uri(VALUE self)
333
+ {
334
+ xmlTextReaderPtr reader;
335
+ const char *uri;
336
+
337
+ Data_Get_Struct(self, xmlTextReader, reader);
338
+ uri = (const char *)xmlTextReaderConstNamespaceUri(reader);
339
+ if(uri == NULL) return Qnil;
340
+
341
+ return NOKOGIRI_STR_NEW2(uri);
342
+ }
343
+
344
+ /*
345
+ * call-seq:
346
+ * local_name
347
+ *
348
+ * Get the local name of the node
349
+ */
350
+ static VALUE local_name(VALUE self)
351
+ {
352
+ xmlTextReaderPtr reader;
353
+ const char *name;
354
+
355
+ Data_Get_Struct(self, xmlTextReader, reader);
356
+ name = (const char *)xmlTextReaderConstLocalName(reader);
357
+ if(name == NULL) return Qnil;
358
+
359
+ return NOKOGIRI_STR_NEW2(name);
360
+ }
361
+
362
+ /*
363
+ * call-seq:
364
+ * name
365
+ *
366
+ * Get the name of the node. Returns a utf-8 encoded string.
367
+ */
368
+ static VALUE name(VALUE self)
369
+ {
370
+ xmlTextReaderPtr reader;
371
+ const char *name;
372
+
373
+ Data_Get_Struct(self, xmlTextReader, reader);
374
+ name = (const char *)xmlTextReaderConstName(reader);
375
+ if(name == NULL) return Qnil;
376
+
377
+ return NOKOGIRI_STR_NEW2(name);
378
+ }
379
+
380
+ /*
381
+ * call-seq:
382
+ * base_uri
383
+ *
384
+ * Get the xml:base of the node
385
+ */
386
+ static VALUE base_uri(VALUE self)
387
+ {
388
+ xmlTextReaderPtr reader;
389
+ const char * base_uri;
390
+
391
+ Data_Get_Struct(self, xmlTextReader, reader);
392
+ base_uri = (const char *)xmlTextReaderBaseUri(reader);
393
+ if (base_uri == NULL) return Qnil;
394
+
395
+ return NOKOGIRI_STR_NEW2(base_uri);
396
+ }
397
+
398
+ /*
399
+ * call-seq:
400
+ * state
401
+ *
402
+ * Get the state of the reader
403
+ */
404
+ static VALUE state(VALUE self)
405
+ {
406
+ xmlTextReaderPtr reader;
407
+ Data_Get_Struct(self, xmlTextReader, reader);
408
+ return INT2NUM((long)xmlTextReaderReadState(reader));
409
+ }
410
+
411
+ /*
412
+ * call-seq:
413
+ * node_type
414
+ *
415
+ * Get the type of readers current node
416
+ */
417
+ static VALUE node_type(VALUE self)
418
+ {
419
+ xmlTextReaderPtr reader;
420
+ Data_Get_Struct(self, xmlTextReader, reader);
421
+ return INT2NUM((long)xmlTextReaderNodeType(reader));
422
+ }
423
+
424
+ /*
425
+ * call-seq:
426
+ * read
427
+ *
428
+ * Move the Reader forward through the XML document.
429
+ */
430
+ static VALUE read_more(VALUE self)
431
+ {
432
+ xmlTextReaderPtr reader;
433
+ xmlErrorPtr error;
434
+ VALUE error_list;
435
+ int ret;
436
+
437
+ Data_Get_Struct(self, xmlTextReader, reader);
438
+
439
+ error_list = rb_funcall(self, rb_intern("errors"), 0);
440
+
441
+ xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
442
+ ret = xmlTextReaderRead(reader);
443
+ xmlSetStructuredErrorFunc(NULL, NULL);
444
+
445
+ if(ret == 1) return self;
446
+ if(ret == 0) return Qnil;
447
+
448
+ error = xmlGetLastError();
449
+ if(error)
450
+ rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
451
+ else
452
+ rb_raise(rb_eRuntimeError, "Error pulling: %d", ret);
453
+
454
+ return Qnil;
455
+ }
456
+
457
+ /*
458
+ * call-seq:
459
+ * inner_xml
460
+ *
461
+ * Read the contents of the current node, including child nodes and markup.
462
+ * Returns a utf-8 encoded string.
463
+ */
464
+ static VALUE inner_xml(VALUE self)
465
+ {
466
+ xmlTextReaderPtr reader;
467
+ xmlChar* value;
468
+ VALUE str;
469
+
470
+ Data_Get_Struct(self, xmlTextReader, reader);
471
+
472
+ value = xmlTextReaderReadInnerXml(reader);
473
+
474
+ str = Qnil;
475
+ if(value) {
476
+ str = NOKOGIRI_STR_NEW2((char*)value);
477
+ xmlFree(value);
478
+ }
479
+
480
+ return str;
481
+ }
482
+
483
+ /*
484
+ * call-seq:
485
+ * outer_xml
486
+ *
487
+ * Read the current node and its contents, including child nodes and markup.
488
+ * Returns a utf-8 encoded string.
489
+ */
490
+ static VALUE outer_xml(VALUE self)
491
+ {
492
+ xmlTextReaderPtr reader;
493
+ xmlChar *value;
494
+ VALUE str = Qnil;
495
+
496
+ Data_Get_Struct(self, xmlTextReader, reader);
497
+
498
+ value = xmlTextReaderReadOuterXml(reader);
499
+
500
+ if(value) {
501
+ str = NOKOGIRI_STR_NEW2((char*)value);
502
+ xmlFree(value);
503
+ }
504
+ return str;
505
+ }
506
+
507
+ /*
508
+ * call-seq:
509
+ * from_memory(string, url = nil, encoding = nil, options = 0)
510
+ *
511
+ * Create a new reader that parses +string+
512
+ */
513
+ static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
514
+ {
515
+ VALUE rb_buffer, rb_url, encoding, rb_options;
516
+ xmlTextReaderPtr reader;
517
+ const char * c_url = NULL;
518
+ const char * c_encoding = NULL;
519
+ int c_options = 0;
520
+ VALUE rb_reader, args[3];
521
+
522
+ rb_scan_args(argc, argv, "13", &rb_buffer, &rb_url, &encoding, &rb_options);
523
+
524
+ if (!RTEST(rb_buffer)) rb_raise(rb_eArgError, "string cannot be nil");
525
+ if (RTEST(rb_url)) c_url = StringValueCStr(rb_url);
526
+ if (RTEST(encoding)) c_encoding = StringValueCStr(encoding);
527
+ if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options);
528
+
529
+ reader = xmlReaderForMemory(
530
+ StringValuePtr(rb_buffer),
531
+ (int)RSTRING_LEN(rb_buffer),
532
+ c_url,
533
+ c_encoding,
534
+ c_options
535
+ );
536
+
537
+ if(reader == NULL) {
538
+ xmlFreeTextReader(reader);
539
+ rb_raise(rb_eRuntimeError, "couldn't create a parser");
540
+ }
541
+
542
+ rb_reader = Data_Wrap_Struct(klass, NULL, dealloc, reader);
543
+ args[0] = rb_buffer;
544
+ args[1] = rb_url;
545
+ args[2] = encoding;
546
+ rb_obj_call_init(rb_reader, 3, args);
547
+
548
+ return rb_reader;
549
+ }
550
+
551
+ /*
552
+ * call-seq:
553
+ * from_io(io, url = nil, encoding = nil, options = 0)
554
+ *
555
+ * Create a new reader that parses +io+
556
+ */
557
+ static VALUE from_io(int argc, VALUE *argv, VALUE klass)
558
+ {
559
+ VALUE rb_io, rb_url, encoding, rb_options;
560
+ xmlTextReaderPtr reader;
561
+ const char * c_url = NULL;
562
+ const char * c_encoding = NULL;
563
+ int c_options = 0;
564
+ VALUE rb_reader, args[3];
565
+
566
+ rb_scan_args(argc, argv, "13", &rb_io, &rb_url, &encoding, &rb_options);
567
+
568
+ if (!RTEST(rb_io)) rb_raise(rb_eArgError, "io cannot be nil");
569
+ if (RTEST(rb_url)) c_url = StringValueCStr(rb_url);
570
+ if (RTEST(encoding)) c_encoding = StringValueCStr(encoding);
571
+ if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options);
572
+
573
+ reader = xmlReaderForIO(
574
+ (xmlInputReadCallback)io_read_callback,
575
+ (xmlInputCloseCallback)io_close_callback,
576
+ (void *)rb_io,
577
+ c_url,
578
+ c_encoding,
579
+ c_options
580
+ );
581
+
582
+ if(reader == NULL) {
583
+ xmlFreeTextReader(reader);
584
+ rb_raise(rb_eRuntimeError, "couldn't create a parser");
585
+ }
586
+
587
+ rb_reader = Data_Wrap_Struct(klass, NULL, dealloc, reader);
588
+ args[0] = rb_io;
589
+ args[1] = rb_url;
590
+ args[2] = encoding;
591
+ rb_obj_call_init(rb_reader, 3, args);
592
+
593
+ return rb_reader;
594
+ }
595
+
596
+ /*
597
+ * call-seq:
598
+ * reader.empty_element? # => true or false
599
+ *
600
+ * Returns true if the current node is empty, otherwise false.
601
+ */
602
+ static VALUE empty_element_p(VALUE self)
603
+ {
604
+ xmlTextReaderPtr reader;
605
+
606
+ Data_Get_Struct(self, xmlTextReader, reader);
607
+
608
+ if(xmlTextReaderIsEmptyElement(reader))
609
+ return Qtrue;
610
+
611
+ return Qfalse;
612
+ }
613
+
614
+ VALUE cNokogiriXmlReader;
615
+
616
+ void init_xml_reader()
617
+ {
618
+ VALUE module = rb_define_module("Nokogiri");
619
+ VALUE xml = rb_define_module_under(module, "XML");
620
+
621
+ /*
622
+ * The Reader parser allows you to effectively pull parse an XML document.
623
+ * Once instantiated, call Nokogiri::XML::Reader#each to iterate over each
624
+ * node. Note that you may only iterate over the document once!
625
+ */
626
+ VALUE klass = rb_define_class_under(xml, "Reader", rb_cObject);
627
+
628
+ cNokogiriXmlReader = klass;
629
+
630
+ rb_define_singleton_method(klass, "from_memory", from_memory, -1);
631
+ rb_define_singleton_method(klass, "from_io", from_io, -1);
632
+
633
+ rb_define_method(klass, "read", read_more, 0);
634
+ rb_define_method(klass, "inner_xml", inner_xml, 0);
635
+ rb_define_method(klass, "outer_xml", outer_xml, 0);
636
+ rb_define_method(klass, "state", state, 0);
637
+ rb_define_method(klass, "node_type", node_type, 0);
638
+ rb_define_method(klass, "name", name, 0);
639
+ rb_define_method(klass, "local_name", local_name, 0);
640
+ rb_define_method(klass, "namespace_uri", namespace_uri, 0);
641
+ rb_define_method(klass, "prefix", prefix, 0);
642
+ rb_define_method(klass, "value", value, 0);
643
+ rb_define_method(klass, "lang", lang, 0);
644
+ rb_define_method(klass, "xml_version", xml_version, 0);
645
+ rb_define_method(klass, "depth", depth, 0);
646
+ rb_define_method(klass, "attribute_count", attribute_count, 0);
647
+ rb_define_method(klass, "attribute", reader_attribute, 1);
648
+ rb_define_method(klass, "namespaces", namespaces, 0);
649
+ rb_define_method(klass, "attribute_at", attribute_at, 1);
650
+ rb_define_method(klass, "empty_element?", empty_element_p, 0);
651
+ rb_define_method(klass, "attributes?", attributes_eh, 0);
652
+ rb_define_method(klass, "value?", value_eh, 0);
653
+ rb_define_method(klass, "default?", default_eh, 0);
654
+ rb_define_method(klass, "base_uri", base_uri, 0);
655
+
656
+ rb_define_private_method(klass, "attr_nodes", attribute_nodes, 0);
657
+ }