coupa-libxml-ruby 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (280) hide show
  1. data/CHANGES +488 -0
  2. data/LICENSE +22 -0
  3. data/README +161 -0
  4. data/Rakefile +188 -0
  5. data/doc/css/normal.css +182 -0
  6. data/doc/img/raze-tiny.png +0 -0
  7. data/doc/img/red-cube.jpg +0 -0
  8. data/doc/img/xml-ruby.png +0 -0
  9. data/doc/index.xml +43 -0
  10. data/doc/install.xml +77 -0
  11. data/doc/layout.rhtml +38 -0
  12. data/doc/layout.xsl +67 -0
  13. data/doc/license.xml +32 -0
  14. data/doc/log/changelog.xml +1324 -0
  15. data/doc/log/changelog.xsl +42 -0
  16. data/doc/rdoc/classes/LibXML.html +207 -0
  17. data/doc/rdoc/classes/LibXML/XML.html +407 -0
  18. data/doc/rdoc/classes/LibXML/XML/Attr.html +521 -0
  19. data/doc/rdoc/classes/LibXML/XML/AttrDecl.html +360 -0
  20. data/doc/rdoc/classes/LibXML/XML/Attributes.html +149 -0
  21. data/doc/rdoc/classes/LibXML/XML/Document.html +460 -0
  22. data/doc/rdoc/classes/LibXML/XML/Error.html +129 -0
  23. data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +263 -0
  24. data/doc/rdoc/classes/LibXML/XML/Namespace.html +248 -0
  25. data/doc/rdoc/classes/LibXML/XML/Namespaces.html +200 -0
  26. data/doc/rdoc/classes/LibXML/XML/Node.html +1351 -0
  27. data/doc/rdoc/classes/LibXML/XML/Parser.html +328 -0
  28. data/doc/rdoc/classes/LibXML/XML/Reader.html +172 -0
  29. data/doc/rdoc/classes/LibXML/XML/SaxParser.html +232 -0
  30. data/doc/rdoc/classes/LibXML/XML/SaxParser/Callbacks.html +506 -0
  31. data/doc/rdoc/classes/LibXML/XML/SaxParser/VerboseCallbacks.html +555 -0
  32. data/doc/rdoc/classes/LibXML/XML/XPath.html +111 -0
  33. data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +162 -0
  34. data/doc/rdoc/classes/cXMLDtd.html +114 -0
  35. data/doc/rdoc/classes/cXMLNode.html +114 -0
  36. data/doc/rdoc/created.rid +1 -0
  37. data/doc/rdoc/files/CHANGES.html +794 -0
  38. data/doc/rdoc/files/LICENSE.html +131 -0
  39. data/doc/rdoc/files/README.html +343 -0
  40. data/doc/rdoc/files/ext/libxml/libxml_c.html +101 -0
  41. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +101 -0
  42. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_decl_c.html +101 -0
  43. data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +101 -0
  44. data/doc/rdoc/files/ext/libxml/ruby_xml_c.html +101 -0
  45. data/doc/rdoc/files/ext/libxml/ruby_xml_cbg_c.html +101 -0
  46. data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +101 -0
  47. data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +101 -0
  48. data/doc/rdoc/files/ext/libxml/ruby_xml_encoding_c.html +101 -0
  49. data/doc/rdoc/files/ext/libxml/ruby_xml_error_c.html +101 -0
  50. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +101 -0
  51. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_context_c.html +101 -0
  52. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_options_c.html +101 -0
  53. data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +101 -0
  54. data/doc/rdoc/files/ext/libxml/ruby_xml_io_c.html +101 -0
  55. data/doc/rdoc/files/ext/libxml/ruby_xml_namespace_c.html +101 -0
  56. data/doc/rdoc/files/ext/libxml/ruby_xml_namespaces_c.html +101 -0
  57. data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +101 -0
  58. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +101 -0
  59. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +101 -0
  60. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_options_c.html +101 -0
  61. data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +101 -0
  62. data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +101 -0
  63. data/doc/rdoc/files/ext/libxml/ruby_xml_sax2_handler_c.html +101 -0
  64. data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +101 -0
  65. data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +101 -0
  66. data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +101 -0
  67. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +101 -0
  68. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +101 -0
  69. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_expression_c.html +101 -0
  70. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +101 -0
  71. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +101 -0
  72. data/doc/rdoc/files/lib/libxml/attr_decl_rb.html +101 -0
  73. data/doc/rdoc/files/lib/libxml/attr_rb.html +101 -0
  74. data/doc/rdoc/files/lib/libxml/attributes_rb.html +101 -0
  75. data/doc/rdoc/files/lib/libxml/document_rb.html +101 -0
  76. data/doc/rdoc/files/lib/libxml/error_rb.html +101 -0
  77. data/doc/rdoc/files/lib/libxml/hpricot_rb.html +192 -0
  78. data/doc/rdoc/files/lib/libxml/html_parser_rb.html +101 -0
  79. data/doc/rdoc/files/lib/libxml/namespace_rb.html +101 -0
  80. data/doc/rdoc/files/lib/libxml/namespaces_rb.html +101 -0
  81. data/doc/rdoc/files/lib/libxml/node_rb.html +108 -0
  82. data/doc/rdoc/files/lib/libxml/ns_rb.html +101 -0
  83. data/doc/rdoc/files/lib/libxml/parser_rb.html +101 -0
  84. data/doc/rdoc/files/lib/libxml/properties_rb.html +101 -0
  85. data/doc/rdoc/files/lib/libxml/reader_rb.html +101 -0
  86. data/doc/rdoc/files/lib/libxml/sax_callbacks_rb.html +101 -0
  87. data/doc/rdoc/files/lib/libxml/sax_parser_rb.html +101 -0
  88. data/doc/rdoc/files/lib/libxml/tree_rb.html +101 -0
  89. data/doc/rdoc/files/lib/libxml/xpath_object_rb.html +101 -0
  90. data/doc/rdoc/files/lib/libxml_rb.html +133 -0
  91. data/doc/rdoc/files/lib/xml/libxml_rb.html +124 -0
  92. data/doc/rdoc/files/lib/xml_rb.html +134 -0
  93. data/doc/rdoc/fr_class_index.html +46 -0
  94. data/doc/rdoc/fr_file_index.html +84 -0
  95. data/doc/rdoc/fr_method_index.html +155 -0
  96. data/doc/rdoc/index.html +24 -0
  97. data/doc/rdoc/rdoc-style.css +208 -0
  98. data/ext/libxml/Makefile +157 -0
  99. data/ext/libxml/build.log +4 -0
  100. data/ext/libxml/extconf.h +5 -0
  101. data/ext/libxml/extconf.rb +278 -0
  102. data/ext/libxml/libxml.c +77 -0
  103. data/ext/libxml/libxml.o +0 -0
  104. data/ext/libxml/libxml_ruby.bundle +0 -0
  105. data/ext/libxml/mkmf.log +228 -0
  106. data/ext/libxml/ruby_libxml.h +93 -0
  107. data/ext/libxml/ruby_xml.c +893 -0
  108. data/ext/libxml/ruby_xml.h +10 -0
  109. data/ext/libxml/ruby_xml.o +0 -0
  110. data/ext/libxml/ruby_xml_attr.c +352 -0
  111. data/ext/libxml/ruby_xml_attr.h +14 -0
  112. data/ext/libxml/ruby_xml_attr.o +0 -0
  113. data/ext/libxml/ruby_xml_attr_decl.c +171 -0
  114. data/ext/libxml/ruby_xml_attr_decl.h +13 -0
  115. data/ext/libxml/ruby_xml_attr_decl.o +0 -0
  116. data/ext/libxml/ruby_xml_attributes.c +277 -0
  117. data/ext/libxml/ruby_xml_attributes.h +17 -0
  118. data/ext/libxml/ruby_xml_attributes.o +0 -0
  119. data/ext/libxml/ruby_xml_cbg.c +86 -0
  120. data/ext/libxml/ruby_xml_cbg.o +0 -0
  121. data/ext/libxml/ruby_xml_document.c +1006 -0
  122. data/ext/libxml/ruby_xml_document.c.old +936 -0
  123. data/ext/libxml/ruby_xml_document.h +17 -0
  124. data/ext/libxml/ruby_xml_document.o +0 -0
  125. data/ext/libxml/ruby_xml_dtd.c +257 -0
  126. data/ext/libxml/ruby_xml_dtd.h +9 -0
  127. data/ext/libxml/ruby_xml_dtd.o +0 -0
  128. data/ext/libxml/ruby_xml_encoding.c +134 -0
  129. data/ext/libxml/ruby_xml_encoding.h +12 -0
  130. data/ext/libxml/ruby_xml_encoding.o +0 -0
  131. data/ext/libxml/ruby_xml_error.c +1004 -0
  132. data/ext/libxml/ruby_xml_error.h +14 -0
  133. data/ext/libxml/ruby_xml_error.o +0 -0
  134. data/ext/libxml/ruby_xml_html_parser.c +92 -0
  135. data/ext/libxml/ruby_xml_html_parser.h +12 -0
  136. data/ext/libxml/ruby_xml_html_parser.o +0 -0
  137. data/ext/libxml/ruby_xml_html_parser_context.c +308 -0
  138. data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
  139. data/ext/libxml/ruby_xml_html_parser_context.o +0 -0
  140. data/ext/libxml/ruby_xml_html_parser_options.c +40 -0
  141. data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
  142. data/ext/libxml/ruby_xml_html_parser_options.o +0 -0
  143. data/ext/libxml/ruby_xml_input_cbg.c +191 -0
  144. data/ext/libxml/ruby_xml_input_cbg.h +20 -0
  145. data/ext/libxml/ruby_xml_input_cbg.o +0 -0
  146. data/ext/libxml/ruby_xml_io.c +30 -0
  147. data/ext/libxml/ruby_xml_io.h +9 -0
  148. data/ext/libxml/ruby_xml_io.o +0 -0
  149. data/ext/libxml/ruby_xml_namespace.c +170 -0
  150. data/ext/libxml/ruby_xml_namespace.h +12 -0
  151. data/ext/libxml/ruby_xml_namespace.o +0 -0
  152. data/ext/libxml/ruby_xml_namespaces.c +295 -0
  153. data/ext/libxml/ruby_xml_namespaces.h +11 -0
  154. data/ext/libxml/ruby_xml_namespaces.o +0 -0
  155. data/ext/libxml/ruby_xml_node.c +1386 -0
  156. data/ext/libxml/ruby_xml_node.h +13 -0
  157. data/ext/libxml/ruby_xml_node.o +0 -0
  158. data/ext/libxml/ruby_xml_parser.c +94 -0
  159. data/ext/libxml/ruby_xml_parser.h +14 -0
  160. data/ext/libxml/ruby_xml_parser.o +0 -0
  161. data/ext/libxml/ruby_xml_parser_context.c +982 -0
  162. data/ext/libxml/ruby_xml_parser_context.h +12 -0
  163. data/ext/libxml/ruby_xml_parser_context.o +0 -0
  164. data/ext/libxml/ruby_xml_parser_options.c +68 -0
  165. data/ext/libxml/ruby_xml_parser_options.h +14 -0
  166. data/ext/libxml/ruby_xml_parser_options.o +0 -0
  167. data/ext/libxml/ruby_xml_reader.c +1002 -0
  168. data/ext/libxml/ruby_xml_reader.h +14 -0
  169. data/ext/libxml/ruby_xml_reader.o +0 -0
  170. data/ext/libxml/ruby_xml_relaxng.c +111 -0
  171. data/ext/libxml/ruby_xml_relaxng.h +10 -0
  172. data/ext/libxml/ruby_xml_relaxng.o +0 -0
  173. data/ext/libxml/ruby_xml_sax2_handler.c +322 -0
  174. data/ext/libxml/ruby_xml_sax2_handler.h +12 -0
  175. data/ext/libxml/ruby_xml_sax2_handler.o +0 -0
  176. data/ext/libxml/ruby_xml_sax_parser.c +137 -0
  177. data/ext/libxml/ruby_xml_sax_parser.h +12 -0
  178. data/ext/libxml/ruby_xml_sax_parser.o +0 -0
  179. data/ext/libxml/ruby_xml_schema.c +159 -0
  180. data/ext/libxml/ruby_xml_schema.h +11 -0
  181. data/ext/libxml/ruby_xml_schema.o +0 -0
  182. data/ext/libxml/ruby_xml_version.h +9 -0
  183. data/ext/libxml/ruby_xml_xinclude.c +18 -0
  184. data/ext/libxml/ruby_xml_xinclude.h +13 -0
  185. data/ext/libxml/ruby_xml_xinclude.o +0 -0
  186. data/ext/libxml/ruby_xml_xpath.c +107 -0
  187. data/ext/libxml/ruby_xml_xpath.h +12 -0
  188. data/ext/libxml/ruby_xml_xpath.o +0 -0
  189. data/ext/libxml/ruby_xml_xpath_context.c +387 -0
  190. data/ext/libxml/ruby_xml_xpath_context.h +11 -0
  191. data/ext/libxml/ruby_xml_xpath_context.o +0 -0
  192. data/ext/libxml/ruby_xml_xpath_expression.c +83 -0
  193. data/ext/libxml/ruby_xml_xpath_expression.h +12 -0
  194. data/ext/libxml/ruby_xml_xpath_expression.o +0 -0
  195. data/ext/libxml/ruby_xml_xpath_object.c +336 -0
  196. data/ext/libxml/ruby_xml_xpath_object.h +19 -0
  197. data/ext/libxml/ruby_xml_xpath_object.o +0 -0
  198. data/ext/libxml/ruby_xml_xpointer.c +101 -0
  199. data/ext/libxml/ruby_xml_xpointer.h +13 -0
  200. data/ext/libxml/ruby_xml_xpointer.o +0 -0
  201. data/ext/mingw/Rakefile +34 -0
  202. data/ext/mingw/build.rake +41 -0
  203. data/ext/vc/libxml_ruby.sln +26 -0
  204. data/lib/libxml.rb +30 -0
  205. data/lib/libxml/attr.rb +111 -0
  206. data/lib/libxml/attr_decl.rb +78 -0
  207. data/lib/libxml/attributes.rb +12 -0
  208. data/lib/libxml/document.rb +190 -0
  209. data/lib/libxml/error.rb +88 -0
  210. data/lib/libxml/hpricot.rb +76 -0
  211. data/lib/libxml/html_parser.rb +94 -0
  212. data/lib/libxml/namespace.rb +60 -0
  213. data/lib/libxml/namespaces.rb +36 -0
  214. data/lib/libxml/node.rb +385 -0
  215. data/lib/libxml/ns.rb +20 -0
  216. data/lib/libxml/parser.rb +365 -0
  217. data/lib/libxml/properties.rb +21 -0
  218. data/lib/libxml/reader.rb +27 -0
  219. data/lib/libxml/sax_callbacks.rb +178 -0
  220. data/lib/libxml/sax_parser.rb +56 -0
  221. data/lib/libxml/tree.rb +27 -0
  222. data/lib/libxml/xpath_object.rb +14 -0
  223. data/lib/xml.rb +14 -0
  224. data/lib/xml/libxml.rb +8 -0
  225. data/setup.rb +1585 -0
  226. data/test/etc_doc_to_s.rb +19 -0
  227. data/test/ets_doc_file.rb +15 -0
  228. data/test/ets_doc_to_s.rb +21 -0
  229. data/test/ets_gpx.rb +26 -0
  230. data/test/ets_node_gc.rb +21 -0
  231. data/test/ets_test.xml +2 -0
  232. data/test/ets_tsr.rb +9 -0
  233. data/test/model/atom.xml +13 -0
  234. data/test/model/bands.xml +5 -0
  235. data/test/model/books.xml +146 -0
  236. data/test/model/merge_bug_data.xml +58 -0
  237. data/test/model/ruby-lang.html +238 -0
  238. data/test/model/rubynet.xml +79 -0
  239. data/test/model/rubynet_project +1 -0
  240. data/test/model/shiporder.rnc +28 -0
  241. data/test/model/shiporder.rng +86 -0
  242. data/test/model/shiporder.xml +23 -0
  243. data/test/model/shiporder.xsd +31 -0
  244. data/test/model/soap.xml +27 -0
  245. data/test/model/xinclude.xml +5 -0
  246. data/test/tc_attr.rb +170 -0
  247. data/test/tc_attr_decl.rb +131 -0
  248. data/test/tc_attributes.rb +133 -0
  249. data/test/tc_deprecated_require.rb +11 -0
  250. data/test/tc_document.rb +113 -0
  251. data/test/tc_document_write.rb +118 -0
  252. data/test/tc_dtd.rb +123 -0
  253. data/test/tc_error.rb +136 -0
  254. data/test/tc_html_parser.rb +138 -0
  255. data/test/tc_namespace.rb +59 -0
  256. data/test/tc_namespaces.rb +174 -0
  257. data/test/tc_node.rb +181 -0
  258. data/test/tc_node_cdata.rb +49 -0
  259. data/test/tc_node_comment.rb +30 -0
  260. data/test/tc_node_copy.rb +40 -0
  261. data/test/tc_node_edit.rb +158 -0
  262. data/test/tc_node_text.rb +69 -0
  263. data/test/tc_node_write.rb +83 -0
  264. data/test/tc_node_xlink.rb +26 -0
  265. data/test/tc_parser.rb +330 -0
  266. data/test/tc_parser_context.rb +186 -0
  267. data/test/tc_properties.rb +36 -0
  268. data/test/tc_reader.rb +284 -0
  269. data/test/tc_relaxng.rb +51 -0
  270. data/test/tc_sax_parser.rb +274 -0
  271. data/test/tc_schema.rb +51 -0
  272. data/test/tc_traversal.rb +220 -0
  273. data/test/tc_xinclude.rb +19 -0
  274. data/test/tc_xml.rb +224 -0
  275. data/test/tc_xpath.rb +193 -0
  276. data/test/tc_xpath_context.rb +78 -0
  277. data/test/tc_xpath_expression.rb +35 -0
  278. data/test/tc_xpointer.rb +72 -0
  279. data/test/test_suite.rb +33 -0
  280. metadata +376 -0
