nokogiri 1.6.2.rc1-x64-mingw32

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 (263) hide show
  1. checksums.yaml +7 -0
  2. data/.autotest +26 -0
  3. data/.editorconfig +17 -0
  4. data/.gemtest +0 -0
  5. data/.travis.yml +25 -0
  6. data/CHANGELOG.ja.rdoc +857 -0
  7. data/CHANGELOG.rdoc +880 -0
  8. data/C_CODING_STYLE.rdoc +33 -0
  9. data/Gemfile +21 -0
  10. data/Manifest.txt +371 -0
  11. data/README.ja.rdoc +112 -0
  12. data/README.rdoc +180 -0
  13. data/ROADMAP.md +89 -0
  14. data/Rakefile +351 -0
  15. data/STANDARD_RESPONSES.md +47 -0
  16. data/Y_U_NO_GEMSPEC.md +155 -0
  17. data/bin/nokogiri +78 -0
  18. data/build_all +130 -0
  19. data/dependencies.yml +4 -0
  20. data/ext/nokogiri/depend +358 -0
  21. data/ext/nokogiri/extconf.rb +453 -0
  22. data/ext/nokogiri/html_document.c +170 -0
  23. data/ext/nokogiri/html_document.h +10 -0
  24. data/ext/nokogiri/html_element_description.c +279 -0
  25. data/ext/nokogiri/html_element_description.h +10 -0
  26. data/ext/nokogiri/html_entity_lookup.c +32 -0
  27. data/ext/nokogiri/html_entity_lookup.h +8 -0
  28. data/ext/nokogiri/html_sax_parser_context.c +116 -0
  29. data/ext/nokogiri/html_sax_parser_context.h +11 -0
  30. data/ext/nokogiri/html_sax_push_parser.c +87 -0
  31. data/ext/nokogiri/html_sax_push_parser.h +9 -0
  32. data/ext/nokogiri/nokogiri.c +148 -0
  33. data/ext/nokogiri/nokogiri.h +164 -0
  34. data/ext/nokogiri/xml_attr.c +94 -0
  35. data/ext/nokogiri/xml_attr.h +9 -0
  36. data/ext/nokogiri/xml_attribute_decl.c +70 -0
  37. data/ext/nokogiri/xml_attribute_decl.h +9 -0
  38. data/ext/nokogiri/xml_cdata.c +56 -0
  39. data/ext/nokogiri/xml_cdata.h +9 -0
  40. data/ext/nokogiri/xml_comment.c +54 -0
  41. data/ext/nokogiri/xml_comment.h +9 -0
  42. data/ext/nokogiri/xml_document.c +577 -0
  43. data/ext/nokogiri/xml_document.h +23 -0
  44. data/ext/nokogiri/xml_document_fragment.c +48 -0
  45. data/ext/nokogiri/xml_document_fragment.h +10 -0
  46. data/ext/nokogiri/xml_dtd.c +202 -0
  47. data/ext/nokogiri/xml_dtd.h +10 -0
  48. data/ext/nokogiri/xml_element_content.c +123 -0
  49. data/ext/nokogiri/xml_element_content.h +10 -0
  50. data/ext/nokogiri/xml_element_decl.c +69 -0
  51. data/ext/nokogiri/xml_element_decl.h +9 -0
  52. data/ext/nokogiri/xml_encoding_handler.c +79 -0
  53. data/ext/nokogiri/xml_encoding_handler.h +8 -0
  54. data/ext/nokogiri/xml_entity_decl.c +110 -0
  55. data/ext/nokogiri/xml_entity_decl.h +10 -0
  56. data/ext/nokogiri/xml_entity_reference.c +52 -0
  57. data/ext/nokogiri/xml_entity_reference.h +9 -0
  58. data/ext/nokogiri/xml_io.c +56 -0
  59. data/ext/nokogiri/xml_io.h +11 -0
  60. data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
  61. data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
  62. data/ext/nokogiri/xml_namespace.c +78 -0
  63. data/ext/nokogiri/xml_namespace.h +13 -0
  64. data/ext/nokogiri/xml_node.c +1541 -0
  65. data/ext/nokogiri/xml_node.h +13 -0
  66. data/ext/nokogiri/xml_node_set.c +467 -0
  67. data/ext/nokogiri/xml_node_set.h +14 -0
  68. data/ext/nokogiri/xml_processing_instruction.c +56 -0
  69. data/ext/nokogiri/xml_processing_instruction.h +9 -0
  70. data/ext/nokogiri/xml_reader.c +681 -0
  71. data/ext/nokogiri/xml_reader.h +10 -0
  72. data/ext/nokogiri/xml_relax_ng.c +161 -0
  73. data/ext/nokogiri/xml_relax_ng.h +9 -0
  74. data/ext/nokogiri/xml_sax_parser.c +312 -0
  75. data/ext/nokogiri/xml_sax_parser.h +39 -0
  76. data/ext/nokogiri/xml_sax_parser_context.c +262 -0
  77. data/ext/nokogiri/xml_sax_parser_context.h +10 -0
  78. data/ext/nokogiri/xml_sax_push_parser.c +115 -0
  79. data/ext/nokogiri/xml_sax_push_parser.h +9 -0
  80. data/ext/nokogiri/xml_schema.c +205 -0
  81. data/ext/nokogiri/xml_schema.h +9 -0
  82. data/ext/nokogiri/xml_syntax_error.c +63 -0
  83. data/ext/nokogiri/xml_syntax_error.h +13 -0
  84. data/ext/nokogiri/xml_text.c +52 -0
  85. data/ext/nokogiri/xml_text.h +9 -0
  86. data/ext/nokogiri/xml_xpath_context.c +307 -0
  87. data/ext/nokogiri/xml_xpath_context.h +10 -0
  88. data/ext/nokogiri/xslt_stylesheet.c +270 -0
  89. data/ext/nokogiri/xslt_stylesheet.h +14 -0
  90. data/lib/nokogiri.rb +137 -0
  91. data/lib/nokogiri/2.0/nokogiri.so +0 -0
  92. data/lib/nokogiri/2.1/nokogiri.so +0 -0
  93. data/lib/nokogiri/css.rb +27 -0
  94. data/lib/nokogiri/css/node.rb +52 -0
  95. data/lib/nokogiri/css/parser.rb +715 -0
  96. data/lib/nokogiri/css/parser.y +249 -0
  97. data/lib/nokogiri/css/parser_extras.rb +91 -0
  98. data/lib/nokogiri/css/syntax_error.rb +7 -0
  99. data/lib/nokogiri/css/tokenizer.rb +152 -0
  100. data/lib/nokogiri/css/tokenizer.rex +55 -0
  101. data/lib/nokogiri/css/xpath_visitor.rb +219 -0
  102. data/lib/nokogiri/decorators/slop.rb +35 -0
  103. data/lib/nokogiri/html.rb +37 -0
  104. data/lib/nokogiri/html/builder.rb +35 -0
  105. data/lib/nokogiri/html/document.rb +333 -0
  106. data/lib/nokogiri/html/document_fragment.rb +41 -0
  107. data/lib/nokogiri/html/element_description.rb +23 -0
  108. data/lib/nokogiri/html/element_description_defaults.rb +671 -0
  109. data/lib/nokogiri/html/entity_lookup.rb +13 -0
  110. data/lib/nokogiri/html/sax/parser.rb +52 -0
  111. data/lib/nokogiri/html/sax/parser_context.rb +16 -0
  112. data/lib/nokogiri/html/sax/push_parser.rb +16 -0
  113. data/lib/nokogiri/syntax_error.rb +4 -0
  114. data/lib/nokogiri/version.rb +106 -0
  115. data/lib/nokogiri/xml.rb +73 -0
  116. data/lib/nokogiri/xml/attr.rb +14 -0
  117. data/lib/nokogiri/xml/attribute_decl.rb +18 -0
  118. data/lib/nokogiri/xml/builder.rb +443 -0
  119. data/lib/nokogiri/xml/cdata.rb +11 -0
  120. data/lib/nokogiri/xml/character_data.rb +7 -0
  121. data/lib/nokogiri/xml/document.rb +279 -0
  122. data/lib/nokogiri/xml/document_fragment.rb +112 -0
  123. data/lib/nokogiri/xml/dtd.rb +32 -0
  124. data/lib/nokogiri/xml/element_content.rb +36 -0
  125. data/lib/nokogiri/xml/element_decl.rb +13 -0
  126. data/lib/nokogiri/xml/entity_decl.rb +19 -0
  127. data/lib/nokogiri/xml/namespace.rb +13 -0
  128. data/lib/nokogiri/xml/node.rb +982 -0
  129. data/lib/nokogiri/xml/node/save_options.rb +61 -0
  130. data/lib/nokogiri/xml/node_set.rb +355 -0
  131. data/lib/nokogiri/xml/notation.rb +6 -0
  132. data/lib/nokogiri/xml/parse_options.rb +98 -0
  133. data/lib/nokogiri/xml/pp.rb +2 -0
  134. data/lib/nokogiri/xml/pp/character_data.rb +18 -0
  135. data/lib/nokogiri/xml/pp/node.rb +56 -0
  136. data/lib/nokogiri/xml/processing_instruction.rb +8 -0
  137. data/lib/nokogiri/xml/reader.rb +112 -0
  138. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  139. data/lib/nokogiri/xml/sax.rb +4 -0
  140. data/lib/nokogiri/xml/sax/document.rb +171 -0
  141. data/lib/nokogiri/xml/sax/parser.rb +123 -0
  142. data/lib/nokogiri/xml/sax/parser_context.rb +16 -0
  143. data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
  144. data/lib/nokogiri/xml/schema.rb +63 -0
  145. data/lib/nokogiri/xml/syntax_error.rb +47 -0
  146. data/lib/nokogiri/xml/text.rb +9 -0
  147. data/lib/nokogiri/xml/xpath.rb +10 -0
  148. data/lib/nokogiri/xml/xpath/syntax_error.rb +11 -0
  149. data/lib/nokogiri/xml/xpath_context.rb +16 -0
  150. data/lib/nokogiri/xslt.rb +56 -0
  151. data/lib/nokogiri/xslt/stylesheet.rb +25 -0
  152. data/lib/xsd/xmlparser/nokogiri.rb +102 -0
  153. data/suppressions/README.txt +1 -0
  154. data/suppressions/nokogiri_ree-1.8.7.358.supp +61 -0
  155. data/suppressions/nokogiri_ruby-1.8.7.370.supp +0 -0
  156. data/suppressions/nokogiri_ruby-1.9.2.320.supp +28 -0
  157. data/suppressions/nokogiri_ruby-1.9.3.327.supp +28 -0
  158. data/tasks/nokogiri.org.rb +24 -0
  159. data/tasks/test.rb +95 -0
  160. data/test/css/test_nthiness.rb +222 -0
  161. data/test/css/test_parser.rb +358 -0
  162. data/test/css/test_tokenizer.rb +198 -0
  163. data/test/css/test_xpath_visitor.rb +96 -0
  164. data/test/decorators/test_slop.rb +16 -0
  165. data/test/files/2ch.html +108 -0
  166. data/test/files/address_book.rlx +12 -0
  167. data/test/files/address_book.xml +10 -0
  168. data/test/files/atom.xml +344 -0
  169. data/test/files/bar/bar.xsd +4 -0
  170. data/test/files/bogus.xml +0 -0
  171. data/test/files/dont_hurt_em_why.xml +422 -0
  172. data/test/files/encoding.html +82 -0
  173. data/test/files/encoding.xhtml +84 -0
  174. data/test/files/exslt.xml +8 -0
  175. data/test/files/exslt.xslt +35 -0
  176. data/test/files/foo/foo.xsd +4 -0
  177. data/test/files/metacharset.html +10 -0
  178. data/test/files/noencoding.html +47 -0
  179. data/test/files/po.xml +32 -0
  180. data/test/files/po.xsd +66 -0
  181. data/test/files/saml/saml20assertion_schema.xsd +283 -0
  182. data/test/files/saml/saml20protocol_schema.xsd +302 -0
  183. data/test/files/saml/xenc_schema.xsd +146 -0
  184. data/test/files/saml/xmldsig_schema.xsd +318 -0
  185. data/test/files/shift_jis.html +10 -0
  186. data/test/files/shift_jis.xml +5 -0
  187. data/test/files/shift_jis_no_charset.html +9 -0
  188. data/test/files/snuggles.xml +3 -0
  189. data/test/files/staff.dtd +10 -0
  190. data/test/files/staff.xml +59 -0
  191. data/test/files/staff.xslt +32 -0
  192. data/test/files/test_document_url/bar.xml +2 -0
  193. data/test/files/test_document_url/document.dtd +4 -0
  194. data/test/files/test_document_url/document.xml +6 -0
  195. data/test/files/tlm.html +850 -0
  196. data/test/files/to_be_xincluded.xml +2 -0
  197. data/test/files/valid_bar.xml +2 -0
  198. data/test/files/xinclude.xml +4 -0
  199. data/test/helper.rb +164 -0
  200. data/test/html/sax/test_parser.rb +141 -0
  201. data/test/html/sax/test_parser_context.rb +46 -0
  202. data/test/html/test_builder.rb +164 -0
  203. data/test/html/test_document.rb +619 -0
  204. data/test/html/test_document_encoding.rb +148 -0
  205. data/test/html/test_document_fragment.rb +261 -0
  206. data/test/html/test_element_description.rb +105 -0
  207. data/test/html/test_named_characters.rb +14 -0
  208. data/test/html/test_node.rb +196 -0
  209. data/test/html/test_node_encoding.rb +27 -0
  210. data/test/namespaces/test_additional_namespaces_in_builder_doc.rb +14 -0
  211. data/test/namespaces/test_namespaces_in_builder_doc.rb +75 -0
  212. data/test/namespaces/test_namespaces_in_cloned_doc.rb +31 -0
  213. data/test/namespaces/test_namespaces_in_created_doc.rb +75 -0
  214. data/test/namespaces/test_namespaces_in_parsed_doc.rb +66 -0
  215. data/test/test_convert_xpath.rb +135 -0
  216. data/test/test_css_cache.rb +45 -0
  217. data/test/test_encoding_handler.rb +46 -0
  218. data/test/test_memory_leak.rb +156 -0
  219. data/test/test_nokogiri.rb +138 -0
  220. data/test/test_reader.rb +558 -0
  221. data/test/test_soap4r_sax.rb +52 -0
  222. data/test/test_xslt_transforms.rb +279 -0
  223. data/test/xml/node/test_save_options.rb +28 -0
  224. data/test/xml/node/test_subclass.rb +44 -0
  225. data/test/xml/sax/test_parser.rb +382 -0
  226. data/test/xml/sax/test_parser_context.rb +115 -0
  227. data/test/xml/sax/test_push_parser.rb +157 -0
  228. data/test/xml/test_attr.rb +64 -0
  229. data/test/xml/test_attribute_decl.rb +86 -0
  230. data/test/xml/test_builder.rb +315 -0
  231. data/test/xml/test_c14n.rb +161 -0
  232. data/test/xml/test_cdata.rb +48 -0
  233. data/test/xml/test_comment.rb +29 -0
  234. data/test/xml/test_document.rb +934 -0
  235. data/test/xml/test_document_encoding.rb +28 -0
  236. data/test/xml/test_document_fragment.rb +228 -0
  237. data/test/xml/test_dtd.rb +187 -0
  238. data/test/xml/test_dtd_encoding.rb +33 -0
  239. data/test/xml/test_element_content.rb +56 -0
  240. data/test/xml/test_element_decl.rb +73 -0
  241. data/test/xml/test_entity_decl.rb +122 -0
  242. data/test/xml/test_entity_reference.rb +245 -0
  243. data/test/xml/test_namespace.rb +95 -0
  244. data/test/xml/test_node.rb +1155 -0
  245. data/test/xml/test_node_attributes.rb +113 -0
  246. data/test/xml/test_node_encoding.rb +107 -0
  247. data/test/xml/test_node_inheritance.rb +32 -0
  248. data/test/xml/test_node_reparenting.rb +374 -0
  249. data/test/xml/test_node_set.rb +755 -0
  250. data/test/xml/test_parse_options.rb +64 -0
  251. data/test/xml/test_processing_instruction.rb +30 -0
  252. data/test/xml/test_reader_encoding.rb +142 -0
  253. data/test/xml/test_relax_ng.rb +60 -0
  254. data/test/xml/test_schema.rb +129 -0
  255. data/test/xml/test_syntax_error.rb +12 -0
  256. data/test/xml/test_text.rb +45 -0
  257. data/test/xml/test_unparented_node.rb +422 -0
  258. data/test/xml/test_xinclude.rb +83 -0
  259. data/test/xml/test_xpath.rb +376 -0
  260. data/test/xslt/test_custom_functions.rb +133 -0
  261. data/test/xslt/test_exception_handling.rb +37 -0
  262. data/test_all +81 -0
  263. metadata +601 -0