@@ -0,0 +1,13 @@
1
+ /* $Id: ruby_xml_node.h 850 2009-03-21 22:21:14Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RXML_NODE__
6
+ #define __RXML_NODE__
7
+
8
+ extern VALUE cXMLNode;
9
+
10
+ void rxml_init_node(void);
11
+ void rxml_node_mark(xmlNodePtr xnode);
12
+ VALUE rxml_node_wrap(xmlNodePtr xnode);
13
+ #endif
@@ -0,0 +1,94 @@
1
+ /* $Id: ruby_xml_parser.c 758 2009-01-25 20:36:03Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include <stdarg.h>
6
+ #include "ruby_libxml.h"
7
+
8
+ /*
9
+ * Document-class: LibXML::XML::Parser
10
+ *
11
+ * The XML::Parser provides a tree based API for processing
12
+ * xml documents, in contract to XML::Reader's stream
13
+ * based api and XML::SaxParser callback based API.
14
+ *
15
+ * As a result, parsing a document creates an in-memory document object
16
+ * that consist of any number of XML::Node instances. This is simple
17
+ * and powerful model, but has the major limitation that the size of
18
+ * the document that can be processed is limited by the amount of
19
+ * memory available. In such cases, it is better to use the XML::Reader.
20
+ *
21
+ * Using the parser is simple:
22
+ *
23
+ * parser = XML::Parser.file('my_file')
24
+ * doc = parser.parse
25
+ *
26
+ * You can also parse documents (see XML::Parser.document),
27
+ * strings (see XML::Parser.string) and io objects (see
28
+ * XML::Parser.io).
29
+ */
30
+
31
+ VALUE cXMLParser;
32
+ static ID CONTEXT_ATTR;
33
+
34
+ /*
35
+ * call-seq:
36
+ * parser.initialize(context) -> XML::Parser
37
+ *
38
+ * Creates a new XML::Parser from the specified
39
+ * XML::Parser::Context.
40
+ */
41
+ static VALUE rxml_parser_initialize(int argc, VALUE *argv, VALUE self)
42
+ {
43
+ VALUE context = Qnil;
44
+
45
+ rb_scan_args(argc, argv, "01", &context);
46
+
47
+ if (context == Qnil)
48
+ {
49
+ rb_warn("Passing no parameters to XML::Parser.new is deprecated. Pass an instance of XML::Parser::Context instead.");
50
+ context = rb_class_new_instance(0, NULL, cXMLParserContext);
51
+ }
52
+
53
+ rb_ivar_set(self, CONTEXT_ATTR, context);
54
+ return self;
55
+ }
56
+
57
+ /*
58
+ * call-seq:
59
+ * parser.parse -> XML::Document
60
+ *
61
+ * Parse the input XML and create an XML::Document with
62
+ * it's content. If an error occurs, XML::Parser::ParseError
63
+ * is thrown.
64
+ */
65
+ static VALUE rxml_parser_parse(VALUE self)
66
+ {
67
+ xmlParserCtxtPtr ctxt;
68
+ VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
69
+
70
+ Data_Get_Struct(context, xmlParserCtxt, ctxt);
71
+
72
+ if ((xmlParseDocument(ctxt) == -1 || !ctxt->wellFormed) && ! ctxt->recovery)
73
+ {
74
+ if (ctxt->myDoc)
75
+ xmlFreeDoc(ctxt->myDoc);
76
+ rxml_raise(&ctxt->lastError);
77
+ }
78
+
79
+ return rxml_document_wrap(ctxt->myDoc);
80
+ }
81
+
82
+ void rxml_init_parser(void)
83
+ {
84
+ cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
85
+
86
+ /* Atributes */
87
+ CONTEXT_ATTR = rb_intern("@context");
88
+ rb_define_attr(cXMLParser, "input", 1, 0);
89
+ rb_define_attr(cXMLParser, "context", 1, 0);
90
+
91
+ /* Instance Methods */
92
+ rb_define_method(cXMLParser, "initialize", rxml_parser_initialize, -1);
93
+ rb_define_method(cXMLParser, "parse", rxml_parser_parse, 0);
94
+ }
@@ -0,0 +1,14 @@
1
+ /* $Id: ruby_xml_parser.h 758 2009-01-25 20:36:03Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RXML_PARSER__
6
+ #define __RXML_PARSER__
7
+
8
+ #define MAX_LIBXML_FEATURES_LEN 50
9
+
10
+ extern VALUE cXMLParser;
11
+
12
+ void rxml_init_parser();
13
+
14
+ #endif
@@ -0,0 +1,982 @@
1
+ /* $Id: ruby_xml_parser_context.c 851 2009-03-21 22:21:36Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_parser_context.h"
7
+
8
+ VALUE cXMLParserContext;
9
+ static ID IO_ATTR;
10
+
11
+ /*
12
+ * Document-class: LibXML::XML::Parser::Context
13
+ *
14
+ * The XML::Parser::Context class provides in-depth control over how
15
+ * a document is parsed.
16
+ */
17
+
18
+ static void rxml_parser_context_free(xmlParserCtxtPtr ctxt)
19
+ {
20
+ xmlFreeParserCtxt(ctxt);
21
+ }
22
+
23
+ static VALUE rxml_parser_context_wrap(xmlParserCtxtPtr ctxt)
24
+ {
25
+ return Data_Wrap_Struct(cXMLParserContext, NULL, rxml_parser_context_free, ctxt);
26
+ }
27
+
28
+
29
+ static VALUE rxml_parser_context_alloc(VALUE klass)
30
+ {
31
+ xmlParserCtxtPtr ctxt = xmlNewParserCtxt();
32
+ return Data_Wrap_Struct(klass, NULL, rxml_parser_context_free, ctxt);
33
+ }
34
+
35
+ /* call-seq:
36
+ * XML::Parser::Context.document(document) -> XML::Parser::Context
37
+ *
38
+ * Creates a new parser context based on the specified document.
39
+ *
40
+ * Parameters:
41
+ *
42
+ * document - An XML::Document instance.
43
+ */
44
+ static VALUE rxml_parser_context_document(VALUE klass, VALUE document)
45
+ {
46
+ xmlParserCtxtPtr ctxt;
47
+ xmlDocPtr xdoc;
48
+ xmlChar *buffer;
49
+ int length;
50
+
51
+ if (rb_obj_is_kind_of(document, cXMLDocument) == Qfalse)
52
+ rb_raise(rb_eTypeError, "Must pass an XML::Document object");
53
+
54
+ Data_Get_Struct(document, xmlDoc, xdoc);
55
+ xmlDocDumpFormatMemoryEnc(xdoc, &buffer, &length, xdoc->encoding, 0);
56
+
57
+ ctxt = xmlCreateDocParserCtxt(buffer);
58
+
59
+ if (!ctxt)
60
+ rxml_raise(&xmlLastError);
61
+
62
+ /* This is annoying, but xmlInitParserCtxt (called indirectly above) and
63
+ xmlCtxtUseOptionsInternal (called below) initialize slightly different
64
+ context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
65
+ sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */
66
+ xmlCtxtUseOptions(ctxt, rxml_libxml_default_options());
67
+
68
+ return rxml_parser_context_wrap(ctxt);
69
+ }
70
+
71
+ /* call-seq:
72
+ * XML::Parser::Context.file(file) -> XML::Parser::Context
73
+ *
74
+ * Creates a new parser context based on the specified file or uri.
75
+ *
76
+ * Parameters:
77
+ *
78
+ * file - A filename or uri.
79
+ */
80
+ static VALUE rxml_parser_context_file(VALUE klass, VALUE file)
81
+ {
82
+ xmlParserCtxtPtr ctxt = xmlCreateURLParserCtxt(StringValuePtr(file), 0);
83
+
84
+ if (!ctxt)
85
+ rxml_raise(&xmlLastError);
86
+
87
+ /* This is annoying, but xmlInitParserCtxt (called indirectly above) and
88
+ xmlCtxtUseOptionsInternal (called below) initialize slightly different
89
+ context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
90
+ sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */
91
+ xmlCtxtUseOptions(ctxt, rxml_libxml_default_options());
92
+
93
+ return rxml_parser_context_wrap(ctxt);
94
+ }
95
+
96
+ /* call-seq:
97
+ * XML::Parser::Context.string(string) -> XML::Parser::Context
98
+ *
99
+ * Creates a new parser context based on the specified string.
100
+ *
101
+ * Parameters:
102
+ *
103
+ * string - A string that contains the data to parse.
104
+ */
105
+ static VALUE rxml_parser_context_string(VALUE klass, VALUE string)
106
+ {
107
+ xmlParserCtxtPtr ctxt;
108
+ Check_Type(string, T_STRING);
109
+
110
+ if (RSTRING_LEN(string) == 0)
111
+ rb_raise(rb_eArgError, "Must specify a string with one or more characters");
112
+
113
+ ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(string),
114
+ RSTRING_LEN(string));
115
+
116
+ if (!ctxt)
117
+ rxml_raise(&xmlLastError);
118
+
119
+ /* This is annoying, but xmlInitParserCtxt (called indirectly above) and
120
+ xmlCtxtUseOptionsInternal (called below) initialize slightly different
121
+ context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
122
+ sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */
123
+ xmlCtxtUseOptions(ctxt, rxml_libxml_default_options());
124
+
125
+ return rxml_parser_context_wrap(ctxt);
126
+ }
127
+
128
+ /* call-seq:
129
+ * XML::Parser::Context.io(io) -> XML::Parser::Context
130
+ *
131
+ * Creates a new parser context based on the specified io object.
132
+ *
133
+ * Parameters:
134
+ *
135
+ * io - A ruby IO object.
136
+ */
137
+ static VALUE rxml_parser_context_io(VALUE klass, VALUE io)
138
+ {
139
+ VALUE result;
140
+ xmlParserCtxtPtr ctxt;
141
+ xmlParserInputBufferPtr input;
142
+ xmlParserInputPtr stream;
143
+
144
+ if (NIL_P(io))
145
+ rb_raise(rb_eTypeError, "Must pass in an IO object");
146
+
147
+ input = xmlParserInputBufferCreateIO((xmlInputReadCallback) rxml_read_callback, NULL,
148
+ (void*)io, XML_CHAR_ENCODING_NONE);
149
+
150
+ ctxt = xmlNewParserCtxt();
151
+
152
+ if (!ctxt)
153
+ {
154
+ xmlFreeParserInputBuffer(input);
155
+ rxml_raise(&xmlLastError);
156
+ }
157
+
158
+ /* This is annoying, but xmlInitParserCtxt (called indirectly above) and
159
+ xmlCtxtUseOptionsInternal (called below) initialize slightly different
160
+ context options, in particular XML_PARSE_NODICT which xmlInitParserCtxt
161
+ sets to 0 and xmlCtxtUseOptionsInternal sets to 1. So we have to call both. */
162
+ xmlCtxtUseOptions(ctxt, rxml_libxml_default_options());
163
+
164
+ stream = xmlNewIOInputStream(ctxt, input, XML_CHAR_ENCODING_NONE);
165
+
166
+ if (!stream)
167
+ {
168
+ xmlFreeParserInputBuffer(input);
169
+ xmlFreeParserCtxt(ctxt);
170
+ rxml_raise(&xmlLastError);
171
+ }
172
+ inputPush(ctxt, stream);
173
+ result = rxml_parser_context_wrap(ctxt);
174
+
175
+ /* Attach io object to parser so it won't get freed.*/
176
+ rb_ivar_set(result, IO_ATTR, io);
177
+
178
+ return result;
179
+ }
180
+
181
+ /*
182
+ * call-seq:
183
+ * context.base_uri -> "http:://libxml.org"
184
+ *
185
+ * Obtain the base url for this parser context.
186
+ */
187
+ static VALUE rxml_parser_context_base_uri_get(VALUE self)
188
+ {
189
+ xmlParserCtxtPtr ctxt;
190
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
191
+
192
+ if (ctxt->input && ctxt->input->filename)
193
+ return rb_str_new2(ctxt->input->filename);
194
+ else
195
+ return Qnil;
196
+ }
197
+
198
+ /*
199
+ * call-seq:
200
+ * context.base_uri = "http:://libxml.org"
201
+ *
202
+ * Sets the base url for this parser context.
203
+ */
204
+ static VALUE rxml_parser_context_base_uri_set(VALUE self, VALUE url)
205
+ {
206
+ xmlParserCtxtPtr ctxt;
207
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
208
+
209
+ Check_Type(url, T_STRING);
210
+
211
+ if (ctxt->input && !ctxt->input->filename)
212
+ {
213
+ const xmlChar * xurl = StringValuePtr(url);
214
+ ctxt->input->filename = (char *) xmlStrdup(xurl);
215
+ }
216
+ return self;
217
+ }
218
+
219
+
220
+ /*
221
+ * call-seq:
222
+ * context.data_directory -> "dir"
223
+ *
224
+ * Obtain the data directory associated with this context.
225
+ */
226
+ static VALUE rxml_parser_context_data_directory_get(VALUE self)
227
+ {
228
+ xmlParserCtxtPtr ctxt;
229
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
230
+
231
+ if (ctxt->directory == NULL)
232
+ return (Qnil);
233
+ else
234
+ return (rb_str_new2(ctxt->directory));
235
+ }
236
+
237
+ /*
238
+ * call-seq:
239
+ * context.depth -> num
240
+ *
241
+ * Obtain the depth of this context.
242
+ */
243
+ static VALUE rxml_parser_context_depth_get(VALUE self)
244
+ {
245
+ xmlParserCtxtPtr ctxt;
246
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
247
+
248
+ return (INT2NUM(ctxt->depth));
249
+ }
250
+
251
+ /*
252
+ * call-seq:
253
+ * context.disable_cdata? -> (true|false)
254
+ *
255
+ * Determine whether CDATA nodes will be created in this context.
256
+ */
257
+ static VALUE rxml_parser_context_disable_cdata_q(VALUE self)
258
+ {
259
+ xmlParserCtxtPtr ctxt;
260
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
261
+
262
+ /* LibXML controls this internally with the default SAX handler. */
263
+ if (ctxt->sax && ctxt->sax->cdataBlock)
264
+ return (Qfalse);
265
+ else
266
+ return (Qtrue);
267
+ }
268
+
269
+ /*
270
+ * call-seq:
271
+ * context.disable_cdata = (true|false)
272
+ *
273
+ * Control whether CDATA nodes will be created in this context.
274
+ */
275
+ static VALUE rxml_parser_context_disable_cdata_set(VALUE self, VALUE bool)
276
+ {
277
+ xmlParserCtxtPtr ctxt;
278
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
279
+
280
+ if (ctxt->sax == NULL)
281
+ rb_raise(rb_eRuntimeError, "Sax handler is not yet set");
282
+
283
+ /* LibXML controls this internally with the default SAX handler. */
284
+ if (bool)
285
+ ctxt->sax->cdataBlock = NULL;
286
+ else
287
+ ctxt->sax->cdataBlock = xmlDefaultSAXHandler.cdataBlock;
288
+
289
+ return bool;
290
+ }
291
+
292
+ /*
293
+ * call-seq:
294
+ * context.disable_sax? -> (true|false)
295
+ *
296
+ * Determine whether SAX-based processing is disabled
297
+ * in this context.
298
+ */
299
+ static VALUE rxml_parser_context_disable_sax_q(VALUE self)
300
+ {
301
+ xmlParserCtxtPtr ctxt;
302
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
303
+
304
+ if (ctxt->disableSAX)
305
+ return (Qtrue);
306
+ else
307
+ return (Qfalse);
308
+ }
309
+
310
+ /*
311
+ * call-seq:
312
+ * context.docbook? -> (true|false)
313
+ *
314
+ * Determine whether this is a docbook context.
315
+ */
316
+ static VALUE rxml_parser_context_docbook_q(VALUE self)
317
+ {
318
+ xmlParserCtxtPtr ctxt;
319
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
320
+
321
+ if (ctxt->html == 2) // TODO check this
322
+ return (Qtrue);
323
+ else
324
+ return (Qfalse);
325
+ }
326
+
327
+ /*
328
+ * call-seq:
329
+ * context.encoding -> XML::Encoding::UTF_8
330
+ *
331
+ * Obtain the character encoding identifier used in
332
+ * this context.
333
+ */
334
+ static VALUE rxml_parser_context_encoding_get(VALUE self)
335
+ {
336
+ xmlParserCtxtPtr ctxt;
337
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
338
+ return INT2NUM(xmlParseCharEncoding(ctxt->encoding));
339
+ }
340
+
341
+ /*
342
+ * call-seq:
343
+ * context.encoding = XML::Encoding::UTF_8
344
+ *
345
+ * Sets the character encoding for this context.
346
+ */
347
+ static VALUE rxml_parser_context_encoding_set(VALUE self, VALUE encoding)
348
+ {
349
+ xmlParserCtxtPtr ctxt;
350
+ int result;
351
+ const char* xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(encoding));
352
+ xmlCharEncodingHandlerPtr hdlr = xmlFindCharEncodingHandler(xencoding);
353
+
354
+ if (!hdlr)
355
+ rb_raise(rb_eRuntimeError, "Unknown encoding: %s", encoding);
356
+
357
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
358
+ result = xmlSwitchToEncoding(ctxt, hdlr);
359
+
360
+ if (result != 0)
361
+ rxml_raise(&xmlLastError);
362
+
363
+ if (ctxt->encoding != NULL)
364
+ xmlFree((xmlChar *) ctxt->encoding);
365
+
366
+ ctxt->encoding = xmlStrdup((const xmlChar *) xencoding);
367
+ return self;
368
+ }
369
+
370
+ /*
371
+ * call-seq:
372
+ * context.errno -> num
373
+ *
374
+ * Obtain the last-error number in this context.
375
+ */
376
+ static VALUE rxml_parser_context_errno_get(VALUE self)
377
+ {
378
+ xmlParserCtxtPtr ctxt;
379
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
380
+
381
+ return (INT2NUM(ctxt->errNo));
382
+ }
383
+
384
+ /*
385
+ * call-seq:
386
+ * context.html? -> (true|false)
387
+ *
388
+ * Determine whether this is an html context.
389
+ */
390
+ static VALUE rxml_parser_context_html_q(VALUE self)
391
+ {
392
+ xmlParserCtxtPtr ctxt;
393
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
394
+
395
+ if (ctxt->html == 1)
396
+ return (Qtrue);
397
+ else
398
+ return (Qfalse);
399
+ }
400
+
401
+ /*
402
+ * call-seq:
403
+ * context.max_num_streams -> num
404
+ *
405
+ * Obtain the limit on the number of IO streams opened in
406
+ * this context.
407
+ */
408
+ static VALUE rxml_parser_context_io_max_num_streams_get(VALUE self)
409
+ {
410
+ // TODO alias to max_streams and dep this?
411
+ xmlParserCtxtPtr ctxt;
412
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
413
+
414
+ return (INT2NUM(ctxt->inputMax));
415
+ }
416
+
417
+ /*
418
+ * call-seq:
419
+ * context.num_streams -> "dir"
420
+ *
421
+ * Obtain the actual number of IO streams in this
422
+ * context.
423
+ */
424
+ static VALUE rxml_parser_context_io_num_streams_get(VALUE self)
425
+ {
426
+ xmlParserCtxtPtr ctxt;
427
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
428
+
429
+ return (INT2NUM(ctxt->inputNr));
430
+ }
431
+
432
+ /*
433
+ * call-seq:
434
+ * context.keep_blanks? -> (true|false)
435
+ *
436
+ * Determine whether parsers in this context retain
437
+ * whitespace.
438
+ */
439
+ static VALUE rxml_parser_context_keep_blanks_q(VALUE self)
440
+ {
441
+ xmlParserCtxtPtr ctxt;
442
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
443
+
444
+ if (ctxt->keepBlanks)
445
+ return (Qtrue);
446
+ else
447
+ return (Qfalse);
448
+ }
449
+
450
+ /*
451
+ * call-seq:
452
+ * context.name_depth -> num
453
+ *
454
+ * Obtain the name depth for this context.
455
+ */
456
+ static VALUE rxml_parser_context_name_depth_get(VALUE self)
457
+ {
458
+ xmlParserCtxtPtr ctxt;
459
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
460
+
461
+ return (INT2NUM(ctxt->nameNr));
462
+ }
463
+
464
+ /*
465
+ * call-seq:
466
+ * context.name_depth_max -> num
467
+ *
468
+ * Obtain the maximum name depth for this context.
469
+ */
470
+ static VALUE rxml_parser_context_name_depth_max_get(VALUE self)
471
+ {
472
+ xmlParserCtxtPtr ctxt;
473
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
474
+
475
+ return (INT2NUM(ctxt->nameMax));
476
+ }
477
+
478
+ /*
479
+ * call-seq:
480
+ * context.name_node -> "name"
481
+ *
482
+ * Obtain the name node for this context.
483
+ */
484
+ static VALUE rxml_parser_context_name_node_get(VALUE self)
485
+ {
486
+ xmlParserCtxtPtr ctxt;
487
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
488
+
489
+ if (ctxt->name == NULL)
490
+ return (Qnil);
491
+ else
492
+ return (rb_str_new2((const char*) ctxt->name));
493
+ }
494
+
495
+ /*
496
+ * call-seq:
497
+ * context.name_tab -> ["name", ..., "name"]
498
+ *
499
+ * Obtain the name table for this context.
500
+ */
501
+ static VALUE rxml_parser_context_name_tab_get(VALUE self)
502
+ {
503
+ int i;
504
+ xmlParserCtxtPtr ctxt;
505
+ VALUE tab_ary;
506
+
507
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
508
+
509
+ if (ctxt->nameTab == NULL)
510
+ return (Qnil);
511
+
512
+ tab_ary = rb_ary_new();
513
+
514
+ for (i = (ctxt->nameNr - 1); i >= 0; i--)
515
+ {
516
+ if (ctxt->nameTab[i] == NULL)
517
+ continue;
518
+ else
519
+ rb_ary_push(tab_ary, rb_str_new2((const char*) ctxt->nameTab[i]));
520
+ }
521
+
522
+ return (tab_ary);
523
+ }
524
+
525
+ /*
526
+ * call-seq:
527
+ * context.node_depth -> num
528
+ *
529
+ * Obtain the node depth for this context.
530
+ */
531
+ static VALUE rxml_parser_context_node_depth_get(VALUE self)
532
+ {
533
+ xmlParserCtxtPtr ctxt;
534
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
535
+
536
+ return (INT2NUM(ctxt->nodeNr));
537
+ }
538
+
539
+ /*
540
+ * call-seq:
541
+ * context.node -> node
542
+ *
543
+ * Obtain the root node of this context.
544
+ */
545
+ static VALUE rxml_parser_context_node_get(VALUE self)
546
+ {
547
+ xmlParserCtxtPtr ctxt;
548
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
549
+
550
+ if (ctxt->node == NULL)
551
+ return (Qnil);
552
+ else
553
+ return (rxml_node_wrap(ctxt->node));
554
+ }
555
+
556
+ /*
557
+ * call-seq:
558
+ * context.node_depth_max -> num
559
+ *
560
+ * Obtain the maximum node depth for this context.
561
+ */
562
+ static VALUE rxml_parser_context_node_depth_max_get(VALUE self)
563
+ {
564
+ xmlParserCtxtPtr ctxt;
565
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
566
+
567
+ return (INT2NUM(ctxt->nodeMax));
568
+ }
569
+
570
+ /*
571
+ * call-seq:
572
+ * context.num_chars -> num
573
+ *
574
+ * Obtain the number of characters in this context.
575
+ */
576
+ static VALUE rxml_parser_context_num_chars_get(VALUE self)
577
+ {
578
+ xmlParserCtxtPtr ctxt;
579
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
580
+
581
+ return (LONG2NUM(ctxt->nbChars));
582
+ }
583
+
584
+
585
+ /*
586
+ * call-seq:
587
+ * context.options > XML::Parser::Options::NOENT
588
+ *
589
+ * Returns the parser options for this context. Multiple
590
+ * options can be combined by using Bitwise OR (|).
591
+ */
592
+ static VALUE rxml_parser_context_options_get(VALUE self)
593
+ {
594
+ xmlParserCtxtPtr ctxt;
595
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
596
+
597
+ return INT2NUM(ctxt->options);
598
+ }
599
+
600
+ /*
601
+ * call-seq:
602
+ * context.options = XML::Parser::Options::NOENT |
603
+ XML::Parser::Options::NOCDATA
604
+ *
605
+ * Provides control over the execution of a parser. Valid values
606
+ * are the constants defined on XML::Parser::Options. Multiple
607
+ * options can be combined by using Bitwise OR (|).
608
+ */
609
+ static VALUE rxml_parser_context_options_set(VALUE self, VALUE options)
610
+ {
611
+ int result;
612
+ xmlParserCtxtPtr ctxt;
613
+ Check_Type(options, T_FIXNUM);
614
+
615
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
616
+ result = xmlCtxtUseOptions(ctxt, NUM2INT(options));
617
+
618
+ return self;
619
+ }
620
+
621
+ /*
622
+ * call-seq:
623
+ * context.recovery? -> (true|false)
624
+ *
625
+ * Determine whether recovery mode is enabled in this
626
+ * context.
627
+ */
628
+ static VALUE rxml_parser_context_recovery_q(VALUE self)
629
+ {
630
+ xmlParserCtxtPtr ctxt;
631
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
632
+
633
+ if (ctxt->recovery)
634
+ return (Qtrue);
635
+ else
636
+ return (Qfalse);
637
+ }
638
+
639
+ /*
640
+ * call-seq:
641
+ * context.recovery = true|false
642
+ *
643
+ * Control whether recovery mode is enabled in this
644
+ * context.
645
+ */
646
+ static VALUE rxml_parser_context_recovery_set(VALUE self, VALUE bool)
647
+ {
648
+ xmlParserCtxtPtr ctxt;
649
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
650
+
651
+ if (TYPE(bool) == T_FALSE)
652
+ {
653
+ ctxt->recovery = 0;
654
+ return (Qfalse);
655
+ }
656
+ else
657
+ {
658
+ ctxt->recovery = 1;
659
+ return (Qtrue);
660
+ }
661
+ }
662
+
663
+ /*
664
+ * call-seq:
665
+ * context.replace_entities? -> (true|false)
666
+ *
667
+ * Determine whether external entity replacement is enabled in this
668
+ * context.
669
+ */
670
+ static VALUE rxml_parser_context_replace_entities_q(VALUE self)
671
+ {
672
+ xmlParserCtxtPtr ctxt;
673
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
674
+
675
+ if (ctxt->replaceEntities)
676
+ return (Qtrue);
677
+ else
678
+ return (Qfalse);
679
+ }
680
+
681
+ /*
682
+ * call-seq:
683
+ * context.replace_entities = true|false
684
+ *
685
+ * Control whether external entity replacement is enabled in this
686
+ * context.
687
+ */
688
+ static VALUE rxml_parser_context_replace_entities_set(VALUE self, VALUE bool)
689
+ {
690
+ xmlParserCtxtPtr ctxt;
691
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
692
+
693
+ if (TYPE(bool) == T_FALSE)
694
+ {
695
+ ctxt->replaceEntities = 0;
696
+ return (Qfalse);
697
+ }
698
+ else
699
+ {
700
+ ctxt->replaceEntities = 1;
701
+ return (Qtrue);
702
+ }
703
+ }
704
+
705
+ /*
706
+ * call-seq:
707
+ * context.space_depth -> num
708
+ *
709
+ * Obtain the space depth for this context.
710
+ */
711
+ static VALUE rxml_parser_context_space_depth_get(VALUE self)
712
+ {
713
+ xmlParserCtxtPtr ctxt;
714
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
715
+
716
+ return (INT2NUM(ctxt->spaceNr));
717
+ }
718
+
719
+ /*
720
+ * call-seq:
721
+ * context.space_depth -> num
722
+ *
723
+ * Obtain the maximum space depth for this context.
724
+ */
725
+ static VALUE rxml_parser_context_space_depth_max_get(VALUE self)
726
+ {
727
+ xmlParserCtxtPtr ctxt;
728
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
729
+
730
+ return (INT2NUM(ctxt->spaceMax));
731
+ }
732
+
733
+ /*
734
+ * call-seq:
735
+ * context.subset_external? -> (true|false)
736
+ *
737
+ * Determine whether this context is a subset of an
738
+ * external context.
739
+ */
740
+ static VALUE rxml_parser_context_subset_external_q(VALUE self)
741
+ {
742
+ xmlParserCtxtPtr ctxt;
743
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
744
+
745
+ if (ctxt->inSubset == 2)
746
+ return (Qtrue);
747
+ else
748
+ return (Qfalse);
749
+ }
750
+
751
+ /*
752
+ * call-seq:
753
+ * context.subset_internal? -> (true|false)
754
+ *
755
+ * Determine whether this context is a subset of an
756
+ * internal context.
757
+ */
758
+ static VALUE rxml_parser_context_subset_internal_q(VALUE self)
759
+ {
760
+ xmlParserCtxtPtr ctxt;
761
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
762
+
763
+ if (ctxt->inSubset == 1)
764
+ return (Qtrue);
765
+ else
766
+ return (Qfalse);
767
+ }
768
+
769
+ /*
770
+ * call-seq:
771
+ * context.subset_internal_name -> "name"
772
+ *
773
+ * Obtain this context's subset name (valid only if
774
+ * either of subset_external? or subset_internal?
775
+ * is true).
776
+ */
777
+ static VALUE rxml_parser_context_subset_name_get(VALUE self)
778
+ {
779
+ xmlParserCtxtPtr ctxt;
780
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
781
+
782
+ if (ctxt->intSubName == NULL)
783
+ return (Qnil);
784
+ else
785
+ return (rb_str_new2((const char*) ctxt->intSubName));
786
+ }
787
+
788
+ /*
789
+ * call-seq:
790
+ * context.subset_external_uri -> "uri"
791
+ *
792
+ * Obtain this context's external subset URI. (valid only if
793
+ * either of subset_external? or subset_internal?
794
+ * is true).
795
+ */
796
+ static VALUE rxml_parser_context_subset_external_uri_get(VALUE self)
797
+ {
798
+ xmlParserCtxtPtr ctxt;
799
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
800
+
801
+ if (ctxt->extSubURI == NULL)
802
+ return (Qnil);
803
+ else
804
+ return (rb_str_new2((const char*) ctxt->extSubURI));
805
+ }
806
+
807
+ /*
808
+ * call-seq:
809
+ * context.subset_external_system_id -> "system_id"
810
+ *
811
+ * Obtain this context's external subset system identifier.
812
+ * (valid only if either of subset_external? or subset_internal?
813
+ * is true).
814
+ */
815
+ static VALUE rxml_parser_context_subset_external_system_id_get(VALUE self)
816
+ {
817
+ xmlParserCtxtPtr ctxt;
818
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
819
+
820
+ if (ctxt->extSubSystem == NULL)
821
+ return (Qnil);
822
+ else
823
+ return (rb_str_new2((const char*) ctxt->extSubSystem));
824
+ }
825
+
826
+ /*
827
+ * call-seq:
828
+ * context.standalone? -> (true|false)
829
+ *
830
+ * Determine whether this is a standalone context.
831
+ */
832
+ static VALUE rxml_parser_context_standalone_q(VALUE self)
833
+ {
834
+ xmlParserCtxtPtr ctxt;
835
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
836
+
837
+ if (ctxt->standalone)
838
+ return (Qtrue);
839
+ else
840
+ return (Qfalse);
841
+ }
842
+
843
+ /*
844
+ * call-seq:
845
+ * context.stats? -> (true|false)
846
+ *
847
+ * Determine whether this context maintains statistics.
848
+ */
849
+ static VALUE rxml_parser_context_stats_q(VALUE self)
850
+ {
851
+ xmlParserCtxtPtr ctxt;
852
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
853
+
854
+ if (ctxt->record_info)
855
+ return (Qtrue);
856
+ else
857
+ return (Qfalse);
858
+ }
859
+
860
+ /*
861
+ * call-seq:
862
+ * context.valid? -> (true|false)
863
+ *
864
+ * Determine whether this context is valid.
865
+ */
866
+ static VALUE rxml_parser_context_valid_q(VALUE self)
867
+ {
868
+ xmlParserCtxtPtr ctxt;
869
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
870
+
871
+ if (ctxt->valid)
872
+ return (Qtrue);
873
+ else
874
+ return (Qfalse);
875
+ }
876
+
877
+ /*
878
+ * call-seq:
879
+ * context.validate? -> (true|false)
880
+ *
881
+ * Determine whether validation is enabled in this context.
882
+ */
883
+ static VALUE rxml_parser_context_validate_q(VALUE self)
884
+ {
885
+ xmlParserCtxtPtr ctxt;
886
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
887
+
888
+ if (ctxt->validate)
889
+ return (Qtrue);
890
+ else
891
+ return (Qfalse);
892
+ }
893
+
894
+ /*
895
+ * call-seq:
896
+ * context.version -> "version"
897
+ *
898
+ * Obtain this context's version identifier.
899
+ */
900
+ static VALUE rxml_parser_context_version_get(VALUE self)
901
+ {
902
+ xmlParserCtxtPtr ctxt;
903
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
904
+
905
+ if (ctxt->version == NULL)
906
+ return (Qnil);
907
+ else
908
+ return (rb_str_new2((const char*) ctxt->version));
909
+ }
910
+
911
+ /*
912
+ * call-seq:
913
+ * context.well_formed? -> (true|false)
914
+ *
915
+ * Determine whether this context contains well-formed XML.
916
+ */
917
+ static VALUE rxml_parser_context_well_formed_q(VALUE self)
918
+ {
919
+ xmlParserCtxtPtr ctxt;
920
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
921
+
922
+ if (ctxt->wellFormed)
923
+ return (Qtrue);
924
+ else
925
+ return (Qfalse);
926
+ }
927
+
928
+ void rxml_init_parser_context(void)
929
+ {
930
+ IO_ATTR = ID2SYM(rb_intern("@io"));
931
+
932
+ cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
933
+ rb_define_alloc_func(cXMLParserContext, rxml_parser_context_alloc);
934
+
935
+ rb_define_singleton_method(cXMLParserContext, "document", rxml_parser_context_document, 1);
936
+ rb_define_singleton_method(cXMLParserContext, "file", rxml_parser_context_file, 1);
937
+ rb_define_singleton_method(cXMLParserContext, "io", rxml_parser_context_io, 1);
938
+ rb_define_singleton_method(cXMLParserContext, "string", rxml_parser_context_string, 1);
939
+
940
+ rb_define_method(cXMLParserContext, "base_uri", rxml_parser_context_base_uri_get, 0);
941
+ rb_define_method(cXMLParserContext, "base_uri=", rxml_parser_context_base_uri_set, 1);
942
+ rb_define_method(cXMLParserContext, "data_directory", rxml_parser_context_data_directory_get, 0);
943
+ rb_define_method(cXMLParserContext, "depth", rxml_parser_context_depth_get, 0);
944
+ rb_define_method(cXMLParserContext, "disable_cdata?", rxml_parser_context_disable_cdata_q, 0);
945
+ rb_define_method(cXMLParserContext, "disable_cdata=", rxml_parser_context_disable_cdata_set, 1);
946
+ rb_define_method(cXMLParserContext, "disable_sax?", rxml_parser_context_disable_sax_q, 0);
947
+ rb_define_method(cXMLParserContext, "docbook?", rxml_parser_context_docbook_q, 0);
948
+ rb_define_method(cXMLParserContext, "encoding", rxml_parser_context_encoding_get, 0);
949
+ rb_define_method(cXMLParserContext, "encoding=", rxml_parser_context_encoding_set, 1);
950
+ rb_define_method(cXMLParserContext, "errno", rxml_parser_context_errno_get, 0);
951
+ rb_define_method(cXMLParserContext, "html?", rxml_parser_context_html_q, 0);
952
+ rb_define_method(cXMLParserContext, "io_max_num_streams", rxml_parser_context_io_max_num_streams_get, 0);
953
+ rb_define_method(cXMLParserContext, "io_num_streams", rxml_parser_context_io_num_streams_get, 0);
954
+ rb_define_method(cXMLParserContext, "keep_blanks?", rxml_parser_context_keep_blanks_q, 0);
955
+ rb_define_method(cXMLParserContext, "name_node", rxml_parser_context_name_node_get, 0);
956
+ rb_define_method(cXMLParserContext, "name_depth", rxml_parser_context_name_depth_get, 0);
957
+ rb_define_method(cXMLParserContext, "name_depth_max", rxml_parser_context_name_depth_max_get, 0);
958
+ rb_define_method(cXMLParserContext, "name_tab", rxml_parser_context_name_tab_get, 0);
959
+ rb_define_method(cXMLParserContext, "node", rxml_parser_context_node_get, 0);
960
+ rb_define_method(cXMLParserContext, "node_depth", rxml_parser_context_node_depth_get, 0);
961
+ rb_define_method(cXMLParserContext, "node_depth_max", rxml_parser_context_node_depth_max_get, 0);
962
+ rb_define_method(cXMLParserContext, "num_chars", rxml_parser_context_num_chars_get, 0);
963
+ rb_define_method(cXMLParserContext, "options", rxml_parser_context_options_get, 0);
964
+ rb_define_method(cXMLParserContext, "options=", rxml_parser_context_options_set, 1);
965
+ rb_define_method(cXMLParserContext, "recovery?", rxml_parser_context_recovery_q, 0);
966
+ rb_define_method(cXMLParserContext, "recovery=", rxml_parser_context_recovery_set, 1);
967
+ rb_define_method(cXMLParserContext, "replace_entities?", rxml_parser_context_replace_entities_q, 0);
968
+ rb_define_method(cXMLParserContext, "replace_entities=", rxml_parser_context_replace_entities_set, 1);
969
+ rb_define_method(cXMLParserContext, "space_depth", rxml_parser_context_space_depth_get, 0);
970
+ rb_define_method(cXMLParserContext, "space_depth_max", rxml_parser_context_space_depth_max_get, 0);
971
+ rb_define_method(cXMLParserContext, "subset_external?", rxml_parser_context_subset_external_q, 0);
972
+ rb_define_method(cXMLParserContext, "subset_external_system_id", rxml_parser_context_subset_external_system_id_get, 0);
973
+ rb_define_method(cXMLParserContext, "subset_external_uri", rxml_parser_context_subset_external_uri_get, 0);
974
+ rb_define_method(cXMLParserContext, "subset_internal?", rxml_parser_context_subset_internal_q, 0);
975
+ rb_define_method(cXMLParserContext, "subset_internal_name", rxml_parser_context_subset_name_get, 0);
976
+ rb_define_method(cXMLParserContext, "stats?", rxml_parser_context_stats_q, 0);
977
+ rb_define_method(cXMLParserContext, "standalone?", rxml_parser_context_standalone_q, 0);
978
+ rb_define_method(cXMLParserContext, "valid", rxml_parser_context_valid_q, 0);
979
+ rb_define_method(cXMLParserContext, "validate?", rxml_parser_context_validate_q, 0);
980
+ rb_define_method(cXMLParserContext, "version", rxml_parser_context_version_get, 0);
981
+ rb_define_method(cXMLParserContext, "well_formed?", rxml_parser_context_well_formed_q, 0);
982
+ }