@@ -0,0 +1,14 @@
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
+
10
+ typedef struct _nokogiriNodeSetTuple {
11
+ xmlNodeSetPtr node_set;
12
+ st_table *namespaces;
13
+ } nokogiriNodeSetTuple;
14
+ #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 *)StringValuePtr(name),
27
+ (const xmlChar *)StringValuePtr(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,681 @@
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
+ static char buffer[XMLNS_BUFFER_LEN] ;
32
+ char *key ;
33
+ size_t keylen ;
34
+
35
+ if (node->type != XML_ELEMENT_NODE) return ;
36
+
37
+ ns = node->nsDef;
38
+ while (ns != NULL) {
39
+
40
+ keylen = XMLNS_PREFIX_LEN + (ns->prefix ? (strlen((const char*)ns->prefix) + 1) : 0) ;
41
+ if (keylen > XMLNS_BUFFER_LEN) {
42
+ key = (char*)malloc(keylen) ;
43
+ } else {
44
+ key = buffer ;
45
+ }
46
+
47
+ if (ns->prefix) {
48
+ sprintf(key, "%s:%s", XMLNS_PREFIX, ns->prefix);
49
+ } else {
50
+ sprintf(key, "%s", XMLNS_PREFIX);
51
+ }
52
+
53
+ rb_hash_aset(attr_hash,
54
+ NOKOGIRI_STR_NEW2(key),
55
+ (ns->href ? NOKOGIRI_STR_NEW2(ns->href) : Qnil)
56
+ );
57
+ if (key != buffer) {
58
+ free(key);
59
+ }
60
+ ns = ns->next ;
61
+ }
62
+ }
63
+
64
+
65
+ /*
66
+ * call-seq:
67
+ * default?
68
+ *
69
+ * Was an attribute generated from the default value in the DTD or schema?
70
+ */
71
+ static VALUE default_eh(VALUE self)
72
+ {
73
+ xmlTextReaderPtr reader;
74
+ int eh;
75
+
76
+ Data_Get_Struct(self, xmlTextReader, reader);
77
+ eh = xmlTextReaderIsDefault(reader);
78
+ if(eh == 0) return Qfalse;
79
+ if(eh == 1) return Qtrue;
80
+
81
+ return Qnil;
82
+ }
83
+
84
+ /*
85
+ * call-seq:
86
+ * value?
87
+ *
88
+ * Does this node have a text value?
89
+ */
90
+ static VALUE value_eh(VALUE self)
91
+ {
92
+ xmlTextReaderPtr reader;
93
+ int eh;
94
+
95
+ Data_Get_Struct(self, xmlTextReader, reader);
96
+ eh = xmlTextReaderHasValue(reader);
97
+ if(eh == 0) return Qfalse;
98
+ if(eh == 1) return Qtrue;
99
+
100
+ return Qnil;
101
+ }
102
+
103
+ /*
104
+ * call-seq:
105
+ * attributes?
106
+ *
107
+ * Does this node have attributes?
108
+ */
109
+ static VALUE attributes_eh(VALUE self)
110
+ {
111
+ xmlTextReaderPtr reader;
112
+ int eh;
113
+
114
+ Data_Get_Struct(self, xmlTextReader, reader);
115
+ eh = has_attributes(reader);
116
+ if(eh == 0) return Qfalse;
117
+ if(eh == 1) return Qtrue;
118
+
119
+ return Qnil;
120
+ }
121
+
122
+ /*
123
+ * call-seq:
124
+ * namespaces
125
+ *
126
+ * Get a hash of namespaces for this Node
127
+ */
128
+ static VALUE namespaces(VALUE self)
129
+ {
130
+ xmlTextReaderPtr reader;
131
+ xmlNodePtr ptr;
132
+ VALUE attr ;
133
+
134
+ Data_Get_Struct(self, xmlTextReader, reader);
135
+
136
+ attr = rb_hash_new() ;
137
+
138
+ if (! has_attributes(reader))
139
+ return attr ;
140
+
141
+ ptr = xmlTextReaderExpand(reader);
142
+ if(ptr == NULL) return Qnil;
143
+
144
+ Nokogiri_xml_node_namespaces(ptr, attr);
145
+
146
+ return attr ;
147
+ }
148
+
149
+ /*
150
+ * call-seq:
151
+ * attribute_nodes
152
+ *
153
+ * Get a list of attributes for this Node
154
+ */
155
+ static VALUE attribute_nodes(VALUE self)
156
+ {
157
+ xmlTextReaderPtr reader;
158
+ xmlNodePtr ptr;
159
+ VALUE attr ;
160
+
161
+ Data_Get_Struct(self, xmlTextReader, reader);
162
+
163
+ attr = rb_ary_new() ;
164
+
165
+ if (! has_attributes(reader))
166
+ return attr ;
167
+
168
+ ptr = xmlTextReaderExpand(reader);
169
+ if(ptr == NULL) return Qnil;
170
+
171
+ Nokogiri_xml_node_properties(ptr, attr);
172
+
173
+ return attr ;
174
+ }
175
+
176
+ /*
177
+ * call-seq:
178
+ * attribute_at(index)
179
+ *
180
+ * Get the value of attribute at +index+
181
+ */
182
+ static VALUE attribute_at(VALUE self, VALUE index)
183
+ {
184
+ xmlTextReaderPtr reader;
185
+ xmlChar *value;
186
+ VALUE rb_value;
187
+
188
+ Data_Get_Struct(self, xmlTextReader, reader);
189
+
190
+ if(NIL_P(index)) return Qnil;
191
+ index = rb_Integer(index);
192
+
193
+ value = xmlTextReaderGetAttributeNo(
194
+ reader,
195
+ (int)NUM2INT(index)
196
+ );
197
+ if(value == NULL) return Qnil;
198
+
199
+ rb_value = NOKOGIRI_STR_NEW2(value);
200
+ xmlFree(value);
201
+ return rb_value;
202
+ }
203
+
204
+ /*
205
+ * call-seq:
206
+ * attribute(name)
207
+ *
208
+ * Get the value of attribute named +name+
209
+ */
210
+ static VALUE reader_attribute(VALUE self, VALUE name)
211
+ {
212
+ xmlTextReaderPtr reader;
213
+ xmlChar *value ;
214
+ VALUE rb_value;
215
+
216
+ Data_Get_Struct(self, xmlTextReader, reader);
217
+
218
+ if(NIL_P(name)) return Qnil;
219
+ name = StringValue(name) ;
220
+
221
+ value = xmlTextReaderGetAttribute(reader, (xmlChar*)StringValuePtr(name));
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;
236
+
237
+ rb_value = NOKOGIRI_STR_NEW2(value);
238
+ xmlFree(value);
239
+ return rb_value;
240
+ }
241
+
242
+ /*
243
+ * call-seq:
244
+ * attribute_count
245
+ *
246
+ * Get the number of attributes for the current node
247
+ */
248
+ static VALUE attribute_count(VALUE self)
249
+ {
250
+ xmlTextReaderPtr reader;
251
+ int count;
252
+
253
+ Data_Get_Struct(self, xmlTextReader, reader);
254
+ count = xmlTextReaderAttributeCount(reader);
255
+ if(count == -1) return Qnil;
256
+
257
+ return INT2NUM((long)count);
258
+ }
259
+
260
+ /*
261
+ * call-seq:
262
+ * depth
263
+ *
264
+ * Get the depth of the node
265
+ */
266
+ static VALUE depth(VALUE self)
267
+ {
268
+ xmlTextReaderPtr reader;
269
+ int depth;
270
+
271
+ Data_Get_Struct(self, xmlTextReader, reader);
272
+ depth = xmlTextReaderDepth(reader);
273
+ if(depth == -1) return Qnil;
274
+
275
+ return INT2NUM((long)depth);
276
+ }
277
+
278
+ /*
279
+ * call-seq:
280
+ * xml_version
281
+ *
282
+ * Get the XML version of the document being read
283
+ */
284
+ static VALUE xml_version(VALUE self)
285
+ {
286
+ xmlTextReaderPtr reader;
287
+ const char *version;
288
+
289
+ Data_Get_Struct(self, xmlTextReader, reader);
290
+ version = (const char *)xmlTextReaderConstXmlVersion(reader);
291
+ if(version == NULL) return Qnil;
292
+
293
+ return NOKOGIRI_STR_NEW2(version);
294
+ }
295
+
296
+ /*
297
+ * call-seq:
298
+ * lang
299
+ *
300
+ * Get the xml:lang scope within which the node resides.
301
+ */
302
+ static VALUE lang(VALUE self)
303
+ {
304
+ xmlTextReaderPtr reader;
305
+ const char *lang;
306
+
307
+ Data_Get_Struct(self, xmlTextReader, reader);
308
+ lang = (const char *)xmlTextReaderConstXmlLang(reader);
309
+ if(lang == NULL) return Qnil;
310
+
311
+ return NOKOGIRI_STR_NEW2(lang);
312
+ }
313
+
314
+ /*
315
+ * call-seq:
316
+ * value
317
+ *
318
+ * Get the text value of the node if present. Returns a utf-8 encoded string.
319
+ */
320
+ static VALUE value(VALUE self)
321
+ {
322
+ xmlTextReaderPtr reader;
323
+ const char *value;
324
+
325
+ Data_Get_Struct(self, xmlTextReader, reader);
326
+ value = (const char *)xmlTextReaderConstValue(reader);
327
+ if(value == NULL) return Qnil;
328
+
329
+ return NOKOGIRI_STR_NEW2(value);
330
+ }
331
+
332
+ /*
333
+ * call-seq:
334
+ * prefix
335
+ *
336
+ * Get the shorthand reference to the namespace associated with the node.
337
+ */
338
+ static VALUE prefix(VALUE self)
339
+ {
340
+ xmlTextReaderPtr reader;
341
+ const char *prefix;
342
+
343
+ Data_Get_Struct(self, xmlTextReader, reader);
344
+ prefix = (const char *)xmlTextReaderConstPrefix(reader);
345
+ if(prefix == NULL) return Qnil;
346
+
347
+ return NOKOGIRI_STR_NEW2(prefix);
348
+ }
349
+
350
+ /*
351
+ * call-seq:
352
+ * namespace_uri
353
+ *
354
+ * Get the URI defining the namespace associated with the node
355
+ */
356
+ static VALUE namespace_uri(VALUE self)
357
+ {
358
+ xmlTextReaderPtr reader;
359
+ const char *uri;
360
+
361
+ Data_Get_Struct(self, xmlTextReader, reader);
362
+ uri = (const char *)xmlTextReaderConstNamespaceUri(reader);
363
+ if(uri == NULL) return Qnil;
364
+
365
+ return NOKOGIRI_STR_NEW2(uri);
366
+ }
367
+
368
+ /*
369
+ * call-seq:
370
+ * local_name
371
+ *
372
+ * Get the local name of the node
373
+ */
374
+ static VALUE local_name(VALUE self)
375
+ {
376
+ xmlTextReaderPtr reader;
377
+ const char *name;
378
+
379
+ Data_Get_Struct(self, xmlTextReader, reader);
380
+ name = (const char *)xmlTextReaderConstLocalName(reader);
381
+ if(name == NULL) return Qnil;
382
+
383
+ return NOKOGIRI_STR_NEW2(name);
384
+ }
385
+
386
+ /*
387
+ * call-seq:
388
+ * name
389
+ *
390
+ * Get the name of the node. Returns a utf-8 encoded string.
391
+ */
392
+ static VALUE name(VALUE self)
393
+ {
394
+ xmlTextReaderPtr reader;
395
+ const char *name;
396
+
397
+ Data_Get_Struct(self, xmlTextReader, reader);
398
+ name = (const char *)xmlTextReaderConstName(reader);
399
+ if(name == NULL) return Qnil;
400
+
401
+ return NOKOGIRI_STR_NEW2(name);
402
+ }
403
+
404
+ /*
405
+ * call-seq:
406
+ * base_uri
407
+ *
408
+ * Get the xml:base of the node
409
+ */
410
+ static VALUE base_uri(VALUE self)
411
+ {
412
+ xmlTextReaderPtr reader;
413
+ const char * base_uri;
414
+
415
+ Data_Get_Struct(self, xmlTextReader, reader);
416
+ base_uri = (const char *)xmlTextReaderBaseUri(reader);
417
+ if (base_uri == NULL) return Qnil;
418
+
419
+ return NOKOGIRI_STR_NEW2(base_uri);
420
+ }
421
+
422
+ /*
423
+ * call-seq:
424
+ * state
425
+ *
426
+ * Get the state of the reader
427
+ */
428
+ static VALUE state(VALUE self)
429
+ {
430
+ xmlTextReaderPtr reader;
431
+ Data_Get_Struct(self, xmlTextReader, reader);
432
+ return INT2NUM((long)xmlTextReaderReadState(reader));
433
+ }
434
+
435
+ /*
436
+ * call-seq:
437
+ * node_type
438
+ *
439
+ * Get the type of readers current node
440
+ */
441
+ static VALUE node_type(VALUE self)
442
+ {
443
+ xmlTextReaderPtr reader;
444
+ Data_Get_Struct(self, xmlTextReader, reader);
445
+ return INT2NUM((long)xmlTextReaderNodeType(reader));
446
+ }
447
+
448
+ /*
449
+ * call-seq:
450
+ * read
451
+ *
452
+ * Move the Reader forward through the XML document.
453
+ */
454
+ static VALUE read_more(VALUE self)
455
+ {
456
+ xmlTextReaderPtr reader;
457
+ xmlErrorPtr error;
458
+ VALUE error_list;
459
+ int ret;
460
+
461
+ Data_Get_Struct(self, xmlTextReader, reader);
462
+
463
+ error_list = rb_funcall(self, rb_intern("errors"), 0);
464
+
465
+ xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
466
+ ret = xmlTextReaderRead(reader);
467
+ xmlSetStructuredErrorFunc(NULL, NULL);
468
+
469
+ if(ret == 1) return self;
470
+ if(ret == 0) return Qnil;
471
+
472
+ error = xmlGetLastError();
473
+ if(error)
474
+ rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
475
+ else
476
+ rb_raise(rb_eRuntimeError, "Error pulling: %d", ret);
477
+
478
+ return Qnil;
479
+ }
480
+
481
+ /*
482
+ * call-seq:
483
+ * inner_xml
484
+ *
485
+ * Read the contents of the current node, including child nodes and markup.
486
+ * Returns a utf-8 encoded string.
487
+ */
488
+ static VALUE inner_xml(VALUE self)
489
+ {
490
+ xmlTextReaderPtr reader;
491
+ xmlChar* value;
492
+ VALUE str;
493
+
494
+ Data_Get_Struct(self, xmlTextReader, reader);
495
+
496
+ value = xmlTextReaderReadInnerXml(reader);
497
+
498
+ str = Qnil;
499
+ if(value) {
500
+ str = NOKOGIRI_STR_NEW2((char*)value);
501
+ xmlFree(value);
502
+ }
503
+
504
+ return str;
505
+ }
506
+
507
+ /*
508
+ * call-seq:
509
+ * outer_xml
510
+ *
511
+ * Read the current node and its contents, including child nodes and markup.
512
+ * Returns a utf-8 encoded string.
513
+ */
514
+ static VALUE outer_xml(VALUE self)
515
+ {
516
+ xmlTextReaderPtr reader;
517
+ xmlChar *value;
518
+ VALUE str = Qnil;
519
+
520
+ Data_Get_Struct(self, xmlTextReader, reader);
521
+
522
+ value = xmlTextReaderReadOuterXml(reader);
523
+
524
+ if(value) {
525
+ str = NOKOGIRI_STR_NEW2((char*)value);
526
+ xmlFree(value);
527
+ }
528
+ return str;
529
+ }
530
+
531
+ /*
532
+ * call-seq:
533
+ * from_memory(string, url = nil, encoding = nil, options = 0)
534
+ *
535
+ * Create a new reader that parses +string+
536
+ */
537
+ static VALUE from_memory(int argc, VALUE *argv, VALUE klass)
538
+ {
539
+ VALUE rb_buffer, rb_url, encoding, rb_options;
540
+ xmlTextReaderPtr reader;
541
+ const char * c_url = NULL;
542
+ const char * c_encoding = NULL;
543
+ int c_options = 0;
544
+ VALUE rb_reader, args[3];
545
+
546
+ rb_scan_args(argc, argv, "13", &rb_buffer, &rb_url, &encoding, &rb_options);
547
+
548
+ if (!RTEST(rb_buffer)) rb_raise(rb_eArgError, "string cannot be nil");
549
+ if (RTEST(rb_url)) c_url = StringValuePtr(rb_url);
550
+ if (RTEST(encoding)) c_encoding = StringValuePtr(encoding);
551
+ if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options);
552
+
553
+ reader = xmlReaderForMemory(
554
+ StringValuePtr(rb_buffer),
555
+ (int)RSTRING_LEN(rb_buffer),
556
+ c_url,
557
+ c_encoding,
558
+ c_options
559
+ );
560
+
561
+ if(reader == NULL) {
562
+ xmlFreeTextReader(reader);
563
+ rb_raise(rb_eRuntimeError, "couldn't create a parser");
564
+ }
565
+
566
+ rb_reader = Data_Wrap_Struct(klass, NULL, dealloc, reader);
567
+ args[0] = rb_buffer;
568
+ args[1] = rb_url;
569
+ args[2] = encoding;
570
+ rb_obj_call_init(rb_reader, 3, args);
571
+
572
+ return rb_reader;
573
+ }
574
+
575
+ /*
576
+ * call-seq:
577
+ * from_io(io, url = nil, encoding = nil, options = 0)
578
+ *
579
+ * Create a new reader that parses +io+
580
+ */
581
+ static VALUE from_io(int argc, VALUE *argv, VALUE klass)
582
+ {
583
+ VALUE rb_io, rb_url, encoding, rb_options;
584
+ xmlTextReaderPtr reader;
585
+ const char * c_url = NULL;
586
+ const char * c_encoding = NULL;
587
+ int c_options = 0;
588
+ VALUE rb_reader, args[3];
589
+
590
+ rb_scan_args(argc, argv, "13", &rb_io, &rb_url, &encoding, &rb_options);
591
+
592
+ if (!RTEST(rb_io)) rb_raise(rb_eArgError, "io cannot be nil");
593
+ if (RTEST(rb_url)) c_url = StringValuePtr(rb_url);
594
+ if (RTEST(encoding)) c_encoding = StringValuePtr(encoding);
595
+ if (RTEST(rb_options)) c_options = (int)NUM2INT(rb_options);
596
+
597
+ reader = xmlReaderForIO(
598
+ (xmlInputReadCallback)io_read_callback,
599
+ (xmlInputCloseCallback)io_close_callback,
600
+ (void *)rb_io,
601
+ c_url,
602
+ c_encoding,
603
+ c_options
604
+ );
605
+
606
+ if(reader == NULL) {
607
+ xmlFreeTextReader(reader);
608
+ rb_raise(rb_eRuntimeError, "couldn't create a parser");
609
+ }
610
+
611
+ rb_reader = Data_Wrap_Struct(klass, NULL, dealloc, reader);
612
+ args[0] = rb_io;
613
+ args[1] = rb_url;
614
+ args[2] = encoding;
615
+ rb_obj_call_init(rb_reader, 3, args);
616
+
617
+ return rb_reader;
618
+ }
619
+
620
+ /*
621
+ * call-seq:
622
+ * reader.empty_element? # => true or false
623
+ *
624
+ * Returns true if the current node is empty, otherwise false.
625
+ */
626
+ static VALUE empty_element_p(VALUE self)
627
+ {
628
+ xmlTextReaderPtr reader;
629
+
630
+ Data_Get_Struct(self, xmlTextReader, reader);
631
+
632
+ if(xmlTextReaderIsEmptyElement(reader))
633
+ return Qtrue;
634
+
635
+ return Qfalse;
636
+ }
637
+
638
+ VALUE cNokogiriXmlReader;
639
+
640
+ void init_xml_reader()
641
+ {
642
+ VALUE module = rb_define_module("Nokogiri");
643
+ VALUE xml = rb_define_module_under(module, "XML");
644
+
645
+ /*
646
+ * The Reader parser allows you to effectively pull parse an XML document.
647
+ * Once instantiated, call Nokogiri::XML::Reader#each to iterate over each
648
+ * node. Note that you may only iterate over the document once!
649
+ */
650
+ VALUE klass = rb_define_class_under(xml, "Reader", rb_cObject);
651
+
652
+ cNokogiriXmlReader = klass;
653
+
654
+ rb_define_singleton_method(klass, "from_memory", from_memory, -1);
655
+ rb_define_singleton_method(klass, "from_io", from_io, -1);
656
+
657
+ rb_define_method(klass, "read", read_more, 0);
658
+ rb_define_method(klass, "inner_xml", inner_xml, 0);
659
+ rb_define_method(klass, "outer_xml", outer_xml, 0);
660
+ rb_define_method(klass, "state", state, 0);
661
+ rb_define_method(klass, "node_type", node_type, 0);
662
+ rb_define_method(klass, "name", name, 0);
663
+ rb_define_method(klass, "local_name", local_name, 0);
664
+ rb_define_method(klass, "namespace_uri", namespace_uri, 0);
665
+ rb_define_method(klass, "prefix", prefix, 0);
666
+ rb_define_method(klass, "value", value, 0);
667
+ rb_define_method(klass, "lang", lang, 0);
668
+ rb_define_method(klass, "xml_version", xml_version, 0);
669
+ rb_define_method(klass, "depth", depth, 0);
670
+ rb_define_method(klass, "attribute_count", attribute_count, 0);
671
+ rb_define_method(klass, "attribute", reader_attribute, 1);
672
+ rb_define_method(klass, "namespaces", namespaces, 0);
673
+ rb_define_method(klass, "attribute_at", attribute_at, 1);
674
+ rb_define_method(klass, "empty_element?", empty_element_p, 0);
675
+ rb_define_method(klass, "attributes?", attributes_eh, 0);
676
+ rb_define_method(klass, "value?", value_eh, 0);
677
+ rb_define_method(klass, "default?", default_eh, 0);
678
+ rb_define_method(klass, "base_uri", base_uri, 0);
679
+
680
+ rb_define_private_method(klass, "attr_nodes", attribute_nodes, 0);
681
+ }