libxml-ruby 0.8.1-x86-mswin32-60 → 0.8.2-x86-mswin32-60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +21 -0
- data/RAKEFILE +213 -0
- data/README +32 -11
- data/doc/rdoc/classes/LibXML.html +4 -0
- data/doc/rdoc/classes/LibXML/XML.html +7 -0
- data/doc/rdoc/classes/LibXML/XML/Attr.html +187 -177
- data/doc/rdoc/classes/LibXML/XML/Attributes.html +62 -61
- data/doc/rdoc/classes/LibXML/XML/Document.html +318 -254
- data/doc/rdoc/classes/LibXML/XML/Dtd.html +62 -8
- data/doc/rdoc/classes/LibXML/XML/Error.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +59 -41
- data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +12 -6
- data/doc/rdoc/classes/LibXML/XML/NS.html +65 -50
- data/doc/rdoc/classes/LibXML/XML/Node.html +671 -630
- data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +12 -0
- data/doc/rdoc/classes/LibXML/XML/Node/Set.html +64 -60
- data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +12 -0
- data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +12 -0
- data/doc/rdoc/classes/LibXML/XML/Parser.html +407 -383
- data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +241 -219
- data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +12 -0
- data/doc/rdoc/classes/LibXML/XML/Reader.html +421 -331
- data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +237 -0
- data/doc/rdoc/classes/LibXML/XML/SaxParser.html +79 -60
- data/doc/rdoc/classes/LibXML/XML/Schema.html +109 -22
- data/doc/rdoc/classes/LibXML/XML/State.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/XInclude.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/XPath.html +4 -48
- data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +6 -5
- data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +61 -0
- data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +12 -8
- data/doc/rdoc/classes/LibXML/XML/XPointer.html +14 -8
- data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +13 -0
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGES.html +38 -10
- data/doc/rdoc/files/LICENSE.html +1 -1
- data/doc/rdoc/files/README.html +57 -23
- data/doc/rdoc/files/VERSION.html +1 -1
- data/doc/rdoc/files/ext/libxml/cbg_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/libxml_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +1 -1
- data/doc/rdoc/{classes/XML.html → files/ext/libxml/ruby_xml_relaxng_c.html} +16 -35
- data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +1 -1
- data/doc/rdoc/files/lib/libxml/attr_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/attributes_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/document_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/node_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/node_set_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/parser_options_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/parser_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/properties_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/tree_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml_rb.html +2 -2
- data/doc/rdoc/files/lib/xml/libxml_rb.html +12 -2
- data/doc/rdoc/files/lib/xml_rb.html +134 -0
- data/doc/rdoc/fr_class_index.html +1 -1
- data/doc/rdoc/fr_file_index.html +2 -0
- data/doc/rdoc/fr_method_index.html +349 -344
- data/ext/libxml/libxml.c +2 -1
- data/ext/libxml/ruby_libxml.h +1 -0
- data/ext/libxml/ruby_xml_attr.c +8 -2
- data/ext/libxml/ruby_xml_attributes.c +5 -5
- data/ext/libxml/ruby_xml_document.c +41 -2
- data/ext/libxml/ruby_xml_dtd.c +169 -169
- data/ext/libxml/ruby_xml_html_parser.c +449 -449
- data/ext/libxml/ruby_xml_input_cbg.c +165 -165
- data/ext/libxml/ruby_xml_node.c +1 -1
- data/ext/libxml/ruby_xml_node_set.c +172 -172
- data/ext/libxml/ruby_xml_ns.c +145 -145
- data/ext/libxml/ruby_xml_parser.c +1398 -1398
- data/ext/libxml/ruby_xml_parser_context.c +697 -697
- data/ext/libxml/ruby_xml_reader.c +44 -0
- data/ext/libxml/ruby_xml_reader.h +14 -14
- data/ext/libxml/ruby_xml_relaxng.c +97 -0
- data/ext/libxml/ruby_xml_relaxng.h +15 -0
- data/ext/libxml/ruby_xml_sax_parser.c +486 -486
- data/ext/libxml/ruby_xml_schema.c +1 -1
- data/ext/libxml/ruby_xml_state.c +4 -4
- data/ext/libxml/ruby_xml_xinclude.c +21 -21
- data/ext/libxml/ruby_xml_xpath.c +89 -89
- data/ext/libxml/ruby_xml_xpath_context.c +283 -283
- data/ext/libxml/ruby_xml_xpath_object.c +5 -5
- data/ext/libxml/ruby_xml_xpointer.c +104 -104
- data/ext/libxml/ruby_xml_xpointer_context.c +22 -22
- data/ext/libxml/version.h +2 -2
- data/ext/libxml/version.h.rej +17 -0
- data/ext/mingw/Rakefile +41 -0
- data/{mingw → lib}/libiconv-2.dll +0 -0
- data/lib/libxml.rb +15 -4
- data/lib/libxml2-2.dll +0 -0
- data/lib/libxml_ruby.dll.a +0 -0
- data/lib/libxml_ruby.so +0 -0
- data/lib/xml.rb +14 -0
- data/lib/xml/libxml.rb +4 -1
- data/test/etc_doc_to_s.rb +1 -1
- data/test/ets_copy_bug.rb +1 -1
- data/test/ets_copy_bug3.rb +1 -1
- data/test/ets_doc_file.rb +1 -1
- data/test/ets_doc_to_s.rb +1 -1
- data/test/ets_node_gc.rb +1 -1
- data/test/ets_tsr.rb +1 -1
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/{tc_xml_attributes.rb → tc_attributes.rb} +1 -10
- data/test/{tc_xml_document.rb → tc_document.rb} +1 -1
- data/test/{tc_xml_document_write.rb → tc_document_write.rb} +1 -1
- data/test/{tc_xml_dtd.rb → tc_dtd.rb} +1 -1
- data/test/{tc_xml_html_parser.rb → tc_html_parser.rb} +1 -1
- data/test/{tc_xml_node.rb → tc_node.rb} +1 -1
- data/test/{tc_xml_node_attr.rb → tc_node_attr.rb} +1 -1
- data/test/{tc_xml_node_cdata.rb → tc_node_cdata.rb} +24 -5
- data/test/{tc_xml_node_comment.rb → tc_node_comment.rb} +1 -1
- data/test/{tc_xml_node_copy.rb → tc_node_copy.rb} +1 -1
- data/test/{tc_xml_node_edit.rb → tc_node_edit.rb} +1 -1
- data/test/{tc_xml_node_set.rb → tc_node_set.rb} +1 -1
- data/test/{tc_xml_node_set2.rb → tc_node_set2.rb} +1 -1
- data/test/{tc_xml_node_text.rb → tc_node_text.rb} +1 -1
- data/test/{tc_xml_node_xlink.rb → tc_node_xlink.rb} +2 -2
- data/test/{tc_xml_parser.rb → tc_parser.rb} +1 -1
- data/test/{tc_xml_parser_context.rb → tc_parser_context.rb} +1 -1
- data/test/{tc_xml_properties.rb → tc_properties.rb} +1 -7
- data/test/{tc_xml_reader.rb → tc_reader.rb} +1 -1
- data/test/tc_relaxng.rb +39 -0
- data/test/{tc_xml_sax_parser.rb → tc_sax_parser.rb} +1 -1
- data/test/{tc_xml_schema.rb → tc_schema.rb} +1 -1
- data/test/{tc_xml_traversal.rb → tc_traversal.rb} +1 -1
- data/test/{tc_xml_xinclude.rb → tc_xinclude.rb} +1 -1
- data/test/{tc_xml_xpath.rb → tc_xpath.rb} +1 -1
- data/test/{tc_xml_xpath_context.rb → tc_xpath_context.rb} +1 -1
- data/test/{tc_xml_xpointer.rb → tc_xpointer.rb} +1 -1
- data/test/test_suite.rb +26 -25
- metadata +103 -100
- data/benchmark/depixelate.rb +0 -632
- data/benchmark/hamlet.xml +0 -9055
- data/benchmark/sock_entries.xml +0 -507
- data/benchmark/throughput.rb +0 -39
- data/benchmark/xml_benchmarks.rb +0 -227
- data/mingw/libxml2-2.dll +0 -0
- data/mingw/libxml_ruby.so +0 -0
- data/test/gc.log +0 -0
- data/vc/libxml_ruby.sln +0 -20
- data/vc/libxml_ruby.vcproj +0 -389
data/ext/libxml/ruby_xml_ns.c
CHANGED
@@ -1,145 +1,145 @@
|
|
1
|
-
/* $Id: ruby_xml_ns.c 461 2008-07-15 21:35:56Z cfis $ */
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
#include "ruby_libxml.h"
|
6
|
-
#include "ruby_xml_ns.h"
|
7
|
-
|
8
|
-
VALUE cXMLNS;
|
9
|
-
|
10
|
-
|
11
|
-
VALUE
|
12
|
-
ruby_xml_ns_alloc(VALUE klass) {
|
13
|
-
return Data_Wrap_Struct(cXMLNS, NULL, NULL, NULL);
|
14
|
-
}
|
15
|
-
|
16
|
-
/*
|
17
|
-
* call-seq:
|
18
|
-
* initialize(node, "href", "prefix")
|
19
|
-
*
|
20
|
-
* Create a new namespace attached to the specified node with the
|
21
|
-
* give prefix and namespace.
|
22
|
-
*
|
23
|
-
* XML::NS.new(node, "xlink", "http://www.w3.org/1999/xlink")
|
24
|
-
*/
|
25
|
-
VALUE
|
26
|
-
ruby_xml_ns_initialize(VALUE self, VALUE node, VALUE href, VALUE prefix) {
|
27
|
-
xmlNodePtr xnode;
|
28
|
-
xmlNsPtr xns;
|
29
|
-
|
30
|
-
Data_Get_Struct(node, xmlNode, xnode);
|
31
|
-
xns = xmlNewNs(xnode, (xmlChar*)StringValuePtr(href), (xmlChar*)StringValuePtr(prefix));
|
32
|
-
|
33
|
-
DATA_PTR(self) = xns;
|
34
|
-
return self;
|
35
|
-
}
|
36
|
-
|
37
|
-
VALUE
|
38
|
-
ruby_xml_ns_wrap(xmlNsPtr xns) {
|
39
|
-
return(Data_Wrap_Struct(cXMLNS, NULL, NULL, xns));
|
40
|
-
}
|
41
|
-
|
42
|
-
|
43
|
-
/*
|
44
|
-
* call-seq:
|
45
|
-
* ns.href -> "href"
|
46
|
-
*
|
47
|
-
* Obtain the namespace's href.
|
48
|
-
*/
|
49
|
-
VALUE
|
50
|
-
ruby_xml_ns_href_get(VALUE self) {
|
51
|
-
xmlNsPtr xns;
|
52
|
-
Data_Get_Struct(self, xmlNs, xns);
|
53
|
-
if (xns == NULL || xns->href == NULL)
|
54
|
-
return(Qnil);
|
55
|
-
else
|
56
|
-
return(rb_str_new2((const char*)xns->href));
|
57
|
-
}
|
58
|
-
|
59
|
-
|
60
|
-
/*
|
61
|
-
* call-seq:
|
62
|
-
* ns.href? -> (true|false)
|
63
|
-
*
|
64
|
-
* Determine whether this namespace has an href.
|
65
|
-
*/
|
66
|
-
VALUE
|
67
|
-
ruby_xml_ns_href_q(VALUE self) {
|
68
|
-
xmlNsPtr xns;
|
69
|
-
Data_Get_Struct(self, xmlNs, xns);
|
70
|
-
if (xns == NULL || xns->href == NULL)
|
71
|
-
return(Qfalse);
|
72
|
-
else
|
73
|
-
return(Qtrue);
|
74
|
-
}
|
75
|
-
|
76
|
-
|
77
|
-
/*
|
78
|
-
* call-seq:
|
79
|
-
* ns.next -> ns
|
80
|
-
*
|
81
|
-
* Obtain the next namespace.
|
82
|
-
*/
|
83
|
-
VALUE
|
84
|
-
ruby_xml_ns_next(VALUE self) {
|
85
|
-
xmlNsPtr xns;
|
86
|
-
Data_Get_Struct(self, xmlNs, xns);
|
87
|
-
if (xns == NULL || xns->next == NULL)
|
88
|
-
return(Qnil);
|
89
|
-
else
|
90
|
-
return(ruby_xml_ns_wrap(xns->next));
|
91
|
-
}
|
92
|
-
|
93
|
-
|
94
|
-
/*
|
95
|
-
* call-seq:
|
96
|
-
* ns.prefix -> "prefix"
|
97
|
-
* ns.to_s -> "prefix"
|
98
|
-
*
|
99
|
-
* Obtain the namespace's prefix.
|
100
|
-
*/
|
101
|
-
VALUE
|
102
|
-
ruby_xml_ns_prefix_get(VALUE self) {
|
103
|
-
xmlNsPtr xns;
|
104
|
-
Data_Get_Struct(self, xmlNs, xns);
|
105
|
-
if (xns == NULL || xns->prefix == NULL)
|
106
|
-
return(Qnil);
|
107
|
-
else
|
108
|
-
return(rb_str_new2((const char*)xns->prefix));
|
109
|
-
}
|
110
|
-
|
111
|
-
|
112
|
-
/*
|
113
|
-
* call-seq:
|
114
|
-
* ns.prefix? -> (true|false)
|
115
|
-
*
|
116
|
-
* Determine whether this namespace has a prefix.
|
117
|
-
*/
|
118
|
-
VALUE
|
119
|
-
ruby_xml_ns_prefix_q(VALUE self) {
|
120
|
-
xmlNsPtr xns;
|
121
|
-
Data_Get_Struct(self, xmlNs, xns);
|
122
|
-
if (xns == NULL || xns->prefix == NULL)
|
123
|
-
return(Qfalse);
|
124
|
-
else
|
125
|
-
return(Qtrue);
|
126
|
-
}
|
127
|
-
|
128
|
-
// Rdoc needs to know
|
129
|
-
#ifdef RDOC_NEVER_DEFINED
|
130
|
-
mLibXML = rb_define_module("LibXML");
|
131
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
132
|
-
#endif
|
133
|
-
|
134
|
-
void
|
135
|
-
ruby_init_xml_ns(void) {
|
136
|
-
cXMLNS = rb_define_class_under(mXML, "NS", rb_cObject);
|
137
|
-
rb_define_alloc_func(cXMLNS, ruby_xml_ns_alloc);
|
138
|
-
rb_define_method(cXMLNS, "initialize", ruby_xml_ns_initialize, 3);
|
139
|
-
rb_define_method(cXMLNS, "href", ruby_xml_ns_href_get, 0);
|
140
|
-
rb_define_method(cXMLNS, "href?", ruby_xml_ns_href_q, 0);
|
141
|
-
rb_define_method(cXMLNS, "next", ruby_xml_ns_next, 0);
|
142
|
-
rb_define_method(cXMLNS, "prefix", ruby_xml_ns_prefix_get, 0);
|
143
|
-
rb_define_method(cXMLNS, "prefix?", ruby_xml_ns_prefix_q, 0);
|
144
|
-
rb_define_method(cXMLNS, "to_s", ruby_xml_ns_prefix_get, 0);
|
145
|
-
}
|
1
|
+
/* $Id: ruby_xml_ns.c 461 2008-07-15 21:35:56Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "ruby_libxml.h"
|
6
|
+
#include "ruby_xml_ns.h"
|
7
|
+
|
8
|
+
VALUE cXMLNS;
|
9
|
+
|
10
|
+
|
11
|
+
VALUE
|
12
|
+
ruby_xml_ns_alloc(VALUE klass) {
|
13
|
+
return Data_Wrap_Struct(cXMLNS, NULL, NULL, NULL);
|
14
|
+
}
|
15
|
+
|
16
|
+
/*
|
17
|
+
* call-seq:
|
18
|
+
* initialize(node, "href", "prefix")
|
19
|
+
*
|
20
|
+
* Create a new namespace attached to the specified node with the
|
21
|
+
* give prefix and namespace.
|
22
|
+
*
|
23
|
+
* XML::NS.new(node, "xlink", "http://www.w3.org/1999/xlink")
|
24
|
+
*/
|
25
|
+
VALUE
|
26
|
+
ruby_xml_ns_initialize(VALUE self, VALUE node, VALUE href, VALUE prefix) {
|
27
|
+
xmlNodePtr xnode;
|
28
|
+
xmlNsPtr xns;
|
29
|
+
|
30
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
31
|
+
xns = xmlNewNs(xnode, (xmlChar*)StringValuePtr(href), (xmlChar*)StringValuePtr(prefix));
|
32
|
+
|
33
|
+
DATA_PTR(self) = xns;
|
34
|
+
return self;
|
35
|
+
}
|
36
|
+
|
37
|
+
VALUE
|
38
|
+
ruby_xml_ns_wrap(xmlNsPtr xns) {
|
39
|
+
return(Data_Wrap_Struct(cXMLNS, NULL, NULL, xns));
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
/*
|
44
|
+
* call-seq:
|
45
|
+
* ns.href -> "href"
|
46
|
+
*
|
47
|
+
* Obtain the namespace's href.
|
48
|
+
*/
|
49
|
+
VALUE
|
50
|
+
ruby_xml_ns_href_get(VALUE self) {
|
51
|
+
xmlNsPtr xns;
|
52
|
+
Data_Get_Struct(self, xmlNs, xns);
|
53
|
+
if (xns == NULL || xns->href == NULL)
|
54
|
+
return(Qnil);
|
55
|
+
else
|
56
|
+
return(rb_str_new2((const char*)xns->href));
|
57
|
+
}
|
58
|
+
|
59
|
+
|
60
|
+
/*
|
61
|
+
* call-seq:
|
62
|
+
* ns.href? -> (true|false)
|
63
|
+
*
|
64
|
+
* Determine whether this namespace has an href.
|
65
|
+
*/
|
66
|
+
VALUE
|
67
|
+
ruby_xml_ns_href_q(VALUE self) {
|
68
|
+
xmlNsPtr xns;
|
69
|
+
Data_Get_Struct(self, xmlNs, xns);
|
70
|
+
if (xns == NULL || xns->href == NULL)
|
71
|
+
return(Qfalse);
|
72
|
+
else
|
73
|
+
return(Qtrue);
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
/*
|
78
|
+
* call-seq:
|
79
|
+
* ns.next -> ns
|
80
|
+
*
|
81
|
+
* Obtain the next namespace.
|
82
|
+
*/
|
83
|
+
VALUE
|
84
|
+
ruby_xml_ns_next(VALUE self) {
|
85
|
+
xmlNsPtr xns;
|
86
|
+
Data_Get_Struct(self, xmlNs, xns);
|
87
|
+
if (xns == NULL || xns->next == NULL)
|
88
|
+
return(Qnil);
|
89
|
+
else
|
90
|
+
return(ruby_xml_ns_wrap(xns->next));
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
/*
|
95
|
+
* call-seq:
|
96
|
+
* ns.prefix -> "prefix"
|
97
|
+
* ns.to_s -> "prefix"
|
98
|
+
*
|
99
|
+
* Obtain the namespace's prefix.
|
100
|
+
*/
|
101
|
+
VALUE
|
102
|
+
ruby_xml_ns_prefix_get(VALUE self) {
|
103
|
+
xmlNsPtr xns;
|
104
|
+
Data_Get_Struct(self, xmlNs, xns);
|
105
|
+
if (xns == NULL || xns->prefix == NULL)
|
106
|
+
return(Qnil);
|
107
|
+
else
|
108
|
+
return(rb_str_new2((const char*)xns->prefix));
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
/*
|
113
|
+
* call-seq:
|
114
|
+
* ns.prefix? -> (true|false)
|
115
|
+
*
|
116
|
+
* Determine whether this namespace has a prefix.
|
117
|
+
*/
|
118
|
+
VALUE
|
119
|
+
ruby_xml_ns_prefix_q(VALUE self) {
|
120
|
+
xmlNsPtr xns;
|
121
|
+
Data_Get_Struct(self, xmlNs, xns);
|
122
|
+
if (xns == NULL || xns->prefix == NULL)
|
123
|
+
return(Qfalse);
|
124
|
+
else
|
125
|
+
return(Qtrue);
|
126
|
+
}
|
127
|
+
|
128
|
+
// Rdoc needs to know
|
129
|
+
#ifdef RDOC_NEVER_DEFINED
|
130
|
+
mLibXML = rb_define_module("LibXML");
|
131
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
132
|
+
#endif
|
133
|
+
|
134
|
+
void
|
135
|
+
ruby_init_xml_ns(void) {
|
136
|
+
cXMLNS = rb_define_class_under(mXML, "NS", rb_cObject);
|
137
|
+
rb_define_alloc_func(cXMLNS, ruby_xml_ns_alloc);
|
138
|
+
rb_define_method(cXMLNS, "initialize", ruby_xml_ns_initialize, 3);
|
139
|
+
rb_define_method(cXMLNS, "href", ruby_xml_ns_href_get, 0);
|
140
|
+
rb_define_method(cXMLNS, "href?", ruby_xml_ns_href_q, 0);
|
141
|
+
rb_define_method(cXMLNS, "next", ruby_xml_ns_next, 0);
|
142
|
+
rb_define_method(cXMLNS, "prefix", ruby_xml_ns_prefix_get, 0);
|
143
|
+
rb_define_method(cXMLNS, "prefix?", ruby_xml_ns_prefix_q, 0);
|
144
|
+
rb_define_method(cXMLNS, "to_s", ruby_xml_ns_prefix_get, 0);
|
145
|
+
}
|
@@ -1,1398 +1,1398 @@
|
|
1
|
-
/* $Id: ruby_xml_parser.c 461 2008-07-15 21:35:56Z 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
|
-
static int id_call;
|
9
|
-
|
10
|
-
VALUE cXMLParser;
|
11
|
-
VALUE eXMLParserParseError;
|
12
|
-
|
13
|
-
static int
|
14
|
-
ctxtRead(FILE *f, char * buf, size_t len) {
|
15
|
-
return(fread(buf, 1, len, f));
|
16
|
-
}
|
17
|
-
|
18
|
-
/*
|
19
|
-
* call-seq:
|
20
|
-
* XML::Parser.catalog_dump -> true
|
21
|
-
*
|
22
|
-
* Dump the parser resource catalogs to stdout.
|
23
|
-
*/
|
24
|
-
VALUE
|
25
|
-
ruby_xml_parser_catalog_dump(VALUE self) {
|
26
|
-
xmlCatalogDump(stdout);
|
27
|
-
return(Qtrue);
|
28
|
-
}
|
29
|
-
|
30
|
-
|
31
|
-
/*
|
32
|
-
* call-seq:
|
33
|
-
* XML::Parser.catalog_remove(catalog) -> true
|
34
|
-
*
|
35
|
-
* Remove the specified resource catalog.
|
36
|
-
*/
|
37
|
-
VALUE
|
38
|
-
ruby_xml_parser_catalog_remove(VALUE self, VALUE cat) {
|
39
|
-
Check_Type(cat, T_STRING);
|
40
|
-
xmlCatalogRemove((xmlChar *)StringValuePtr(cat));
|
41
|
-
return(Qtrue);
|
42
|
-
}
|
43
|
-
|
44
|
-
|
45
|
-
/*
|
46
|
-
* call-seq:
|
47
|
-
* XML::Parser.check_lib_versions -> true
|
48
|
-
*
|
49
|
-
* Check LIBXML version matches version the bindings
|
50
|
-
* were compiled to. Throws an exception if not.
|
51
|
-
*/
|
52
|
-
VALUE
|
53
|
-
ruby_xml_parser_check_lib_versions(VALUE class) {
|
54
|
-
xmlCheckVersion(LIBXML_VERSION);
|
55
|
-
return(Qtrue);
|
56
|
-
}
|
57
|
-
|
58
|
-
|
59
|
-
/*
|
60
|
-
* call-seq:
|
61
|
-
* XML::Parser.enabled_automata? -> (true|false)
|
62
|
-
*
|
63
|
-
* Determine whether libxml regexp automata support is enabled.
|
64
|
-
*/
|
65
|
-
VALUE
|
66
|
-
ruby_xml_parser_enabled_automata_q(VALUE class) {
|
67
|
-
#ifdef LIBXML_AUTOMATA_ENABLED
|
68
|
-
return(Qtrue);
|
69
|
-
#else
|
70
|
-
return(Qfalse);
|
71
|
-
#endif
|
72
|
-
}
|
73
|
-
|
74
|
-
|
75
|
-
/*
|
76
|
-
* call-seq:
|
77
|
-
* XML::Parser.enabled_c14n? -> (true|false)
|
78
|
-
*
|
79
|
-
* Determine whether libxml 'canonical XML' support is enabled.
|
80
|
-
* See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
|
81
|
-
*/
|
82
|
-
VALUE
|
83
|
-
ruby_xml_parser_enabled_c14n_q(VALUE class) {
|
84
|
-
#ifdef LIBXML_C14N_ENABLED
|
85
|
-
return(Qtrue);
|
86
|
-
#else
|
87
|
-
return(Qfalse);
|
88
|
-
#endif
|
89
|
-
}
|
90
|
-
|
91
|
-
|
92
|
-
/*
|
93
|
-
* call-seq:
|
94
|
-
* XML::Parser.enabled_catalog? -> (true|false)
|
95
|
-
*
|
96
|
-
* Determine whether libxml resource catalog support is enabled.
|
97
|
-
*/
|
98
|
-
VALUE
|
99
|
-
ruby_xml_parser_enabled_catalog_q(VALUE class) {
|
100
|
-
#ifdef LIBXML_CATALOG_ENABLED
|
101
|
-
return(Qtrue);
|
102
|
-
#else
|
103
|
-
return(Qfalse);
|
104
|
-
#endif
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
/*
|
109
|
-
* call-seq:
|
110
|
-
* XML::Parser.enabled_debug? -> (true|false)
|
111
|
-
*
|
112
|
-
* Determine whether libxml debugging support is enabled.
|
113
|
-
*/
|
114
|
-
VALUE
|
115
|
-
ruby_xml_parser_enabled_debug_q(VALUE class) {
|
116
|
-
#ifdef LIBXML_DEBUG_ENABLED
|
117
|
-
return(Qtrue);
|
118
|
-
#else
|
119
|
-
return(Qfalse);
|
120
|
-
#endif
|
121
|
-
}
|
122
|
-
|
123
|
-
|
124
|
-
/*
|
125
|
-
* call-seq:
|
126
|
-
* XML::Parser.enabled_docbook? -> (true|false)
|
127
|
-
*
|
128
|
-
* Determine whether libxml docbook support is enabled.
|
129
|
-
*/
|
130
|
-
VALUE
|
131
|
-
ruby_xml_parser_enabled_docbook_q(VALUE class) {
|
132
|
-
#ifdef LIBXML_DOCB_ENABLED
|
133
|
-
return(Qtrue);
|
134
|
-
#else
|
135
|
-
return(Qfalse);
|
136
|
-
#endif
|
137
|
-
}
|
138
|
-
|
139
|
-
|
140
|
-
/*
|
141
|
-
* call-seq:
|
142
|
-
* XML::Parser.enabled_ftp? -> (true|false)
|
143
|
-
*
|
144
|
-
* Determine whether libxml ftp client support is enabled.
|
145
|
-
*/
|
146
|
-
VALUE
|
147
|
-
ruby_xml_parser_enabled_ftp_q(VALUE class) {
|
148
|
-
#ifdef LIBXML_FTP_ENABLED
|
149
|
-
return(Qtrue);
|
150
|
-
#else
|
151
|
-
return(Qfalse);
|
152
|
-
#endif
|
153
|
-
}
|
154
|
-
|
155
|
-
|
156
|
-
/*
|
157
|
-
* call-seq:
|
158
|
-
* XML::Parser.enabled_http? -> (true|false)
|
159
|
-
*
|
160
|
-
* Determine whether libxml http client support is enabled.
|
161
|
-
*/
|
162
|
-
VALUE
|
163
|
-
ruby_xml_parser_enabled_http_q(VALUE class) {
|
164
|
-
#ifdef LIBXML_HTTP_ENABLED
|
165
|
-
return(Qtrue);
|
166
|
-
#else
|
167
|
-
return(Qfalse);
|
168
|
-
#endif
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
/*
|
173
|
-
* call-seq:
|
174
|
-
* XML::Parser.enabled_html? -> (true|false)
|
175
|
-
*
|
176
|
-
* Determine whether libxml html support is enabled.
|
177
|
-
*/
|
178
|
-
VALUE
|
179
|
-
ruby_xml_parser_enabled_html_q(VALUE class) {
|
180
|
-
#ifdef LIBXML_HTML_ENABLED
|
181
|
-
return(Qtrue);
|
182
|
-
#else
|
183
|
-
return(Qfalse);
|
184
|
-
#endif
|
185
|
-
}
|
186
|
-
|
187
|
-
|
188
|
-
/*
|
189
|
-
* call-seq:
|
190
|
-
* XML::Parser.enabled_iconv? -> (true|false)
|
191
|
-
*
|
192
|
-
* Determine whether libxml iconv support is enabled.
|
193
|
-
*/
|
194
|
-
VALUE
|
195
|
-
ruby_xml_parser_enabled_iconv_q(VALUE class) {
|
196
|
-
#ifdef LIBXML_ICONV_ENABLED
|
197
|
-
return(Qtrue);
|
198
|
-
#else
|
199
|
-
return(Qfalse);
|
200
|
-
#endif
|
201
|
-
}
|
202
|
-
|
203
|
-
|
204
|
-
/*
|
205
|
-
* call-seq:
|
206
|
-
* XML::Parser.enabled_memory_debug? -> (true|false)
|
207
|
-
*
|
208
|
-
* Determine whether libxml memory location debugging support
|
209
|
-
* is enabled.
|
210
|
-
*/
|
211
|
-
VALUE
|
212
|
-
ruby_xml_parser_enabled_memory_debug_location_q(VALUE class) {
|
213
|
-
#ifdef DEBUG_MEMORY_LOCATION
|
214
|
-
return(Qtrue);
|
215
|
-
#else
|
216
|
-
return(Qfalse);
|
217
|
-
#endif
|
218
|
-
}
|
219
|
-
|
220
|
-
|
221
|
-
/*
|
222
|
-
* call-seq:
|
223
|
-
* XML::Parser.enabled_regexp? -> (true|false)
|
224
|
-
*
|
225
|
-
* Determine whether libxml regular expression support is enabled.
|
226
|
-
*/
|
227
|
-
VALUE
|
228
|
-
ruby_xml_parser_enabled_regexp_q(VALUE class) {
|
229
|
-
#ifdef LIBXML_REGEXP_ENABLED
|
230
|
-
return(Qtrue);
|
231
|
-
#else
|
232
|
-
return(Qfalse);
|
233
|
-
#endif
|
234
|
-
}
|
235
|
-
|
236
|
-
|
237
|
-
/*
|
238
|
-
* call-seq:
|
239
|
-
* XML::Parser.enabled_schemas? -> (true|false)
|
240
|
-
*
|
241
|
-
* Determine whether libxml schema support is enabled.
|
242
|
-
*/
|
243
|
-
VALUE
|
244
|
-
ruby_xml_parser_enabled_schemas_q(VALUE class) {
|
245
|
-
#ifdef LIBXML_SCHEMAS_ENABLED
|
246
|
-
return(Qtrue);
|
247
|
-
#else
|
248
|
-
return(Qfalse);
|
249
|
-
#endif
|
250
|
-
}
|
251
|
-
|
252
|
-
|
253
|
-
/*
|
254
|
-
* call-seq:
|
255
|
-
* XML::Parser.enabled_thread? -> (true|false)
|
256
|
-
*
|
257
|
-
* Determine whether libxml thread-safe semantics support
|
258
|
-
* is enabled (I think?).
|
259
|
-
*/
|
260
|
-
VALUE
|
261
|
-
ruby_xml_parser_enabled_thread_q(VALUE class) {
|
262
|
-
#ifdef LIBXML_THREAD_ENABLED
|
263
|
-
return(Qtrue);
|
264
|
-
#else
|
265
|
-
return(Qfalse);
|
266
|
-
#endif
|
267
|
-
}
|
268
|
-
|
269
|
-
|
270
|
-
/*
|
271
|
-
* call-seq:
|
272
|
-
* XML::Parser.enabled_unicode? -> (true|false)
|
273
|
-
*
|
274
|
-
* Determine whether libxml unicode support is enabled.
|
275
|
-
*/
|
276
|
-
VALUE
|
277
|
-
ruby_xml_parser_enabled_unicode_q(VALUE class) {
|
278
|
-
#ifdef LIBXML_UNICODE_ENABLED
|
279
|
-
return(Qtrue);
|
280
|
-
#else
|
281
|
-
return(Qfalse);
|
282
|
-
#endif
|
283
|
-
}
|
284
|
-
|
285
|
-
|
286
|
-
/*
|
287
|
-
* call-seq:
|
288
|
-
* XML::Parser.enabled_xinclude? -> (true|false)
|
289
|
-
*
|
290
|
-
* Determine whether libxml xinclude support is enabled.
|
291
|
-
*/
|
292
|
-
VALUE
|
293
|
-
ruby_xml_parser_enabled_xinclude_q(VALUE class) {
|
294
|
-
#ifdef LIBXML_XINCLUDE_ENABLED
|
295
|
-
return(Qtrue);
|
296
|
-
#else
|
297
|
-
return(Qfalse);
|
298
|
-
#endif
|
299
|
-
}
|
300
|
-
|
301
|
-
|
302
|
-
/*
|
303
|
-
* call-seq:
|
304
|
-
* XML::Parser.enabled_xpath? -> (true|false)
|
305
|
-
*
|
306
|
-
* Determine whether libxml xpath support is enabled.
|
307
|
-
*/
|
308
|
-
VALUE
|
309
|
-
ruby_xml_parser_enabled_xpath_q(VALUE class) {
|
310
|
-
#ifdef LIBXML_XPATH_ENABLED
|
311
|
-
return(Qtrue);
|
312
|
-
#else
|
313
|
-
return(Qfalse);
|
314
|
-
#endif
|
315
|
-
}
|
316
|
-
|
317
|
-
|
318
|
-
/*
|
319
|
-
* call-seq:
|
320
|
-
* XML::Parser.enabled_xpointer? -> (true|false)
|
321
|
-
*
|
322
|
-
* Determine whether libxml xpointer support is enabled.
|
323
|
-
*/
|
324
|
-
VALUE
|
325
|
-
ruby_xml_parser_enabled_xpointer_q(VALUE class) {
|
326
|
-
#ifdef LIBXML_XPTR_ENABLED
|
327
|
-
return(Qtrue);
|
328
|
-
#else
|
329
|
-
return(Qfalse);
|
330
|
-
#endif
|
331
|
-
}
|
332
|
-
|
333
|
-
|
334
|
-
/*
|
335
|
-
* call-seq:
|
336
|
-
* XML::Parser.enabled_zlib? -> (true|false)
|
337
|
-
*
|
338
|
-
* Determine whether libxml zlib support is enabled.
|
339
|
-
*/
|
340
|
-
VALUE
|
341
|
-
ruby_xml_parser_enabled_zlib_q(VALUE class) {
|
342
|
-
#ifdef HAVE_ZLIB_H
|
343
|
-
return(Qtrue);
|
344
|
-
#else
|
345
|
-
return(Qfalse);
|
346
|
-
#endif
|
347
|
-
}
|
348
|
-
|
349
|
-
|
350
|
-
/*
|
351
|
-
* call-seq:
|
352
|
-
* XML::Parser.debug_entities -> (true|false)
|
353
|
-
*
|
354
|
-
* Determine whether included-entity debugging is enabled.
|
355
|
-
* (Requires Libxml to be compiled with debugging support)
|
356
|
-
*/
|
357
|
-
VALUE
|
358
|
-
ruby_xml_parser_debug_entities_get(VALUE class) {
|
359
|
-
#ifdef LIBXML_DEBUG_ENABLED
|
360
|
-
if (xmlParserDebugEntities)
|
361
|
-
return(Qtrue);
|
362
|
-
else
|
363
|
-
return(Qfalse);
|
364
|
-
#else
|
365
|
-
rb_warn("libxml was compiled with debugging turned off");
|
366
|
-
return(Qfalse);
|
367
|
-
#endif
|
368
|
-
}
|
369
|
-
|
370
|
-
|
371
|
-
/*
|
372
|
-
* call-seq:
|
373
|
-
* XML::Parser.debug_entities = true|false
|
374
|
-
*
|
375
|
-
* Enable or disable included-entity debugging.
|
376
|
-
* (Requires Libxml to be compiled with debugging support)
|
377
|
-
*/
|
378
|
-
VALUE
|
379
|
-
ruby_xml_parser_debug_entities_set(VALUE class, VALUE bool) {
|
380
|
-
#ifdef LIBXML_DEBUG_ENABLED
|
381
|
-
if (TYPE(bool) == T_FALSE) {
|
382
|
-
xmlParserDebugEntities = 0;
|
383
|
-
return(Qfalse);
|
384
|
-
} else {
|
385
|
-
xmlParserDebugEntities = 1;
|
386
|
-
return(Qtrue);
|
387
|
-
}
|
388
|
-
#else
|
389
|
-
rb_warn("libxml was compiled with debugging turned off");
|
390
|
-
#endif
|
391
|
-
}
|
392
|
-
|
393
|
-
|
394
|
-
/*
|
395
|
-
* call-seq:
|
396
|
-
* XML::Parser.default_keep_blanks -> (true|false)
|
397
|
-
*
|
398
|
-
* Determine whether parsers retain whitespace by default.
|
399
|
-
*/
|
400
|
-
VALUE
|
401
|
-
ruby_xml_parser_default_keep_blanks_get(VALUE class) {
|
402
|
-
if (xmlKeepBlanksDefaultValue)
|
403
|
-
return(Qtrue);
|
404
|
-
else
|
405
|
-
return(Qfalse);
|
406
|
-
}
|
407
|
-
|
408
|
-
|
409
|
-
/*
|
410
|
-
* call-seq:
|
411
|
-
* XML::Parser.default_keep_blanks = true|false
|
412
|
-
*
|
413
|
-
* Controls whether parsers retain whitespace by default.
|
414
|
-
*/
|
415
|
-
VALUE
|
416
|
-
ruby_xml_parser_default_keep_blanks_set(VALUE class, VALUE bool) {
|
417
|
-
if (TYPE(bool) == T_FALSE) {
|
418
|
-
xmlKeepBlanksDefaultValue = 0;
|
419
|
-
return(Qfalse);
|
420
|
-
} else if (TYPE(bool) == T_TRUE) {
|
421
|
-
xmlKeepBlanksDefaultValue = 1;
|
422
|
-
return(Qtrue);
|
423
|
-
} else {
|
424
|
-
rb_raise(rb_eArgError, "invalid argument, must be a boolean");
|
425
|
-
}
|
426
|
-
}
|
427
|
-
|
428
|
-
|
429
|
-
/*
|
430
|
-
* call-seq:
|
431
|
-
* XML::Parser.default_load_external_dtd -> (true|false)
|
432
|
-
*
|
433
|
-
* Determine whether parsers load external DTDs by default.
|
434
|
-
*/
|
435
|
-
VALUE
|
436
|
-
ruby_xml_parser_default_load_external_dtd_get(VALUE class) {
|
437
|
-
if (xmlLoadExtDtdDefaultValue)
|
438
|
-
return(Qtrue);
|
439
|
-
else
|
440
|
-
return(Qfalse);
|
441
|
-
}
|
442
|
-
|
443
|
-
|
444
|
-
/*
|
445
|
-
* call-seq:
|
446
|
-
* XML::Parser.default_load_external_dtd = true|false
|
447
|
-
*
|
448
|
-
* Controls whether parsers load external DTDs by default.
|
449
|
-
*/
|
450
|
-
VALUE
|
451
|
-
ruby_xml_parser_default_load_external_dtd_set(VALUE class, VALUE bool) {
|
452
|
-
if (TYPE(bool) == T_FALSE) {
|
453
|
-
xmlLoadExtDtdDefaultValue = 0;
|
454
|
-
return(Qfalse);
|
455
|
-
} else {
|
456
|
-
xmlLoadExtDtdDefaultValue = 1;
|
457
|
-
return(Qtrue);
|
458
|
-
}
|
459
|
-
}
|
460
|
-
|
461
|
-
|
462
|
-
/*
|
463
|
-
* call-seq:
|
464
|
-
* XML::Parser.default_line_numbers -> (true|false)
|
465
|
-
*
|
466
|
-
* Determine whether parsers retain line-numbers by default.
|
467
|
-
*/
|
468
|
-
VALUE
|
469
|
-
ruby_xml_parser_default_line_numbers_get(VALUE class) {
|
470
|
-
if (xmlLineNumbersDefaultValue)
|
471
|
-
return(Qtrue);
|
472
|
-
else
|
473
|
-
return(Qfalse);
|
474
|
-
}
|
475
|
-
|
476
|
-
|
477
|
-
/*
|
478
|
-
* call-seq:
|
479
|
-
* XML::Parser.default_line_numbers = true|false
|
480
|
-
*
|
481
|
-
* Controls whether parsers retain line-numbers by default.
|
482
|
-
*/
|
483
|
-
VALUE
|
484
|
-
ruby_xml_parser_default_line_numbers_set(VALUE class, VALUE bool) {
|
485
|
-
if (TYPE(bool) == T_FALSE) {
|
486
|
-
xmlLineNumbersDefault(0);
|
487
|
-
return(Qfalse);
|
488
|
-
} else {
|
489
|
-
xmlLineNumbersDefault(1);
|
490
|
-
return(Qtrue);
|
491
|
-
}
|
492
|
-
}
|
493
|
-
|
494
|
-
|
495
|
-
/*
|
496
|
-
* call-seq:
|
497
|
-
* XML::Parser.default_pedantic_parser -> (true|false)
|
498
|
-
*
|
499
|
-
* Determine whether parsers are pedantic by default.
|
500
|
-
*/
|
501
|
-
VALUE
|
502
|
-
ruby_xml_parser_default_pedantic_parser_get(VALUE class) {
|
503
|
-
if (xmlPedanticParserDefaultValue)
|
504
|
-
return(Qtrue);
|
505
|
-
else
|
506
|
-
return(Qfalse);
|
507
|
-
}
|
508
|
-
|
509
|
-
|
510
|
-
/*
|
511
|
-
* call-seq:
|
512
|
-
* XML::Parser.default_pedantic_parser = true|false
|
513
|
-
*
|
514
|
-
* Controls whether parsers are pedantic by default.
|
515
|
-
*/
|
516
|
-
VALUE
|
517
|
-
ruby_xml_parser_default_pedantic_parser_set(VALUE class, VALUE bool) {
|
518
|
-
if (TYPE(bool) == T_FALSE) {
|
519
|
-
xmlPedanticParserDefault(0);
|
520
|
-
return(Qfalse);
|
521
|
-
} else {
|
522
|
-
xmlPedanticParserDefault(1);
|
523
|
-
return(Qtrue);
|
524
|
-
}
|
525
|
-
}
|
526
|
-
|
527
|
-
|
528
|
-
/*
|
529
|
-
* call-seq:
|
530
|
-
* XML::Parser.default_substitute_entities -> (true|false)
|
531
|
-
*
|
532
|
-
* Determine whether parsers perform inline entity substitution
|
533
|
-
* (for external entities) by default.
|
534
|
-
*/
|
535
|
-
VALUE
|
536
|
-
ruby_xml_parser_default_substitute_entities_get(VALUE class) {
|
537
|
-
if (xmlSubstituteEntitiesDefaultValue)
|
538
|
-
return(Qtrue);
|
539
|
-
else
|
540
|
-
return(Qfalse);
|
541
|
-
}
|
542
|
-
|
543
|
-
|
544
|
-
/*
|
545
|
-
* call-seq:
|
546
|
-
* XML::Parser.default_substitute_entities = true|false
|
547
|
-
*
|
548
|
-
* Controls whether parsers perform inline entity substitution
|
549
|
-
* (for external entities) by default.
|
550
|
-
*/
|
551
|
-
VALUE
|
552
|
-
ruby_xml_parser_default_substitute_entities_set(VALUE class, VALUE bool) {
|
553
|
-
if (TYPE(bool) == T_FALSE) {
|
554
|
-
xmlSubstituteEntitiesDefault(0);
|
555
|
-
return(Qfalse);
|
556
|
-
} else {
|
557
|
-
xmlSubstituteEntitiesDefault(1);
|
558
|
-
return(Qtrue);
|
559
|
-
}
|
560
|
-
}
|
561
|
-
|
562
|
-
|
563
|
-
/*
|
564
|
-
* call-seq:
|
565
|
-
* XML::Parser.default_tree_indent_string -> "string"
|
566
|
-
*
|
567
|
-
* Obtain the default string used by parsers to indent the XML tree
|
568
|
-
* for output.
|
569
|
-
*/
|
570
|
-
VALUE
|
571
|
-
ruby_xml_parser_default_tree_indent_string_get(VALUE class) {
|
572
|
-
if (xmlTreeIndentString == NULL)
|
573
|
-
return(Qnil);
|
574
|
-
else
|
575
|
-
return(rb_str_new2(xmlTreeIndentString));
|
576
|
-
}
|
577
|
-
|
578
|
-
|
579
|
-
/*
|
580
|
-
* call-seq:
|
581
|
-
* XML::Parser.default_tree_indent_string = "string"
|
582
|
-
*
|
583
|
-
* Set the default string used by parsers to indent the XML tree
|
584
|
-
* for output.
|
585
|
-
*/
|
586
|
-
VALUE
|
587
|
-
ruby_xml_parser_default_tree_indent_string_set(VALUE class, VALUE string) {
|
588
|
-
Check_Type(string, T_STRING);
|
589
|
-
xmlTreeIndentString = xmlStrdup(StringValuePtr(string));
|
590
|
-
return(string);
|
591
|
-
}
|
592
|
-
|
593
|
-
|
594
|
-
/*
|
595
|
-
* call-seq:
|
596
|
-
* XML::Parser.default_validity_checking -> (true|false)
|
597
|
-
*
|
598
|
-
* Determine whether parsers perform XML validation by default.
|
599
|
-
*/
|
600
|
-
VALUE
|
601
|
-
ruby_xml_parser_default_validity_checking_get(VALUE class) {
|
602
|
-
if (xmlDoValidityCheckingDefaultValue)
|
603
|
-
return(Qtrue);
|
604
|
-
else
|
605
|
-
return(Qfalse);
|
606
|
-
}
|
607
|
-
|
608
|
-
|
609
|
-
/*
|
610
|
-
* call-seq:
|
611
|
-
* XML::Parser.default_validity_checking = true|false
|
612
|
-
*
|
613
|
-
* Controls whether parsers perform XML validation by default.
|
614
|
-
*/
|
615
|
-
VALUE
|
616
|
-
ruby_xml_parser_default_validity_checking_set(VALUE class, VALUE bool) {
|
617
|
-
if (TYPE(bool) == T_FALSE) {
|
618
|
-
xmlDoValidityCheckingDefaultValue = 0;
|
619
|
-
return(Qfalse);
|
620
|
-
} else {
|
621
|
-
xmlDoValidityCheckingDefaultValue = 1;
|
622
|
-
return(Qtrue);
|
623
|
-
}
|
624
|
-
}
|
625
|
-
|
626
|
-
|
627
|
-
/*
|
628
|
-
* call-seq:
|
629
|
-
* XML::Parser.default_warnings -> (true|false)
|
630
|
-
*
|
631
|
-
* Determine whether parsers output warnings by default.
|
632
|
-
*/
|
633
|
-
VALUE
|
634
|
-
ruby_xml_parser_default_warnings_get(VALUE class) {
|
635
|
-
if (xmlGetWarningsDefaultValue)
|
636
|
-
return(Qtrue);
|
637
|
-
else
|
638
|
-
return(Qfalse);
|
639
|
-
}
|
640
|
-
|
641
|
-
|
642
|
-
/*
|
643
|
-
* call-seq:
|
644
|
-
* XML::Parser.default_warnings = true|false
|
645
|
-
*
|
646
|
-
* Controls whether parsers output warnings by default.
|
647
|
-
*/
|
648
|
-
VALUE
|
649
|
-
ruby_xml_parser_default_warnings_set(VALUE class, VALUE bool) {
|
650
|
-
if (TYPE(bool) == T_FALSE) {
|
651
|
-
xmlGetWarningsDefaultValue = 0;
|
652
|
-
return(Qfalse);
|
653
|
-
} else {
|
654
|
-
xmlGetWarningsDefaultValue = 1;
|
655
|
-
return(Qtrue);
|
656
|
-
}
|
657
|
-
}
|
658
|
-
|
659
|
-
|
660
|
-
/*
|
661
|
-
* call-seq:
|
662
|
-
* XML::Parser.default_compression -> (true|false)
|
663
|
-
*
|
664
|
-
* Determine whether parsers use Zlib compression by default
|
665
|
-
* (requires libxml to be compiled with Zlib support).
|
666
|
-
*/
|
667
|
-
VALUE
|
668
|
-
ruby_xml_parser_default_compression_get(VALUE class) {
|
669
|
-
#ifdef HAVE_ZLIB_H
|
670
|
-
return(INT2FIX(xmlGetCompressMode()));
|
671
|
-
#else
|
672
|
-
rb_warn("libxml was compiled without zlib support");
|
673
|
-
return(Qfalse);
|
674
|
-
#endif
|
675
|
-
}
|
676
|
-
|
677
|
-
|
678
|
-
/*
|
679
|
-
* call-seq:
|
680
|
-
* XML::Parser.default_compression = true|false
|
681
|
-
*
|
682
|
-
* Controls whether parsers use Zlib compression by default
|
683
|
-
* (requires libxml to be compiled with Zlib support).
|
684
|
-
*/
|
685
|
-
VALUE
|
686
|
-
ruby_xml_parser_default_compression_set(VALUE class, VALUE num) {
|
687
|
-
#ifdef HAVE_ZLIB_H
|
688
|
-
Check_Type(num, T_FIXNUM);
|
689
|
-
xmlSetCompressMode(FIX2INT(num));
|
690
|
-
return(num);
|
691
|
-
#else
|
692
|
-
rb_warn("libxml was compiled without zlib support");
|
693
|
-
return(Qfalse);
|
694
|
-
#endif
|
695
|
-
}
|
696
|
-
|
697
|
-
|
698
|
-
/*
|
699
|
-
* call-seq:
|
700
|
-
* XML::Parser.features -> ["feature", ..., "feature"]
|
701
|
-
*
|
702
|
-
* Obtains an array of strings representing features supported
|
703
|
-
* (and enabled) by the installed libxml.
|
704
|
-
*/
|
705
|
-
VALUE
|
706
|
-
ruby_xml_parser_features(VALUE class) {
|
707
|
-
VALUE arr, str;
|
708
|
-
int i, len = MAX_LIBXML_FEATURES_LEN;
|
709
|
-
char **list = NULL;
|
710
|
-
|
711
|
-
list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
|
712
|
-
MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);
|
713
|
-
|
714
|
-
arr = rb_ary_new();
|
715
|
-
if (xmlGetFeaturesList(&len, (const char **)list) == -1)
|
716
|
-
return Qnil;
|
717
|
-
|
718
|
-
for (i = 0; i < len; i++) {
|
719
|
-
str = rb_str_new2((const char *)list[i]);
|
720
|
-
rb_gc_unregister_address(&str);
|
721
|
-
rb_ary_push(arr, str);
|
722
|
-
}
|
723
|
-
|
724
|
-
if (len == MAX_LIBXML_FEATURES_LEN)
|
725
|
-
rb_warn("Please contact libxml-devel@rubyforge.org and ask to have the \"MAX_LIBXML_FEATURES_LEN increased\" because you could possibly be seeing an incomplete list");
|
726
|
-
|
727
|
-
ruby_xfree(list);
|
728
|
-
return(arr);
|
729
|
-
}
|
730
|
-
|
731
|
-
|
732
|
-
/*
|
733
|
-
* call-seq:
|
734
|
-
* parser.filename -> "filename"
|
735
|
-
*
|
736
|
-
* Obtain the filename this parser will read from.
|
737
|
-
*/
|
738
|
-
VALUE
|
739
|
-
ruby_xml_parser_filename_get(VALUE self) {
|
740
|
-
ruby_xml_parser *rxp;
|
741
|
-
rx_file_data *data;
|
742
|
-
|
743
|
-
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
744
|
-
if (rxp->data == NULL)
|
745
|
-
return(Qnil);
|
746
|
-
|
747
|
-
if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_FILE)
|
748
|
-
return(Qnil);
|
749
|
-
|
750
|
-
data = (rx_file_data *)rxp->data;
|
751
|
-
return(data->filename);
|
752
|
-
}
|
753
|
-
|
754
|
-
|
755
|
-
/*
|
756
|
-
* call-seq:
|
757
|
-
* parser.filename = "filename"
|
758
|
-
*
|
759
|
-
* Set the filename this parser will read from.
|
760
|
-
*/
|
761
|
-
VALUE
|
762
|
-
ruby_xml_parser_filename_set(VALUE self, VALUE filename) {
|
763
|
-
ruby_xml_parser *rxp;
|
764
|
-
ruby_xml_parser_context *rxpc;
|
765
|
-
rx_file_data *data;
|
766
|
-
int retry_count = 0;
|
767
|
-
|
768
|
-
Check_Type(filename, T_STRING);
|
769
|
-
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
770
|
-
|
771
|
-
if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
|
772
|
-
if (rxp->data != NULL)
|
773
|
-
rb_fatal("crap, this should be null");
|
774
|
-
|
775
|
-
rxp->data_type = RUBY_LIBXML_SRC_TYPE_FILE;
|
776
|
-
data = ALLOC(rx_file_data);
|
777
|
-
rxp->data = data;
|
778
|
-
} else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_FILE) {
|
779
|
-
return(Qnil);
|
780
|
-
}
|
781
|
-
|
782
|
-
rxp->ctxt = ruby_xml_parser_context_new();
|
783
|
-
data = (rx_file_data *)rxp->data;
|
784
|
-
data->filename = filename;
|
785
|
-
|
786
|
-
Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
|
787
|
-
retry:
|
788
|
-
rxpc->ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename));
|
789
|
-
if (rxpc->ctxt == NULL) {
|
790
|
-
if ((errno == EMFILE || errno == ENFILE) && retry_count == 0) {
|
791
|
-
retry_count++;
|
792
|
-
rb_gc();
|
793
|
-
goto retry;
|
794
|
-
} else {
|
795
|
-
rb_raise(rb_eIOError, StringValuePtr(filename));
|
796
|
-
}
|
797
|
-
}
|
798
|
-
|
799
|
-
return(data->filename);
|
800
|
-
}
|
801
|
-
|
802
|
-
|
803
|
-
void
|
804
|
-
ruby_xml_parser_free(ruby_xml_parser *rxp) {
|
805
|
-
void *data;
|
806
|
-
|
807
|
-
switch(rxp->data_type) {
|
808
|
-
case RUBY_LIBXML_SRC_TYPE_NULL:
|
809
|
-
break;
|
810
|
-
case RUBY_LIBXML_SRC_TYPE_FILE:
|
811
|
-
data = (void *)(rx_file_data *)rxp->data;
|
812
|
-
ruby_xfree((rx_file_data *)data);
|
813
|
-
break;
|
814
|
-
case RUBY_LIBXML_SRC_TYPE_STRING:
|
815
|
-
data = (void *)(rx_string_data *)rxp->data;
|
816
|
-
ruby_xfree((rx_string_data *)data);
|
817
|
-
break;
|
818
|
-
case RUBY_LIBXML_SRC_TYPE_IO:
|
819
|
-
data = (void *)(rx_io_data *)rxp->data;
|
820
|
-
ruby_xfree((rx_io_data *)data);
|
821
|
-
break;
|
822
|
-
default:
|
823
|
-
rb_fatal("Unknown data type, %d", rxp->data_type);
|
824
|
-
}
|
825
|
-
|
826
|
-
ruby_xfree(rxp);
|
827
|
-
}
|
828
|
-
|
829
|
-
|
830
|
-
/*
|
831
|
-
* call-seq:
|
832
|
-
* XML::Parser.indent_tree_output -> (true|false)
|
833
|
-
*
|
834
|
-
* Determines whether XML output will be indented
|
835
|
-
* (using the string supplied to +default_indent_tree_string+)
|
836
|
-
*/
|
837
|
-
VALUE
|
838
|
-
ruby_xml_parser_indent_tree_output_get(VALUE class) {
|
839
|
-
if (xmlIndentTreeOutput)
|
840
|
-
return(Qtrue);
|
841
|
-
else
|
842
|
-
return(Qfalse);
|
843
|
-
}
|
844
|
-
|
845
|
-
|
846
|
-
/*
|
847
|
-
* call-seq:
|
848
|
-
* XML::Parser.indent_tree_output = true|false
|
849
|
-
*
|
850
|
-
* Controls whether XML output will be indented
|
851
|
-
* (using the string supplied to +default_indent_tree_string+)
|
852
|
-
*/
|
853
|
-
VALUE
|
854
|
-
ruby_xml_parser_indent_tree_output_set(VALUE class, VALUE bool) {
|
855
|
-
if (TYPE(bool) == T_TRUE) {
|
856
|
-
xmlIndentTreeOutput = 1;
|
857
|
-
return(Qtrue);
|
858
|
-
} else if (TYPE(bool) == T_FALSE) {
|
859
|
-
xmlIndentTreeOutput = 0;
|
860
|
-
return(Qfalse);
|
861
|
-
} else {
|
862
|
-
rb_raise(rb_eArgError, "invalid argument, must be boolean");
|
863
|
-
}
|
864
|
-
}
|
865
|
-
|
866
|
-
|
867
|
-
/*
|
868
|
-
* call-seq:
|
869
|
-
* parser.io -> IO
|
870
|
-
*
|
871
|
-
* Obtain the IO instance this parser works with.
|
872
|
-
*/
|
873
|
-
VALUE
|
874
|
-
ruby_xml_parser_io_get(VALUE self, VALUE io) {
|
875
|
-
ruby_xml_parser *rxp;
|
876
|
-
rx_io_data *data;
|
877
|
-
|
878
|
-
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
879
|
-
|
880
|
-
if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL ||
|
881
|
-
rxp->data_type != RUBY_LIBXML_SRC_TYPE_IO ||
|
882
|
-
rxp->data == NULL)
|
883
|
-
return(Qnil);
|
884
|
-
|
885
|
-
data = (rx_io_data *)rxp->data;
|
886
|
-
|
887
|
-
return(data->io);
|
888
|
-
}
|
889
|
-
|
890
|
-
|
891
|
-
/*
|
892
|
-
* call-seq:
|
893
|
-
* parser.io = IO
|
894
|
-
*
|
895
|
-
* Set the IO instance this parser works with.
|
896
|
-
*/
|
897
|
-
VALUE
|
898
|
-
ruby_xml_parser_io_set(VALUE self, VALUE io) {
|
899
|
-
ruby_xml_parser *rxp;
|
900
|
-
ruby_xml_parser_context *rxpc;
|
901
|
-
rx_io_data *data;
|
902
|
-
OpenFile *fptr;
|
903
|
-
FILE *f;
|
904
|
-
|
905
|
-
#ifdef _WIN32
|
906
|
-
rb_raise(rb_eRuntimeError, "Setting an io buffer is not supported on Windows");
|
907
|
-
#endif
|
908
|
-
|
909
|
-
if (!rb_obj_is_kind_of(io, rb_cIO))
|
910
|
-
rb_raise(rb_eTypeError, "need an IO object");
|
911
|
-
|
912
|
-
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
913
|
-
|
914
|
-
if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
|
915
|
-
if (rxp->data != NULL)
|
916
|
-
rb_fatal("crap, this should be null");
|
917
|
-
|
918
|
-
rxp->data_type = RUBY_LIBXML_SRC_TYPE_IO;
|
919
|
-
data = ALLOC(rx_io_data);
|
920
|
-
rxp->data = data;
|
921
|
-
} else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_IO) {
|
922
|
-
return(Qnil);
|
923
|
-
}
|
924
|
-
|
925
|
-
rxp->ctxt = ruby_xml_parser_context_new();
|
926
|
-
data = (rx_io_data *)rxp->data;
|
927
|
-
data->io = io;
|
928
|
-
|
929
|
-
GetOpenFile(io, fptr);
|
930
|
-
rb_io_check_readable(fptr);
|
931
|
-
f = GetWriteFile(fptr);
|
932
|
-
|
933
|
-
Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
|
934
|
-
rxpc->ctxt = xmlCreateIOParserCtxt(NULL, NULL,
|
935
|
-
(xmlInputReadCallback) ctxtRead,
|
936
|
-
NULL, f, XML_CHAR_ENCODING_NONE);
|
937
|
-
if (!rxpc->ctxt)
|
938
|
-
rb_sys_fail(0);
|
939
|
-
|
940
|
-
return(data->io);
|
941
|
-
}
|
942
|
-
|
943
|
-
|
944
|
-
void
|
945
|
-
ruby_xml_parser_mark(ruby_xml_parser *rxp) {
|
946
|
-
if (rxp == NULL) return;
|
947
|
-
if (!NIL_P(rxp->ctxt))
|
948
|
-
rb_gc_mark(rxp->ctxt);
|
949
|
-
|
950
|
-
rb_gc_mark(LIBXML_STATE);
|
951
|
-
|
952
|
-
switch(rxp->data_type) {
|
953
|
-
case RUBY_LIBXML_SRC_TYPE_NULL:
|
954
|
-
break;
|
955
|
-
case RUBY_LIBXML_SRC_TYPE_FILE:
|
956
|
-
if (!NIL_P(((rx_file_data *)rxp->data)->filename))
|
957
|
-
rb_gc_mark(((rx_file_data *)rxp->data)->filename);
|
958
|
-
break;
|
959
|
-
case RUBY_LIBXML_SRC_TYPE_STRING:
|
960
|
-
if (!NIL_P(((rx_string_data *)rxp->data)->str))
|
961
|
-
rb_gc_mark(((rx_string_data *)rxp->data)->str);
|
962
|
-
break;
|
963
|
-
case RUBY_LIBXML_SRC_TYPE_IO:
|
964
|
-
if (!NIL_P(((rx_io_data *)rxp->data)->io))
|
965
|
-
rb_gc_mark(((rx_io_data *)rxp->data)->io);
|
966
|
-
break;
|
967
|
-
default:
|
968
|
-
rb_fatal("unknown datatype: %d", rxp->data_type);
|
969
|
-
}
|
970
|
-
}
|
971
|
-
|
972
|
-
|
973
|
-
/*
|
974
|
-
* call-seq:
|
975
|
-
* XML::Parser.memory_dump -> (true|false)
|
976
|
-
*
|
977
|
-
* Perform a parser memory dump (requires memory debugging
|
978
|
-
* support in libxml).
|
979
|
-
*/
|
980
|
-
VALUE
|
981
|
-
ruby_xml_parser_memory_dump(VALUE self) {
|
982
|
-
#ifdef DEBUG_MEMORY_LOCATION
|
983
|
-
xmlMemoryDump();
|
984
|
-
return(Qtrue);
|
985
|
-
#else
|
986
|
-
rb_warn("libxml was compiled without memory debugging support");
|
987
|
-
return(Qfalse);
|
988
|
-
#endif
|
989
|
-
}
|
990
|
-
|
991
|
-
|
992
|
-
/*
|
993
|
-
* call-seq:
|
994
|
-
* XML::Parser.memory_used -> num_bytes
|
995
|
-
*
|
996
|
-
* Perform a parser memory dump (requires memory debugging
|
997
|
-
* support in libxml).
|
998
|
-
*/
|
999
|
-
VALUE
|
1000
|
-
ruby_xml_parser_memory_used(VALUE self) {
|
1001
|
-
#ifdef DEBUG_MEMORY_LOCATION
|
1002
|
-
return(INT2NUM(xmlMemUsed()));
|
1003
|
-
#else
|
1004
|
-
rb_warn("libxml was compiled without memory debugging support");
|
1005
|
-
return(Qfalse);
|
1006
|
-
#endif
|
1007
|
-
}
|
1008
|
-
|
1009
|
-
|
1010
|
-
/*
|
1011
|
-
* call-seq:
|
1012
|
-
* XML::Parser.new -> parser
|
1013
|
-
*
|
1014
|
-
* Create a new parser instance with no pre-determined source.
|
1015
|
-
*/
|
1016
|
-
VALUE
|
1017
|
-
ruby_xml_parser_new(VALUE class) {
|
1018
|
-
ruby_xml_parser *rxp;
|
1019
|
-
VALUE r;
|
1020
|
-
|
1021
|
-
r=Data_Make_Struct(class,
|
1022
|
-
ruby_xml_parser,
|
1023
|
-
ruby_xml_parser_mark,
|
1024
|
-
ruby_xml_parser_free,
|
1025
|
-
rxp);
|
1026
|
-
|
1027
|
-
rxp->ctxt = Qnil;
|
1028
|
-
rxp->data_type = RUBY_LIBXML_SRC_TYPE_NULL;
|
1029
|
-
rxp->data = NULL;
|
1030
|
-
rxp->parsed = 0;
|
1031
|
-
|
1032
|
-
return r;
|
1033
|
-
}
|
1034
|
-
|
1035
|
-
|
1036
|
-
/*
|
1037
|
-
* call-seq:
|
1038
|
-
* XML::Parser.file -> parser
|
1039
|
-
*
|
1040
|
-
* Create a new parser instance that will read the specified file.
|
1041
|
-
*/
|
1042
|
-
VALUE
|
1043
|
-
ruby_xml_parser_new_file(VALUE class, VALUE filename) {
|
1044
|
-
VALUE obj;
|
1045
|
-
ruby_xml_parser *rxp;
|
1046
|
-
rx_file_data *data;
|
1047
|
-
|
1048
|
-
obj = ruby_xml_parser_new(class);
|
1049
|
-
Data_Get_Struct(obj, ruby_xml_parser, rxp);
|
1050
|
-
|
1051
|
-
data = ALLOC(rx_file_data);
|
1052
|
-
rxp->data_type = RUBY_LIBXML_SRC_TYPE_FILE;
|
1053
|
-
rxp->data = data;
|
1054
|
-
|
1055
|
-
ruby_xml_parser_filename_set(obj, filename);
|
1056
|
-
|
1057
|
-
return(obj);
|
1058
|
-
}
|
1059
|
-
|
1060
|
-
|
1061
|
-
/*
|
1062
|
-
* call-seq:
|
1063
|
-
* XML::Parser.io -> parser
|
1064
|
-
*
|
1065
|
-
* Create a new parser instance that will read from the
|
1066
|
-
* specified IO object.
|
1067
|
-
*/
|
1068
|
-
VALUE
|
1069
|
-
ruby_xml_parser_new_io(VALUE class, VALUE io) {
|
1070
|
-
VALUE obj;
|
1071
|
-
ruby_xml_parser *rxp;
|
1072
|
-
rx_io_data *data;
|
1073
|
-
|
1074
|
-
obj = ruby_xml_parser_new(class);
|
1075
|
-
Data_Get_Struct(obj, ruby_xml_parser, rxp);
|
1076
|
-
|
1077
|
-
data = ALLOC(rx_io_data);
|
1078
|
-
rxp->data_type = RUBY_LIBXML_SRC_TYPE_IO;
|
1079
|
-
rxp->data = data;
|
1080
|
-
|
1081
|
-
ruby_xml_parser_io_set(obj, io);
|
1082
|
-
|
1083
|
-
return(obj);
|
1084
|
-
}
|
1085
|
-
|
1086
|
-
|
1087
|
-
/*
|
1088
|
-
* call-seq:
|
1089
|
-
* XML::Parser.string -> parser
|
1090
|
-
*
|
1091
|
-
* Create a new parser instance that will parse the given
|
1092
|
-
* string.
|
1093
|
-
*/
|
1094
|
-
VALUE
|
1095
|
-
ruby_xml_parser_new_string(VALUE class, VALUE str) {
|
1096
|
-
VALUE obj;
|
1097
|
-
ruby_xml_parser *rxp;
|
1098
|
-
rx_string_data *data;
|
1099
|
-
|
1100
|
-
obj = ruby_xml_parser_new(class);
|
1101
|
-
Data_Get_Struct(obj, ruby_xml_parser, rxp);
|
1102
|
-
|
1103
|
-
data = ALLOC(rx_string_data);
|
1104
|
-
rxp->data_type = RUBY_LIBXML_SRC_TYPE_STRING;
|
1105
|
-
rxp->data = data;
|
1106
|
-
|
1107
|
-
ruby_xml_parser_str_set(obj, str);
|
1108
|
-
|
1109
|
-
return(obj);
|
1110
|
-
}
|
1111
|
-
|
1112
|
-
|
1113
|
-
/*
|
1114
|
-
* call-seq:
|
1115
|
-
* parser.parse -> document
|
1116
|
-
*
|
1117
|
-
* Parse the input XML and create an XML::Document with
|
1118
|
-
* it's content. If an error occurs, XML::Parser::ParseError
|
1119
|
-
* is thrown.
|
1120
|
-
*/
|
1121
|
-
VALUE
|
1122
|
-
ruby_xml_parser_parse(VALUE self) {
|
1123
|
-
ruby_xml_parser *rxp;
|
1124
|
-
ruby_xml_parser_context *rxpc;
|
1125
|
-
xmlDocPtr xdp;
|
1126
|
-
VALUE doc;
|
1127
|
-
|
1128
|
-
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
1129
|
-
|
1130
|
-
switch (rxp->data_type) {
|
1131
|
-
case RUBY_LIBXML_SRC_TYPE_NULL:
|
1132
|
-
return(Qnil);
|
1133
|
-
case RUBY_LIBXML_SRC_TYPE_STRING:
|
1134
|
-
case RUBY_LIBXML_SRC_TYPE_FILE:
|
1135
|
-
case RUBY_LIBXML_SRC_TYPE_IO:
|
1136
|
-
Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
|
1137
|
-
if (xmlParseDocument(rxpc->ctxt) == -1) {
|
1138
|
-
xmlFreeDoc(rxpc->ctxt->myDoc);
|
1139
|
-
rb_raise(eXMLParserParseError, "Document didn't parse");
|
1140
|
-
}
|
1141
|
-
|
1142
|
-
xdp = rxpc->ctxt->myDoc;
|
1143
|
-
if (!rxpc->ctxt->wellFormed) {
|
1144
|
-
xmlFreeDoc(xdp);
|
1145
|
-
xdp = NULL;
|
1146
|
-
rb_raise(eXMLParserParseError, "Document did not contain well-formed XML");
|
1147
|
-
} else {
|
1148
|
-
rxp->parsed = 1;
|
1149
|
-
}
|
1150
|
-
|
1151
|
-
doc = ruby_xml_document_wrap(xdp);
|
1152
|
-
break;
|
1153
|
-
default:
|
1154
|
-
rb_fatal("Unknown data type, %d", rxp->data_type);
|
1155
|
-
}
|
1156
|
-
|
1157
|
-
return(doc);
|
1158
|
-
}
|
1159
|
-
|
1160
|
-
|
1161
|
-
/*
|
1162
|
-
* call-seq:
|
1163
|
-
* parser.context -> context
|
1164
|
-
*
|
1165
|
-
* Obtain the XML::Parser::Context associated with this
|
1166
|
-
* parser.
|
1167
|
-
*/
|
1168
|
-
VALUE
|
1169
|
-
ruby_xml_parser_context_get(VALUE self) {
|
1170
|
-
ruby_xml_parser *rxp;
|
1171
|
-
|
1172
|
-
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
1173
|
-
if (rxp->ctxt == Qnil)
|
1174
|
-
return(Qnil);
|
1175
|
-
else
|
1176
|
-
return(rxp->ctxt);
|
1177
|
-
}
|
1178
|
-
|
1179
|
-
|
1180
|
-
/*
|
1181
|
-
* call-seq:
|
1182
|
-
* parser.string -> "string"
|
1183
|
-
*
|
1184
|
-
* Obtain the string this parser works with.
|
1185
|
-
*/
|
1186
|
-
VALUE
|
1187
|
-
ruby_xml_parser_str_get(VALUE self) {
|
1188
|
-
ruby_xml_parser *rxp;
|
1189
|
-
rx_string_data *data;
|
1190
|
-
|
1191
|
-
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
1192
|
-
if (rxp->data == NULL || rxp->data_type != RUBY_LIBXML_SRC_TYPE_STRING)
|
1193
|
-
return(Qnil);
|
1194
|
-
|
1195
|
-
data = (rx_string_data *)rxp->data;
|
1196
|
-
return(data->str);
|
1197
|
-
}
|
1198
|
-
|
1199
|
-
|
1200
|
-
/*
|
1201
|
-
* call-seq:
|
1202
|
-
* parser.string = "string"
|
1203
|
-
*
|
1204
|
-
* Set the string this parser works with.
|
1205
|
-
*/
|
1206
|
-
VALUE
|
1207
|
-
ruby_xml_parser_str_set(VALUE self, VALUE str) {
|
1208
|
-
ruby_xml_parser *rxp;
|
1209
|
-
ruby_xml_parser_context *rxpc;
|
1210
|
-
rx_string_data *data;
|
1211
|
-
|
1212
|
-
Check_Type(str, T_STRING);
|
1213
|
-
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
1214
|
-
|
1215
|
-
if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
|
1216
|
-
rxp->data_type = RUBY_LIBXML_SRC_TYPE_STRING;
|
1217
|
-
data = ALLOC(rx_string_data);
|
1218
|
-
rxp->data = data;
|
1219
|
-
} else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_STRING) {
|
1220
|
-
return(Qnil);
|
1221
|
-
}
|
1222
|
-
|
1223
|
-
rxp->ctxt = ruby_xml_parser_context_new();
|
1224
|
-
data = (rx_string_data *)rxp->data;
|
1225
|
-
data->str = str;
|
1226
|
-
|
1227
|
-
Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
|
1228
|
-
rxpc->ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(data->str), RSTRING_LEN(data->str));
|
1229
|
-
if ( rxpc->ctxt == NULL )
|
1230
|
-
rb_raise(eXMLParserParseError,"Cannot initialize parser with given string (maybe empty?)");
|
1231
|
-
|
1232
|
-
return(data->str);
|
1233
|
-
}
|
1234
|
-
|
1235
|
-
static void
|
1236
|
-
libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg, ...)
|
1237
|
-
{
|
1238
|
-
VALUE message;
|
1239
|
-
va_list ap;
|
1240
|
-
char str[1000];
|
1241
|
-
|
1242
|
-
va_start(ap, msg);
|
1243
|
-
if (vsnprintf(str, 999, msg, ap) >= 998) str[999] = 0;
|
1244
|
-
va_end(ap);
|
1245
|
-
|
1246
|
-
message = rb_str_new2(str);
|
1247
|
-
rb_funcall(cXMLParser, rb_intern("xml_error_func_handler"), 1, message);
|
1248
|
-
}
|
1249
|
-
|
1250
|
-
/* #define RUBY_XML_PARSER_ENABLED_INIT(func, method) \
|
1251
|
-
rb_define_singleton_method(cXMLParser, method, \
|
1252
|
-
ruby_xml_parser_enabled_##func##_q, 0); */
|
1253
|
-
|
1254
|
-
///#include "cbg.c"
|
1255
|
-
///
|
1256
|
-
///VALUE ruby_register_deb(VALUE self) {
|
1257
|
-
/// deb_register_cbg();
|
1258
|
-
/// return(Qtrue);
|
1259
|
-
///}
|
1260
|
-
|
1261
|
-
// Rdoc needs to know
|
1262
|
-
#ifdef RDOC_NEVER_DEFINED
|
1263
|
-
mLibXML = rb_define_module("LibXML");
|
1264
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
1265
|
-
#endif
|
1266
|
-
|
1267
|
-
void
|
1268
|
-
ruby_init_parser(void) {
|
1269
|
-
cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
|
1270
|
-
eXMLParserParseError = rb_define_class_under(cXMLParser, "ParseError",
|
1271
|
-
rb_eRuntimeError);
|
1272
|
-
|
1273
|
-
/* Constants */
|
1274
|
-
rb_define_const(cXMLParser, "LIBXML_VERSION",
|
1275
|
-
rb_str_new2(LIBXML_DOTTED_VERSION));
|
1276
|
-
rb_define_const(cXMLParser, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
|
1277
|
-
rb_define_const(cXMLParser, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
|
1278
|
-
|
1279
|
-
/* Question-esqe Class Methods */
|
1280
|
-
/* RDoc won't have them defined by a macro... */
|
1281
|
-
rb_define_singleton_method(cXMLParser, "enabled_automata?",
|
1282
|
-
ruby_xml_parser_enabled_automata_q, 0);
|
1283
|
-
rb_define_singleton_method(cXMLParser, "enabled_c14n?",
|
1284
|
-
ruby_xml_parser_enabled_c14n_q, 0);
|
1285
|
-
rb_define_singleton_method(cXMLParser, "enabled_catalog?",
|
1286
|
-
ruby_xml_parser_enabled_catalog_q, 0);
|
1287
|
-
rb_define_singleton_method(cXMLParser, "enabled_debug?",
|
1288
|
-
ruby_xml_parser_enabled_debug_q, 0);
|
1289
|
-
rb_define_singleton_method(cXMLParser, "enabled_docbook?",
|
1290
|
-
ruby_xml_parser_enabled_docbook_q, 0);
|
1291
|
-
rb_define_singleton_method(cXMLParser, "enabled_ftp?",
|
1292
|
-
ruby_xml_parser_enabled_ftp_q, 0);
|
1293
|
-
rb_define_singleton_method(cXMLParser, "enabled_http?",
|
1294
|
-
ruby_xml_parser_enabled_http_q, 0);
|
1295
|
-
rb_define_singleton_method(cXMLParser, "enabled_html?",
|
1296
|
-
ruby_xml_parser_enabled_html_q, 0);
|
1297
|
-
rb_define_singleton_method(cXMLParser, "enabled_iconv?",
|
1298
|
-
ruby_xml_parser_enabled_iconv_q, 0);
|
1299
|
-
rb_define_singleton_method(cXMLParser, "enabled_memory_debug?",
|
1300
|
-
ruby_xml_parser_enabled_memory_debug_location_q, 0);
|
1301
|
-
rb_define_singleton_method(cXMLParser, "enabled_regexp?",
|
1302
|
-
ruby_xml_parser_enabled_regexp_q, 0);
|
1303
|
-
rb_define_singleton_method(cXMLParser, "enabled_schemas?",
|
1304
|
-
ruby_xml_parser_enabled_schemas_q, 0);
|
1305
|
-
rb_define_singleton_method(cXMLParser, "enabled_thread?",
|
1306
|
-
ruby_xml_parser_enabled_thread_q, 0);
|
1307
|
-
rb_define_singleton_method(cXMLParser, "enabled_unicode?",
|
1308
|
-
ruby_xml_parser_enabled_unicode_q, 0);
|
1309
|
-
rb_define_singleton_method(cXMLParser, "enabled_xinclude?",
|
1310
|
-
ruby_xml_parser_enabled_xinclude_q, 0);
|
1311
|
-
rb_define_singleton_method(cXMLParser, "enabled_xpath?",
|
1312
|
-
ruby_xml_parser_enabled_xpath_q, 0);
|
1313
|
-
rb_define_singleton_method(cXMLParser, "enabled_xpointer?",
|
1314
|
-
ruby_xml_parser_enabled_xpointer_q, 0);
|
1315
|
-
rb_define_singleton_method(cXMLParser, "enabled_zlib?",
|
1316
|
-
ruby_xml_parser_enabled_zlib_q, 0);
|
1317
|
-
|
1318
|
-
/* Other Class Methods */
|
1319
|
-
/// rb_define_singleton_method(cXMLParser, "register_deb",
|
1320
|
-
/// ruby_register_deb, 0);
|
1321
|
-
|
1322
|
-
// TODO Maybe a set of 'xxxx_catalog' aliases might be more Ruby?
|
1323
|
-
rb_define_singleton_method(cXMLParser, "catalog_dump",
|
1324
|
-
ruby_xml_parser_catalog_dump, 0);
|
1325
|
-
rb_define_singleton_method(cXMLParser, "catalog_remove",
|
1326
|
-
ruby_xml_parser_catalog_remove, 1);
|
1327
|
-
rb_define_singleton_method(cXMLParser, "check_lib_versions",
|
1328
|
-
ruby_xml_parser_check_lib_versions, 0);
|
1329
|
-
|
1330
|
-
// TODO should this be debug_entities_q / debug_entities_set?
|
1331
|
-
// should all these default attribute pairs work that way?
|
1332
|
-
rb_define_singleton_method(cXMLParser, "debug_entities",
|
1333
|
-
ruby_xml_parser_debug_entities_get, 0);
|
1334
|
-
rb_define_singleton_method(cXMLParser, "debug_entities=",
|
1335
|
-
ruby_xml_parser_debug_entities_set, 1);
|
1336
|
-
rb_define_singleton_method(cXMLParser, "default_compression",
|
1337
|
-
ruby_xml_parser_default_compression_get, 0);
|
1338
|
-
rb_define_singleton_method(cXMLParser, "default_compression=",
|
1339
|
-
ruby_xml_parser_default_compression_set, 1);
|
1340
|
-
rb_define_singleton_method(cXMLParser, "default_keep_blanks",
|
1341
|
-
ruby_xml_parser_default_keep_blanks_get, 0);
|
1342
|
-
rb_define_singleton_method(cXMLParser, "default_keep_blanks=",
|
1343
|
-
ruby_xml_parser_default_keep_blanks_set, 1);
|
1344
|
-
rb_define_singleton_method(cXMLParser, "default_load_external_dtd",
|
1345
|
-
ruby_xml_parser_default_load_external_dtd_get, 0);
|
1346
|
-
rb_define_singleton_method(cXMLParser, "default_load_external_dtd=",
|
1347
|
-
ruby_xml_parser_default_load_external_dtd_set, 1);
|
1348
|
-
rb_define_singleton_method(cXMLParser, "default_line_numbers",
|
1349
|
-
ruby_xml_parser_default_line_numbers_get, 0);
|
1350
|
-
rb_define_singleton_method(cXMLParser, "default_line_numbers=",
|
1351
|
-
ruby_xml_parser_default_line_numbers_set, 1);
|
1352
|
-
rb_define_singleton_method(cXMLParser, "default_pedantic_parser",
|
1353
|
-
ruby_xml_parser_default_pedantic_parser_get, 0);
|
1354
|
-
rb_define_singleton_method(cXMLParser, "default_pedantic_parser=",
|
1355
|
-
ruby_xml_parser_default_pedantic_parser_set, 1);
|
1356
|
-
rb_define_singleton_method(cXMLParser, "default_substitute_entities",
|
1357
|
-
ruby_xml_parser_default_substitute_entities_get, 0);
|
1358
|
-
rb_define_singleton_method(cXMLParser, "default_substitute_entities=",
|
1359
|
-
ruby_xml_parser_default_substitute_entities_set, 1);
|
1360
|
-
rb_define_singleton_method(cXMLParser, "default_tree_indent_string",
|
1361
|
-
ruby_xml_parser_default_tree_indent_string_get, 0);
|
1362
|
-
rb_define_singleton_method(cXMLParser, "default_tree_indent_string=",
|
1363
|
-
ruby_xml_parser_default_tree_indent_string_set, 1);
|
1364
|
-
rb_define_singleton_method(cXMLParser, "default_validity_checking",
|
1365
|
-
ruby_xml_parser_default_validity_checking_get, 0);
|
1366
|
-
rb_define_singleton_method(cXMLParser, "default_validity_checking=",
|
1367
|
-
ruby_xml_parser_default_validity_checking_set, 1);
|
1368
|
-
rb_define_singleton_method(cXMLParser, "default_warnings",
|
1369
|
-
ruby_xml_parser_default_warnings_get, 0);
|
1370
|
-
rb_define_singleton_method(cXMLParser, "default_warnings=",
|
1371
|
-
ruby_xml_parser_default_warnings_set, 1);
|
1372
|
-
|
1373
|
-
rb_define_singleton_method(cXMLParser, "features", ruby_xml_parser_features, 0);
|
1374
|
-
rb_define_singleton_method(cXMLParser, "file", ruby_xml_parser_new_file, 1);
|
1375
|
-
rb_define_singleton_method(cXMLParser, "indent_tree_output", ruby_xml_parser_indent_tree_output_get, 0);
|
1376
|
-
rb_define_singleton_method(cXMLParser, "indent_tree_output=", ruby_xml_parser_indent_tree_output_set, 1);
|
1377
|
-
rb_define_singleton_method(cXMLParser, "io", ruby_xml_parser_new_io, 1);
|
1378
|
-
rb_define_singleton_method(cXMLParser, "memory_dump",
|
1379
|
-
ruby_xml_parser_memory_dump, 0);
|
1380
|
-
rb_define_singleton_method(cXMLParser, "memory_used",
|
1381
|
-
ruby_xml_parser_memory_used, 0);
|
1382
|
-
rb_define_singleton_method(cXMLParser, "new", ruby_xml_parser_new, 0);
|
1383
|
-
rb_define_singleton_method(cXMLParser, "string", ruby_xml_parser_new_string, 1);
|
1384
|
-
rb_define_method(cXMLParser, "filename", ruby_xml_parser_filename_get, 0);
|
1385
|
-
rb_define_method(cXMLParser, "filename=", ruby_xml_parser_filename_set, 1);
|
1386
|
-
rb_define_method(cXMLParser, "io", ruby_xml_parser_io_get, 0);
|
1387
|
-
rb_define_method(cXMLParser, "io=", ruby_xml_parser_io_set, 1);
|
1388
|
-
rb_define_method(cXMLParser, "parse", ruby_xml_parser_parse, 0);
|
1389
|
-
rb_define_method(cXMLParser, "context", ruby_xml_parser_context_get, 0);
|
1390
|
-
rb_define_method(cXMLParser, "string", ruby_xml_parser_str_get, 0);
|
1391
|
-
rb_define_method(cXMLParser, "string=", ruby_xml_parser_str_set, 1);
|
1392
|
-
|
1393
|
-
// set up error handling
|
1394
|
-
xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
|
1395
|
-
xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
|
1396
|
-
|
1397
|
-
id_call = rb_intern("call");
|
1398
|
-
}
|
1
|
+
/* $Id: ruby_xml_parser.c 461 2008-07-15 21:35:56Z 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
|
+
static int id_call;
|
9
|
+
|
10
|
+
VALUE cXMLParser;
|
11
|
+
VALUE eXMLParserParseError;
|
12
|
+
|
13
|
+
static int
|
14
|
+
ctxtRead(FILE *f, char * buf, size_t len) {
|
15
|
+
return(fread(buf, 1, len, f));
|
16
|
+
}
|
17
|
+
|
18
|
+
/*
|
19
|
+
* call-seq:
|
20
|
+
* XML::Parser.catalog_dump -> true
|
21
|
+
*
|
22
|
+
* Dump the parser resource catalogs to stdout.
|
23
|
+
*/
|
24
|
+
VALUE
|
25
|
+
ruby_xml_parser_catalog_dump(VALUE self) {
|
26
|
+
xmlCatalogDump(stdout);
|
27
|
+
return(Qtrue);
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
/*
|
32
|
+
* call-seq:
|
33
|
+
* XML::Parser.catalog_remove(catalog) -> true
|
34
|
+
*
|
35
|
+
* Remove the specified resource catalog.
|
36
|
+
*/
|
37
|
+
VALUE
|
38
|
+
ruby_xml_parser_catalog_remove(VALUE self, VALUE cat) {
|
39
|
+
Check_Type(cat, T_STRING);
|
40
|
+
xmlCatalogRemove((xmlChar *)StringValuePtr(cat));
|
41
|
+
return(Qtrue);
|
42
|
+
}
|
43
|
+
|
44
|
+
|
45
|
+
/*
|
46
|
+
* call-seq:
|
47
|
+
* XML::Parser.check_lib_versions -> true
|
48
|
+
*
|
49
|
+
* Check LIBXML version matches version the bindings
|
50
|
+
* were compiled to. Throws an exception if not.
|
51
|
+
*/
|
52
|
+
VALUE
|
53
|
+
ruby_xml_parser_check_lib_versions(VALUE class) {
|
54
|
+
xmlCheckVersion(LIBXML_VERSION);
|
55
|
+
return(Qtrue);
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
/*
|
60
|
+
* call-seq:
|
61
|
+
* XML::Parser.enabled_automata? -> (true|false)
|
62
|
+
*
|
63
|
+
* Determine whether libxml regexp automata support is enabled.
|
64
|
+
*/
|
65
|
+
VALUE
|
66
|
+
ruby_xml_parser_enabled_automata_q(VALUE class) {
|
67
|
+
#ifdef LIBXML_AUTOMATA_ENABLED
|
68
|
+
return(Qtrue);
|
69
|
+
#else
|
70
|
+
return(Qfalse);
|
71
|
+
#endif
|
72
|
+
}
|
73
|
+
|
74
|
+
|
75
|
+
/*
|
76
|
+
* call-seq:
|
77
|
+
* XML::Parser.enabled_c14n? -> (true|false)
|
78
|
+
*
|
79
|
+
* Determine whether libxml 'canonical XML' support is enabled.
|
80
|
+
* See "Canonical XML" (http://www.w3.org/TR/xml-c14n)
|
81
|
+
*/
|
82
|
+
VALUE
|
83
|
+
ruby_xml_parser_enabled_c14n_q(VALUE class) {
|
84
|
+
#ifdef LIBXML_C14N_ENABLED
|
85
|
+
return(Qtrue);
|
86
|
+
#else
|
87
|
+
return(Qfalse);
|
88
|
+
#endif
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
/*
|
93
|
+
* call-seq:
|
94
|
+
* XML::Parser.enabled_catalog? -> (true|false)
|
95
|
+
*
|
96
|
+
* Determine whether libxml resource catalog support is enabled.
|
97
|
+
*/
|
98
|
+
VALUE
|
99
|
+
ruby_xml_parser_enabled_catalog_q(VALUE class) {
|
100
|
+
#ifdef LIBXML_CATALOG_ENABLED
|
101
|
+
return(Qtrue);
|
102
|
+
#else
|
103
|
+
return(Qfalse);
|
104
|
+
#endif
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
/*
|
109
|
+
* call-seq:
|
110
|
+
* XML::Parser.enabled_debug? -> (true|false)
|
111
|
+
*
|
112
|
+
* Determine whether libxml debugging support is enabled.
|
113
|
+
*/
|
114
|
+
VALUE
|
115
|
+
ruby_xml_parser_enabled_debug_q(VALUE class) {
|
116
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
117
|
+
return(Qtrue);
|
118
|
+
#else
|
119
|
+
return(Qfalse);
|
120
|
+
#endif
|
121
|
+
}
|
122
|
+
|
123
|
+
|
124
|
+
/*
|
125
|
+
* call-seq:
|
126
|
+
* XML::Parser.enabled_docbook? -> (true|false)
|
127
|
+
*
|
128
|
+
* Determine whether libxml docbook support is enabled.
|
129
|
+
*/
|
130
|
+
VALUE
|
131
|
+
ruby_xml_parser_enabled_docbook_q(VALUE class) {
|
132
|
+
#ifdef LIBXML_DOCB_ENABLED
|
133
|
+
return(Qtrue);
|
134
|
+
#else
|
135
|
+
return(Qfalse);
|
136
|
+
#endif
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
/*
|
141
|
+
* call-seq:
|
142
|
+
* XML::Parser.enabled_ftp? -> (true|false)
|
143
|
+
*
|
144
|
+
* Determine whether libxml ftp client support is enabled.
|
145
|
+
*/
|
146
|
+
VALUE
|
147
|
+
ruby_xml_parser_enabled_ftp_q(VALUE class) {
|
148
|
+
#ifdef LIBXML_FTP_ENABLED
|
149
|
+
return(Qtrue);
|
150
|
+
#else
|
151
|
+
return(Qfalse);
|
152
|
+
#endif
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
/*
|
157
|
+
* call-seq:
|
158
|
+
* XML::Parser.enabled_http? -> (true|false)
|
159
|
+
*
|
160
|
+
* Determine whether libxml http client support is enabled.
|
161
|
+
*/
|
162
|
+
VALUE
|
163
|
+
ruby_xml_parser_enabled_http_q(VALUE class) {
|
164
|
+
#ifdef LIBXML_HTTP_ENABLED
|
165
|
+
return(Qtrue);
|
166
|
+
#else
|
167
|
+
return(Qfalse);
|
168
|
+
#endif
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
/*
|
173
|
+
* call-seq:
|
174
|
+
* XML::Parser.enabled_html? -> (true|false)
|
175
|
+
*
|
176
|
+
* Determine whether libxml html support is enabled.
|
177
|
+
*/
|
178
|
+
VALUE
|
179
|
+
ruby_xml_parser_enabled_html_q(VALUE class) {
|
180
|
+
#ifdef LIBXML_HTML_ENABLED
|
181
|
+
return(Qtrue);
|
182
|
+
#else
|
183
|
+
return(Qfalse);
|
184
|
+
#endif
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
/*
|
189
|
+
* call-seq:
|
190
|
+
* XML::Parser.enabled_iconv? -> (true|false)
|
191
|
+
*
|
192
|
+
* Determine whether libxml iconv support is enabled.
|
193
|
+
*/
|
194
|
+
VALUE
|
195
|
+
ruby_xml_parser_enabled_iconv_q(VALUE class) {
|
196
|
+
#ifdef LIBXML_ICONV_ENABLED
|
197
|
+
return(Qtrue);
|
198
|
+
#else
|
199
|
+
return(Qfalse);
|
200
|
+
#endif
|
201
|
+
}
|
202
|
+
|
203
|
+
|
204
|
+
/*
|
205
|
+
* call-seq:
|
206
|
+
* XML::Parser.enabled_memory_debug? -> (true|false)
|
207
|
+
*
|
208
|
+
* Determine whether libxml memory location debugging support
|
209
|
+
* is enabled.
|
210
|
+
*/
|
211
|
+
VALUE
|
212
|
+
ruby_xml_parser_enabled_memory_debug_location_q(VALUE class) {
|
213
|
+
#ifdef DEBUG_MEMORY_LOCATION
|
214
|
+
return(Qtrue);
|
215
|
+
#else
|
216
|
+
return(Qfalse);
|
217
|
+
#endif
|
218
|
+
}
|
219
|
+
|
220
|
+
|
221
|
+
/*
|
222
|
+
* call-seq:
|
223
|
+
* XML::Parser.enabled_regexp? -> (true|false)
|
224
|
+
*
|
225
|
+
* Determine whether libxml regular expression support is enabled.
|
226
|
+
*/
|
227
|
+
VALUE
|
228
|
+
ruby_xml_parser_enabled_regexp_q(VALUE class) {
|
229
|
+
#ifdef LIBXML_REGEXP_ENABLED
|
230
|
+
return(Qtrue);
|
231
|
+
#else
|
232
|
+
return(Qfalse);
|
233
|
+
#endif
|
234
|
+
}
|
235
|
+
|
236
|
+
|
237
|
+
/*
|
238
|
+
* call-seq:
|
239
|
+
* XML::Parser.enabled_schemas? -> (true|false)
|
240
|
+
*
|
241
|
+
* Determine whether libxml schema support is enabled.
|
242
|
+
*/
|
243
|
+
VALUE
|
244
|
+
ruby_xml_parser_enabled_schemas_q(VALUE class) {
|
245
|
+
#ifdef LIBXML_SCHEMAS_ENABLED
|
246
|
+
return(Qtrue);
|
247
|
+
#else
|
248
|
+
return(Qfalse);
|
249
|
+
#endif
|
250
|
+
}
|
251
|
+
|
252
|
+
|
253
|
+
/*
|
254
|
+
* call-seq:
|
255
|
+
* XML::Parser.enabled_thread? -> (true|false)
|
256
|
+
*
|
257
|
+
* Determine whether libxml thread-safe semantics support
|
258
|
+
* is enabled (I think?).
|
259
|
+
*/
|
260
|
+
VALUE
|
261
|
+
ruby_xml_parser_enabled_thread_q(VALUE class) {
|
262
|
+
#ifdef LIBXML_THREAD_ENABLED
|
263
|
+
return(Qtrue);
|
264
|
+
#else
|
265
|
+
return(Qfalse);
|
266
|
+
#endif
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
/*
|
271
|
+
* call-seq:
|
272
|
+
* XML::Parser.enabled_unicode? -> (true|false)
|
273
|
+
*
|
274
|
+
* Determine whether libxml unicode support is enabled.
|
275
|
+
*/
|
276
|
+
VALUE
|
277
|
+
ruby_xml_parser_enabled_unicode_q(VALUE class) {
|
278
|
+
#ifdef LIBXML_UNICODE_ENABLED
|
279
|
+
return(Qtrue);
|
280
|
+
#else
|
281
|
+
return(Qfalse);
|
282
|
+
#endif
|
283
|
+
}
|
284
|
+
|
285
|
+
|
286
|
+
/*
|
287
|
+
* call-seq:
|
288
|
+
* XML::Parser.enabled_xinclude? -> (true|false)
|
289
|
+
*
|
290
|
+
* Determine whether libxml xinclude support is enabled.
|
291
|
+
*/
|
292
|
+
VALUE
|
293
|
+
ruby_xml_parser_enabled_xinclude_q(VALUE class) {
|
294
|
+
#ifdef LIBXML_XINCLUDE_ENABLED
|
295
|
+
return(Qtrue);
|
296
|
+
#else
|
297
|
+
return(Qfalse);
|
298
|
+
#endif
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
/*
|
303
|
+
* call-seq:
|
304
|
+
* XML::Parser.enabled_xpath? -> (true|false)
|
305
|
+
*
|
306
|
+
* Determine whether libxml xpath support is enabled.
|
307
|
+
*/
|
308
|
+
VALUE
|
309
|
+
ruby_xml_parser_enabled_xpath_q(VALUE class) {
|
310
|
+
#ifdef LIBXML_XPATH_ENABLED
|
311
|
+
return(Qtrue);
|
312
|
+
#else
|
313
|
+
return(Qfalse);
|
314
|
+
#endif
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
/*
|
319
|
+
* call-seq:
|
320
|
+
* XML::Parser.enabled_xpointer? -> (true|false)
|
321
|
+
*
|
322
|
+
* Determine whether libxml xpointer support is enabled.
|
323
|
+
*/
|
324
|
+
VALUE
|
325
|
+
ruby_xml_parser_enabled_xpointer_q(VALUE class) {
|
326
|
+
#ifdef LIBXML_XPTR_ENABLED
|
327
|
+
return(Qtrue);
|
328
|
+
#else
|
329
|
+
return(Qfalse);
|
330
|
+
#endif
|
331
|
+
}
|
332
|
+
|
333
|
+
|
334
|
+
/*
|
335
|
+
* call-seq:
|
336
|
+
* XML::Parser.enabled_zlib? -> (true|false)
|
337
|
+
*
|
338
|
+
* Determine whether libxml zlib support is enabled.
|
339
|
+
*/
|
340
|
+
VALUE
|
341
|
+
ruby_xml_parser_enabled_zlib_q(VALUE class) {
|
342
|
+
#ifdef HAVE_ZLIB_H
|
343
|
+
return(Qtrue);
|
344
|
+
#else
|
345
|
+
return(Qfalse);
|
346
|
+
#endif
|
347
|
+
}
|
348
|
+
|
349
|
+
|
350
|
+
/*
|
351
|
+
* call-seq:
|
352
|
+
* XML::Parser.debug_entities -> (true|false)
|
353
|
+
*
|
354
|
+
* Determine whether included-entity debugging is enabled.
|
355
|
+
* (Requires Libxml to be compiled with debugging support)
|
356
|
+
*/
|
357
|
+
VALUE
|
358
|
+
ruby_xml_parser_debug_entities_get(VALUE class) {
|
359
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
360
|
+
if (xmlParserDebugEntities)
|
361
|
+
return(Qtrue);
|
362
|
+
else
|
363
|
+
return(Qfalse);
|
364
|
+
#else
|
365
|
+
rb_warn("libxml was compiled with debugging turned off");
|
366
|
+
return(Qfalse);
|
367
|
+
#endif
|
368
|
+
}
|
369
|
+
|
370
|
+
|
371
|
+
/*
|
372
|
+
* call-seq:
|
373
|
+
* XML::Parser.debug_entities = true|false
|
374
|
+
*
|
375
|
+
* Enable or disable included-entity debugging.
|
376
|
+
* (Requires Libxml to be compiled with debugging support)
|
377
|
+
*/
|
378
|
+
VALUE
|
379
|
+
ruby_xml_parser_debug_entities_set(VALUE class, VALUE bool) {
|
380
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
381
|
+
if (TYPE(bool) == T_FALSE) {
|
382
|
+
xmlParserDebugEntities = 0;
|
383
|
+
return(Qfalse);
|
384
|
+
} else {
|
385
|
+
xmlParserDebugEntities = 1;
|
386
|
+
return(Qtrue);
|
387
|
+
}
|
388
|
+
#else
|
389
|
+
rb_warn("libxml was compiled with debugging turned off");
|
390
|
+
#endif
|
391
|
+
}
|
392
|
+
|
393
|
+
|
394
|
+
/*
|
395
|
+
* call-seq:
|
396
|
+
* XML::Parser.default_keep_blanks -> (true|false)
|
397
|
+
*
|
398
|
+
* Determine whether parsers retain whitespace by default.
|
399
|
+
*/
|
400
|
+
VALUE
|
401
|
+
ruby_xml_parser_default_keep_blanks_get(VALUE class) {
|
402
|
+
if (xmlKeepBlanksDefaultValue)
|
403
|
+
return(Qtrue);
|
404
|
+
else
|
405
|
+
return(Qfalse);
|
406
|
+
}
|
407
|
+
|
408
|
+
|
409
|
+
/*
|
410
|
+
* call-seq:
|
411
|
+
* XML::Parser.default_keep_blanks = true|false
|
412
|
+
*
|
413
|
+
* Controls whether parsers retain whitespace by default.
|
414
|
+
*/
|
415
|
+
VALUE
|
416
|
+
ruby_xml_parser_default_keep_blanks_set(VALUE class, VALUE bool) {
|
417
|
+
if (TYPE(bool) == T_FALSE) {
|
418
|
+
xmlKeepBlanksDefaultValue = 0;
|
419
|
+
return(Qfalse);
|
420
|
+
} else if (TYPE(bool) == T_TRUE) {
|
421
|
+
xmlKeepBlanksDefaultValue = 1;
|
422
|
+
return(Qtrue);
|
423
|
+
} else {
|
424
|
+
rb_raise(rb_eArgError, "invalid argument, must be a boolean");
|
425
|
+
}
|
426
|
+
}
|
427
|
+
|
428
|
+
|
429
|
+
/*
|
430
|
+
* call-seq:
|
431
|
+
* XML::Parser.default_load_external_dtd -> (true|false)
|
432
|
+
*
|
433
|
+
* Determine whether parsers load external DTDs by default.
|
434
|
+
*/
|
435
|
+
VALUE
|
436
|
+
ruby_xml_parser_default_load_external_dtd_get(VALUE class) {
|
437
|
+
if (xmlLoadExtDtdDefaultValue)
|
438
|
+
return(Qtrue);
|
439
|
+
else
|
440
|
+
return(Qfalse);
|
441
|
+
}
|
442
|
+
|
443
|
+
|
444
|
+
/*
|
445
|
+
* call-seq:
|
446
|
+
* XML::Parser.default_load_external_dtd = true|false
|
447
|
+
*
|
448
|
+
* Controls whether parsers load external DTDs by default.
|
449
|
+
*/
|
450
|
+
VALUE
|
451
|
+
ruby_xml_parser_default_load_external_dtd_set(VALUE class, VALUE bool) {
|
452
|
+
if (TYPE(bool) == T_FALSE) {
|
453
|
+
xmlLoadExtDtdDefaultValue = 0;
|
454
|
+
return(Qfalse);
|
455
|
+
} else {
|
456
|
+
xmlLoadExtDtdDefaultValue = 1;
|
457
|
+
return(Qtrue);
|
458
|
+
}
|
459
|
+
}
|
460
|
+
|
461
|
+
|
462
|
+
/*
|
463
|
+
* call-seq:
|
464
|
+
* XML::Parser.default_line_numbers -> (true|false)
|
465
|
+
*
|
466
|
+
* Determine whether parsers retain line-numbers by default.
|
467
|
+
*/
|
468
|
+
VALUE
|
469
|
+
ruby_xml_parser_default_line_numbers_get(VALUE class) {
|
470
|
+
if (xmlLineNumbersDefaultValue)
|
471
|
+
return(Qtrue);
|
472
|
+
else
|
473
|
+
return(Qfalse);
|
474
|
+
}
|
475
|
+
|
476
|
+
|
477
|
+
/*
|
478
|
+
* call-seq:
|
479
|
+
* XML::Parser.default_line_numbers = true|false
|
480
|
+
*
|
481
|
+
* Controls whether parsers retain line-numbers by default.
|
482
|
+
*/
|
483
|
+
VALUE
|
484
|
+
ruby_xml_parser_default_line_numbers_set(VALUE class, VALUE bool) {
|
485
|
+
if (TYPE(bool) == T_FALSE) {
|
486
|
+
xmlLineNumbersDefault(0);
|
487
|
+
return(Qfalse);
|
488
|
+
} else {
|
489
|
+
xmlLineNumbersDefault(1);
|
490
|
+
return(Qtrue);
|
491
|
+
}
|
492
|
+
}
|
493
|
+
|
494
|
+
|
495
|
+
/*
|
496
|
+
* call-seq:
|
497
|
+
* XML::Parser.default_pedantic_parser -> (true|false)
|
498
|
+
*
|
499
|
+
* Determine whether parsers are pedantic by default.
|
500
|
+
*/
|
501
|
+
VALUE
|
502
|
+
ruby_xml_parser_default_pedantic_parser_get(VALUE class) {
|
503
|
+
if (xmlPedanticParserDefaultValue)
|
504
|
+
return(Qtrue);
|
505
|
+
else
|
506
|
+
return(Qfalse);
|
507
|
+
}
|
508
|
+
|
509
|
+
|
510
|
+
/*
|
511
|
+
* call-seq:
|
512
|
+
* XML::Parser.default_pedantic_parser = true|false
|
513
|
+
*
|
514
|
+
* Controls whether parsers are pedantic by default.
|
515
|
+
*/
|
516
|
+
VALUE
|
517
|
+
ruby_xml_parser_default_pedantic_parser_set(VALUE class, VALUE bool) {
|
518
|
+
if (TYPE(bool) == T_FALSE) {
|
519
|
+
xmlPedanticParserDefault(0);
|
520
|
+
return(Qfalse);
|
521
|
+
} else {
|
522
|
+
xmlPedanticParserDefault(1);
|
523
|
+
return(Qtrue);
|
524
|
+
}
|
525
|
+
}
|
526
|
+
|
527
|
+
|
528
|
+
/*
|
529
|
+
* call-seq:
|
530
|
+
* XML::Parser.default_substitute_entities -> (true|false)
|
531
|
+
*
|
532
|
+
* Determine whether parsers perform inline entity substitution
|
533
|
+
* (for external entities) by default.
|
534
|
+
*/
|
535
|
+
VALUE
|
536
|
+
ruby_xml_parser_default_substitute_entities_get(VALUE class) {
|
537
|
+
if (xmlSubstituteEntitiesDefaultValue)
|
538
|
+
return(Qtrue);
|
539
|
+
else
|
540
|
+
return(Qfalse);
|
541
|
+
}
|
542
|
+
|
543
|
+
|
544
|
+
/*
|
545
|
+
* call-seq:
|
546
|
+
* XML::Parser.default_substitute_entities = true|false
|
547
|
+
*
|
548
|
+
* Controls whether parsers perform inline entity substitution
|
549
|
+
* (for external entities) by default.
|
550
|
+
*/
|
551
|
+
VALUE
|
552
|
+
ruby_xml_parser_default_substitute_entities_set(VALUE class, VALUE bool) {
|
553
|
+
if (TYPE(bool) == T_FALSE) {
|
554
|
+
xmlSubstituteEntitiesDefault(0);
|
555
|
+
return(Qfalse);
|
556
|
+
} else {
|
557
|
+
xmlSubstituteEntitiesDefault(1);
|
558
|
+
return(Qtrue);
|
559
|
+
}
|
560
|
+
}
|
561
|
+
|
562
|
+
|
563
|
+
/*
|
564
|
+
* call-seq:
|
565
|
+
* XML::Parser.default_tree_indent_string -> "string"
|
566
|
+
*
|
567
|
+
* Obtain the default string used by parsers to indent the XML tree
|
568
|
+
* for output.
|
569
|
+
*/
|
570
|
+
VALUE
|
571
|
+
ruby_xml_parser_default_tree_indent_string_get(VALUE class) {
|
572
|
+
if (xmlTreeIndentString == NULL)
|
573
|
+
return(Qnil);
|
574
|
+
else
|
575
|
+
return(rb_str_new2(xmlTreeIndentString));
|
576
|
+
}
|
577
|
+
|
578
|
+
|
579
|
+
/*
|
580
|
+
* call-seq:
|
581
|
+
* XML::Parser.default_tree_indent_string = "string"
|
582
|
+
*
|
583
|
+
* Set the default string used by parsers to indent the XML tree
|
584
|
+
* for output.
|
585
|
+
*/
|
586
|
+
VALUE
|
587
|
+
ruby_xml_parser_default_tree_indent_string_set(VALUE class, VALUE string) {
|
588
|
+
Check_Type(string, T_STRING);
|
589
|
+
xmlTreeIndentString = xmlStrdup(StringValuePtr(string));
|
590
|
+
return(string);
|
591
|
+
}
|
592
|
+
|
593
|
+
|
594
|
+
/*
|
595
|
+
* call-seq:
|
596
|
+
* XML::Parser.default_validity_checking -> (true|false)
|
597
|
+
*
|
598
|
+
* Determine whether parsers perform XML validation by default.
|
599
|
+
*/
|
600
|
+
VALUE
|
601
|
+
ruby_xml_parser_default_validity_checking_get(VALUE class) {
|
602
|
+
if (xmlDoValidityCheckingDefaultValue)
|
603
|
+
return(Qtrue);
|
604
|
+
else
|
605
|
+
return(Qfalse);
|
606
|
+
}
|
607
|
+
|
608
|
+
|
609
|
+
/*
|
610
|
+
* call-seq:
|
611
|
+
* XML::Parser.default_validity_checking = true|false
|
612
|
+
*
|
613
|
+
* Controls whether parsers perform XML validation by default.
|
614
|
+
*/
|
615
|
+
VALUE
|
616
|
+
ruby_xml_parser_default_validity_checking_set(VALUE class, VALUE bool) {
|
617
|
+
if (TYPE(bool) == T_FALSE) {
|
618
|
+
xmlDoValidityCheckingDefaultValue = 0;
|
619
|
+
return(Qfalse);
|
620
|
+
} else {
|
621
|
+
xmlDoValidityCheckingDefaultValue = 1;
|
622
|
+
return(Qtrue);
|
623
|
+
}
|
624
|
+
}
|
625
|
+
|
626
|
+
|
627
|
+
/*
|
628
|
+
* call-seq:
|
629
|
+
* XML::Parser.default_warnings -> (true|false)
|
630
|
+
*
|
631
|
+
* Determine whether parsers output warnings by default.
|
632
|
+
*/
|
633
|
+
VALUE
|
634
|
+
ruby_xml_parser_default_warnings_get(VALUE class) {
|
635
|
+
if (xmlGetWarningsDefaultValue)
|
636
|
+
return(Qtrue);
|
637
|
+
else
|
638
|
+
return(Qfalse);
|
639
|
+
}
|
640
|
+
|
641
|
+
|
642
|
+
/*
|
643
|
+
* call-seq:
|
644
|
+
* XML::Parser.default_warnings = true|false
|
645
|
+
*
|
646
|
+
* Controls whether parsers output warnings by default.
|
647
|
+
*/
|
648
|
+
VALUE
|
649
|
+
ruby_xml_parser_default_warnings_set(VALUE class, VALUE bool) {
|
650
|
+
if (TYPE(bool) == T_FALSE) {
|
651
|
+
xmlGetWarningsDefaultValue = 0;
|
652
|
+
return(Qfalse);
|
653
|
+
} else {
|
654
|
+
xmlGetWarningsDefaultValue = 1;
|
655
|
+
return(Qtrue);
|
656
|
+
}
|
657
|
+
}
|
658
|
+
|
659
|
+
|
660
|
+
/*
|
661
|
+
* call-seq:
|
662
|
+
* XML::Parser.default_compression -> (true|false)
|
663
|
+
*
|
664
|
+
* Determine whether parsers use Zlib compression by default
|
665
|
+
* (requires libxml to be compiled with Zlib support).
|
666
|
+
*/
|
667
|
+
VALUE
|
668
|
+
ruby_xml_parser_default_compression_get(VALUE class) {
|
669
|
+
#ifdef HAVE_ZLIB_H
|
670
|
+
return(INT2FIX(xmlGetCompressMode()));
|
671
|
+
#else
|
672
|
+
rb_warn("libxml was compiled without zlib support");
|
673
|
+
return(Qfalse);
|
674
|
+
#endif
|
675
|
+
}
|
676
|
+
|
677
|
+
|
678
|
+
/*
|
679
|
+
* call-seq:
|
680
|
+
* XML::Parser.default_compression = true|false
|
681
|
+
*
|
682
|
+
* Controls whether parsers use Zlib compression by default
|
683
|
+
* (requires libxml to be compiled with Zlib support).
|
684
|
+
*/
|
685
|
+
VALUE
|
686
|
+
ruby_xml_parser_default_compression_set(VALUE class, VALUE num) {
|
687
|
+
#ifdef HAVE_ZLIB_H
|
688
|
+
Check_Type(num, T_FIXNUM);
|
689
|
+
xmlSetCompressMode(FIX2INT(num));
|
690
|
+
return(num);
|
691
|
+
#else
|
692
|
+
rb_warn("libxml was compiled without zlib support");
|
693
|
+
return(Qfalse);
|
694
|
+
#endif
|
695
|
+
}
|
696
|
+
|
697
|
+
|
698
|
+
/*
|
699
|
+
* call-seq:
|
700
|
+
* XML::Parser.features -> ["feature", ..., "feature"]
|
701
|
+
*
|
702
|
+
* Obtains an array of strings representing features supported
|
703
|
+
* (and enabled) by the installed libxml.
|
704
|
+
*/
|
705
|
+
VALUE
|
706
|
+
ruby_xml_parser_features(VALUE class) {
|
707
|
+
VALUE arr, str;
|
708
|
+
int i, len = MAX_LIBXML_FEATURES_LEN;
|
709
|
+
char **list = NULL;
|
710
|
+
|
711
|
+
list = ALLOC_N(char *,MAX_LIBXML_FEATURES_LEN);
|
712
|
+
MEMZERO(list, char *, MAX_LIBXML_FEATURES_LEN);
|
713
|
+
|
714
|
+
arr = rb_ary_new();
|
715
|
+
if (xmlGetFeaturesList(&len, (const char **)list) == -1)
|
716
|
+
return Qnil;
|
717
|
+
|
718
|
+
for (i = 0; i < len; i++) {
|
719
|
+
str = rb_str_new2((const char *)list[i]);
|
720
|
+
rb_gc_unregister_address(&str);
|
721
|
+
rb_ary_push(arr, str);
|
722
|
+
}
|
723
|
+
|
724
|
+
if (len == MAX_LIBXML_FEATURES_LEN)
|
725
|
+
rb_warn("Please contact libxml-devel@rubyforge.org and ask to have the \"MAX_LIBXML_FEATURES_LEN increased\" because you could possibly be seeing an incomplete list");
|
726
|
+
|
727
|
+
ruby_xfree(list);
|
728
|
+
return(arr);
|
729
|
+
}
|
730
|
+
|
731
|
+
|
732
|
+
/*
|
733
|
+
* call-seq:
|
734
|
+
* parser.filename -> "filename"
|
735
|
+
*
|
736
|
+
* Obtain the filename this parser will read from.
|
737
|
+
*/
|
738
|
+
VALUE
|
739
|
+
ruby_xml_parser_filename_get(VALUE self) {
|
740
|
+
ruby_xml_parser *rxp;
|
741
|
+
rx_file_data *data;
|
742
|
+
|
743
|
+
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
744
|
+
if (rxp->data == NULL)
|
745
|
+
return(Qnil);
|
746
|
+
|
747
|
+
if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_FILE)
|
748
|
+
return(Qnil);
|
749
|
+
|
750
|
+
data = (rx_file_data *)rxp->data;
|
751
|
+
return(data->filename);
|
752
|
+
}
|
753
|
+
|
754
|
+
|
755
|
+
/*
|
756
|
+
* call-seq:
|
757
|
+
* parser.filename = "filename"
|
758
|
+
*
|
759
|
+
* Set the filename this parser will read from.
|
760
|
+
*/
|
761
|
+
VALUE
|
762
|
+
ruby_xml_parser_filename_set(VALUE self, VALUE filename) {
|
763
|
+
ruby_xml_parser *rxp;
|
764
|
+
ruby_xml_parser_context *rxpc;
|
765
|
+
rx_file_data *data;
|
766
|
+
int retry_count = 0;
|
767
|
+
|
768
|
+
Check_Type(filename, T_STRING);
|
769
|
+
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
770
|
+
|
771
|
+
if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
|
772
|
+
if (rxp->data != NULL)
|
773
|
+
rb_fatal("crap, this should be null");
|
774
|
+
|
775
|
+
rxp->data_type = RUBY_LIBXML_SRC_TYPE_FILE;
|
776
|
+
data = ALLOC(rx_file_data);
|
777
|
+
rxp->data = data;
|
778
|
+
} else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_FILE) {
|
779
|
+
return(Qnil);
|
780
|
+
}
|
781
|
+
|
782
|
+
rxp->ctxt = ruby_xml_parser_context_new();
|
783
|
+
data = (rx_file_data *)rxp->data;
|
784
|
+
data->filename = filename;
|
785
|
+
|
786
|
+
Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
|
787
|
+
retry:
|
788
|
+
rxpc->ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename));
|
789
|
+
if (rxpc->ctxt == NULL) {
|
790
|
+
if ((errno == EMFILE || errno == ENFILE) && retry_count == 0) {
|
791
|
+
retry_count++;
|
792
|
+
rb_gc();
|
793
|
+
goto retry;
|
794
|
+
} else {
|
795
|
+
rb_raise(rb_eIOError, StringValuePtr(filename));
|
796
|
+
}
|
797
|
+
}
|
798
|
+
|
799
|
+
return(data->filename);
|
800
|
+
}
|
801
|
+
|
802
|
+
|
803
|
+
void
|
804
|
+
ruby_xml_parser_free(ruby_xml_parser *rxp) {
|
805
|
+
void *data;
|
806
|
+
|
807
|
+
switch(rxp->data_type) {
|
808
|
+
case RUBY_LIBXML_SRC_TYPE_NULL:
|
809
|
+
break;
|
810
|
+
case RUBY_LIBXML_SRC_TYPE_FILE:
|
811
|
+
data = (void *)(rx_file_data *)rxp->data;
|
812
|
+
ruby_xfree((rx_file_data *)data);
|
813
|
+
break;
|
814
|
+
case RUBY_LIBXML_SRC_TYPE_STRING:
|
815
|
+
data = (void *)(rx_string_data *)rxp->data;
|
816
|
+
ruby_xfree((rx_string_data *)data);
|
817
|
+
break;
|
818
|
+
case RUBY_LIBXML_SRC_TYPE_IO:
|
819
|
+
data = (void *)(rx_io_data *)rxp->data;
|
820
|
+
ruby_xfree((rx_io_data *)data);
|
821
|
+
break;
|
822
|
+
default:
|
823
|
+
rb_fatal("Unknown data type, %d", rxp->data_type);
|
824
|
+
}
|
825
|
+
|
826
|
+
ruby_xfree(rxp);
|
827
|
+
}
|
828
|
+
|
829
|
+
|
830
|
+
/*
|
831
|
+
* call-seq:
|
832
|
+
* XML::Parser.indent_tree_output -> (true|false)
|
833
|
+
*
|
834
|
+
* Determines whether XML output will be indented
|
835
|
+
* (using the string supplied to +default_indent_tree_string+)
|
836
|
+
*/
|
837
|
+
VALUE
|
838
|
+
ruby_xml_parser_indent_tree_output_get(VALUE class) {
|
839
|
+
if (xmlIndentTreeOutput)
|
840
|
+
return(Qtrue);
|
841
|
+
else
|
842
|
+
return(Qfalse);
|
843
|
+
}
|
844
|
+
|
845
|
+
|
846
|
+
/*
|
847
|
+
* call-seq:
|
848
|
+
* XML::Parser.indent_tree_output = true|false
|
849
|
+
*
|
850
|
+
* Controls whether XML output will be indented
|
851
|
+
* (using the string supplied to +default_indent_tree_string+)
|
852
|
+
*/
|
853
|
+
VALUE
|
854
|
+
ruby_xml_parser_indent_tree_output_set(VALUE class, VALUE bool) {
|
855
|
+
if (TYPE(bool) == T_TRUE) {
|
856
|
+
xmlIndentTreeOutput = 1;
|
857
|
+
return(Qtrue);
|
858
|
+
} else if (TYPE(bool) == T_FALSE) {
|
859
|
+
xmlIndentTreeOutput = 0;
|
860
|
+
return(Qfalse);
|
861
|
+
} else {
|
862
|
+
rb_raise(rb_eArgError, "invalid argument, must be boolean");
|
863
|
+
}
|
864
|
+
}
|
865
|
+
|
866
|
+
|
867
|
+
/*
|
868
|
+
* call-seq:
|
869
|
+
* parser.io -> IO
|
870
|
+
*
|
871
|
+
* Obtain the IO instance this parser works with.
|
872
|
+
*/
|
873
|
+
VALUE
|
874
|
+
ruby_xml_parser_io_get(VALUE self, VALUE io) {
|
875
|
+
ruby_xml_parser *rxp;
|
876
|
+
rx_io_data *data;
|
877
|
+
|
878
|
+
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
879
|
+
|
880
|
+
if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL ||
|
881
|
+
rxp->data_type != RUBY_LIBXML_SRC_TYPE_IO ||
|
882
|
+
rxp->data == NULL)
|
883
|
+
return(Qnil);
|
884
|
+
|
885
|
+
data = (rx_io_data *)rxp->data;
|
886
|
+
|
887
|
+
return(data->io);
|
888
|
+
}
|
889
|
+
|
890
|
+
|
891
|
+
/*
|
892
|
+
* call-seq:
|
893
|
+
* parser.io = IO
|
894
|
+
*
|
895
|
+
* Set the IO instance this parser works with.
|
896
|
+
*/
|
897
|
+
VALUE
|
898
|
+
ruby_xml_parser_io_set(VALUE self, VALUE io) {
|
899
|
+
ruby_xml_parser *rxp;
|
900
|
+
ruby_xml_parser_context *rxpc;
|
901
|
+
rx_io_data *data;
|
902
|
+
OpenFile *fptr;
|
903
|
+
FILE *f;
|
904
|
+
|
905
|
+
#ifdef _WIN32
|
906
|
+
rb_raise(rb_eRuntimeError, "Setting an io buffer is not supported on Windows");
|
907
|
+
#endif
|
908
|
+
|
909
|
+
if (!rb_obj_is_kind_of(io, rb_cIO))
|
910
|
+
rb_raise(rb_eTypeError, "need an IO object");
|
911
|
+
|
912
|
+
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
913
|
+
|
914
|
+
if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
|
915
|
+
if (rxp->data != NULL)
|
916
|
+
rb_fatal("crap, this should be null");
|
917
|
+
|
918
|
+
rxp->data_type = RUBY_LIBXML_SRC_TYPE_IO;
|
919
|
+
data = ALLOC(rx_io_data);
|
920
|
+
rxp->data = data;
|
921
|
+
} else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_IO) {
|
922
|
+
return(Qnil);
|
923
|
+
}
|
924
|
+
|
925
|
+
rxp->ctxt = ruby_xml_parser_context_new();
|
926
|
+
data = (rx_io_data *)rxp->data;
|
927
|
+
data->io = io;
|
928
|
+
|
929
|
+
GetOpenFile(io, fptr);
|
930
|
+
rb_io_check_readable(fptr);
|
931
|
+
f = GetWriteFile(fptr);
|
932
|
+
|
933
|
+
Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
|
934
|
+
rxpc->ctxt = xmlCreateIOParserCtxt(NULL, NULL,
|
935
|
+
(xmlInputReadCallback) ctxtRead,
|
936
|
+
NULL, f, XML_CHAR_ENCODING_NONE);
|
937
|
+
if (!rxpc->ctxt)
|
938
|
+
rb_sys_fail(0);
|
939
|
+
|
940
|
+
return(data->io);
|
941
|
+
}
|
942
|
+
|
943
|
+
|
944
|
+
void
|
945
|
+
ruby_xml_parser_mark(ruby_xml_parser *rxp) {
|
946
|
+
if (rxp == NULL) return;
|
947
|
+
if (!NIL_P(rxp->ctxt))
|
948
|
+
rb_gc_mark(rxp->ctxt);
|
949
|
+
|
950
|
+
rb_gc_mark(LIBXML_STATE);
|
951
|
+
|
952
|
+
switch(rxp->data_type) {
|
953
|
+
case RUBY_LIBXML_SRC_TYPE_NULL:
|
954
|
+
break;
|
955
|
+
case RUBY_LIBXML_SRC_TYPE_FILE:
|
956
|
+
if (!NIL_P(((rx_file_data *)rxp->data)->filename))
|
957
|
+
rb_gc_mark(((rx_file_data *)rxp->data)->filename);
|
958
|
+
break;
|
959
|
+
case RUBY_LIBXML_SRC_TYPE_STRING:
|
960
|
+
if (!NIL_P(((rx_string_data *)rxp->data)->str))
|
961
|
+
rb_gc_mark(((rx_string_data *)rxp->data)->str);
|
962
|
+
break;
|
963
|
+
case RUBY_LIBXML_SRC_TYPE_IO:
|
964
|
+
if (!NIL_P(((rx_io_data *)rxp->data)->io))
|
965
|
+
rb_gc_mark(((rx_io_data *)rxp->data)->io);
|
966
|
+
break;
|
967
|
+
default:
|
968
|
+
rb_fatal("unknown datatype: %d", rxp->data_type);
|
969
|
+
}
|
970
|
+
}
|
971
|
+
|
972
|
+
|
973
|
+
/*
|
974
|
+
* call-seq:
|
975
|
+
* XML::Parser.memory_dump -> (true|false)
|
976
|
+
*
|
977
|
+
* Perform a parser memory dump (requires memory debugging
|
978
|
+
* support in libxml).
|
979
|
+
*/
|
980
|
+
VALUE
|
981
|
+
ruby_xml_parser_memory_dump(VALUE self) {
|
982
|
+
#ifdef DEBUG_MEMORY_LOCATION
|
983
|
+
xmlMemoryDump();
|
984
|
+
return(Qtrue);
|
985
|
+
#else
|
986
|
+
rb_warn("libxml was compiled without memory debugging support");
|
987
|
+
return(Qfalse);
|
988
|
+
#endif
|
989
|
+
}
|
990
|
+
|
991
|
+
|
992
|
+
/*
|
993
|
+
* call-seq:
|
994
|
+
* XML::Parser.memory_used -> num_bytes
|
995
|
+
*
|
996
|
+
* Perform a parser memory dump (requires memory debugging
|
997
|
+
* support in libxml).
|
998
|
+
*/
|
999
|
+
VALUE
|
1000
|
+
ruby_xml_parser_memory_used(VALUE self) {
|
1001
|
+
#ifdef DEBUG_MEMORY_LOCATION
|
1002
|
+
return(INT2NUM(xmlMemUsed()));
|
1003
|
+
#else
|
1004
|
+
rb_warn("libxml was compiled without memory debugging support");
|
1005
|
+
return(Qfalse);
|
1006
|
+
#endif
|
1007
|
+
}
|
1008
|
+
|
1009
|
+
|
1010
|
+
/*
|
1011
|
+
* call-seq:
|
1012
|
+
* XML::Parser.new -> parser
|
1013
|
+
*
|
1014
|
+
* Create a new parser instance with no pre-determined source.
|
1015
|
+
*/
|
1016
|
+
VALUE
|
1017
|
+
ruby_xml_parser_new(VALUE class) {
|
1018
|
+
ruby_xml_parser *rxp;
|
1019
|
+
VALUE r;
|
1020
|
+
|
1021
|
+
r=Data_Make_Struct(class,
|
1022
|
+
ruby_xml_parser,
|
1023
|
+
ruby_xml_parser_mark,
|
1024
|
+
ruby_xml_parser_free,
|
1025
|
+
rxp);
|
1026
|
+
|
1027
|
+
rxp->ctxt = Qnil;
|
1028
|
+
rxp->data_type = RUBY_LIBXML_SRC_TYPE_NULL;
|
1029
|
+
rxp->data = NULL;
|
1030
|
+
rxp->parsed = 0;
|
1031
|
+
|
1032
|
+
return r;
|
1033
|
+
}
|
1034
|
+
|
1035
|
+
|
1036
|
+
/*
|
1037
|
+
* call-seq:
|
1038
|
+
* XML::Parser.file -> parser
|
1039
|
+
*
|
1040
|
+
* Create a new parser instance that will read the specified file.
|
1041
|
+
*/
|
1042
|
+
VALUE
|
1043
|
+
ruby_xml_parser_new_file(VALUE class, VALUE filename) {
|
1044
|
+
VALUE obj;
|
1045
|
+
ruby_xml_parser *rxp;
|
1046
|
+
rx_file_data *data;
|
1047
|
+
|
1048
|
+
obj = ruby_xml_parser_new(class);
|
1049
|
+
Data_Get_Struct(obj, ruby_xml_parser, rxp);
|
1050
|
+
|
1051
|
+
data = ALLOC(rx_file_data);
|
1052
|
+
rxp->data_type = RUBY_LIBXML_SRC_TYPE_FILE;
|
1053
|
+
rxp->data = data;
|
1054
|
+
|
1055
|
+
ruby_xml_parser_filename_set(obj, filename);
|
1056
|
+
|
1057
|
+
return(obj);
|
1058
|
+
}
|
1059
|
+
|
1060
|
+
|
1061
|
+
/*
|
1062
|
+
* call-seq:
|
1063
|
+
* XML::Parser.io -> parser
|
1064
|
+
*
|
1065
|
+
* Create a new parser instance that will read from the
|
1066
|
+
* specified IO object.
|
1067
|
+
*/
|
1068
|
+
VALUE
|
1069
|
+
ruby_xml_parser_new_io(VALUE class, VALUE io) {
|
1070
|
+
VALUE obj;
|
1071
|
+
ruby_xml_parser *rxp;
|
1072
|
+
rx_io_data *data;
|
1073
|
+
|
1074
|
+
obj = ruby_xml_parser_new(class);
|
1075
|
+
Data_Get_Struct(obj, ruby_xml_parser, rxp);
|
1076
|
+
|
1077
|
+
data = ALLOC(rx_io_data);
|
1078
|
+
rxp->data_type = RUBY_LIBXML_SRC_TYPE_IO;
|
1079
|
+
rxp->data = data;
|
1080
|
+
|
1081
|
+
ruby_xml_parser_io_set(obj, io);
|
1082
|
+
|
1083
|
+
return(obj);
|
1084
|
+
}
|
1085
|
+
|
1086
|
+
|
1087
|
+
/*
|
1088
|
+
* call-seq:
|
1089
|
+
* XML::Parser.string -> parser
|
1090
|
+
*
|
1091
|
+
* Create a new parser instance that will parse the given
|
1092
|
+
* string.
|
1093
|
+
*/
|
1094
|
+
VALUE
|
1095
|
+
ruby_xml_parser_new_string(VALUE class, VALUE str) {
|
1096
|
+
VALUE obj;
|
1097
|
+
ruby_xml_parser *rxp;
|
1098
|
+
rx_string_data *data;
|
1099
|
+
|
1100
|
+
obj = ruby_xml_parser_new(class);
|
1101
|
+
Data_Get_Struct(obj, ruby_xml_parser, rxp);
|
1102
|
+
|
1103
|
+
data = ALLOC(rx_string_data);
|
1104
|
+
rxp->data_type = RUBY_LIBXML_SRC_TYPE_STRING;
|
1105
|
+
rxp->data = data;
|
1106
|
+
|
1107
|
+
ruby_xml_parser_str_set(obj, str);
|
1108
|
+
|
1109
|
+
return(obj);
|
1110
|
+
}
|
1111
|
+
|
1112
|
+
|
1113
|
+
/*
|
1114
|
+
* call-seq:
|
1115
|
+
* parser.parse -> document
|
1116
|
+
*
|
1117
|
+
* Parse the input XML and create an XML::Document with
|
1118
|
+
* it's content. If an error occurs, XML::Parser::ParseError
|
1119
|
+
* is thrown.
|
1120
|
+
*/
|
1121
|
+
VALUE
|
1122
|
+
ruby_xml_parser_parse(VALUE self) {
|
1123
|
+
ruby_xml_parser *rxp;
|
1124
|
+
ruby_xml_parser_context *rxpc;
|
1125
|
+
xmlDocPtr xdp;
|
1126
|
+
VALUE doc;
|
1127
|
+
|
1128
|
+
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
1129
|
+
|
1130
|
+
switch (rxp->data_type) {
|
1131
|
+
case RUBY_LIBXML_SRC_TYPE_NULL:
|
1132
|
+
return(Qnil);
|
1133
|
+
case RUBY_LIBXML_SRC_TYPE_STRING:
|
1134
|
+
case RUBY_LIBXML_SRC_TYPE_FILE:
|
1135
|
+
case RUBY_LIBXML_SRC_TYPE_IO:
|
1136
|
+
Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
|
1137
|
+
if (xmlParseDocument(rxpc->ctxt) == -1) {
|
1138
|
+
xmlFreeDoc(rxpc->ctxt->myDoc);
|
1139
|
+
rb_raise(eXMLParserParseError, "Document didn't parse");
|
1140
|
+
}
|
1141
|
+
|
1142
|
+
xdp = rxpc->ctxt->myDoc;
|
1143
|
+
if (!rxpc->ctxt->wellFormed) {
|
1144
|
+
xmlFreeDoc(xdp);
|
1145
|
+
xdp = NULL;
|
1146
|
+
rb_raise(eXMLParserParseError, "Document did not contain well-formed XML");
|
1147
|
+
} else {
|
1148
|
+
rxp->parsed = 1;
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
doc = ruby_xml_document_wrap(xdp);
|
1152
|
+
break;
|
1153
|
+
default:
|
1154
|
+
rb_fatal("Unknown data type, %d", rxp->data_type);
|
1155
|
+
}
|
1156
|
+
|
1157
|
+
return(doc);
|
1158
|
+
}
|
1159
|
+
|
1160
|
+
|
1161
|
+
/*
|
1162
|
+
* call-seq:
|
1163
|
+
* parser.context -> context
|
1164
|
+
*
|
1165
|
+
* Obtain the XML::Parser::Context associated with this
|
1166
|
+
* parser.
|
1167
|
+
*/
|
1168
|
+
VALUE
|
1169
|
+
ruby_xml_parser_context_get(VALUE self) {
|
1170
|
+
ruby_xml_parser *rxp;
|
1171
|
+
|
1172
|
+
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
1173
|
+
if (rxp->ctxt == Qnil)
|
1174
|
+
return(Qnil);
|
1175
|
+
else
|
1176
|
+
return(rxp->ctxt);
|
1177
|
+
}
|
1178
|
+
|
1179
|
+
|
1180
|
+
/*
|
1181
|
+
* call-seq:
|
1182
|
+
* parser.string -> "string"
|
1183
|
+
*
|
1184
|
+
* Obtain the string this parser works with.
|
1185
|
+
*/
|
1186
|
+
VALUE
|
1187
|
+
ruby_xml_parser_str_get(VALUE self) {
|
1188
|
+
ruby_xml_parser *rxp;
|
1189
|
+
rx_string_data *data;
|
1190
|
+
|
1191
|
+
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
1192
|
+
if (rxp->data == NULL || rxp->data_type != RUBY_LIBXML_SRC_TYPE_STRING)
|
1193
|
+
return(Qnil);
|
1194
|
+
|
1195
|
+
data = (rx_string_data *)rxp->data;
|
1196
|
+
return(data->str);
|
1197
|
+
}
|
1198
|
+
|
1199
|
+
|
1200
|
+
/*
|
1201
|
+
* call-seq:
|
1202
|
+
* parser.string = "string"
|
1203
|
+
*
|
1204
|
+
* Set the string this parser works with.
|
1205
|
+
*/
|
1206
|
+
VALUE
|
1207
|
+
ruby_xml_parser_str_set(VALUE self, VALUE str) {
|
1208
|
+
ruby_xml_parser *rxp;
|
1209
|
+
ruby_xml_parser_context *rxpc;
|
1210
|
+
rx_string_data *data;
|
1211
|
+
|
1212
|
+
Check_Type(str, T_STRING);
|
1213
|
+
Data_Get_Struct(self, ruby_xml_parser, rxp);
|
1214
|
+
|
1215
|
+
if (rxp->data_type == RUBY_LIBXML_SRC_TYPE_NULL) {
|
1216
|
+
rxp->data_type = RUBY_LIBXML_SRC_TYPE_STRING;
|
1217
|
+
data = ALLOC(rx_string_data);
|
1218
|
+
rxp->data = data;
|
1219
|
+
} else if (rxp->data_type != RUBY_LIBXML_SRC_TYPE_STRING) {
|
1220
|
+
return(Qnil);
|
1221
|
+
}
|
1222
|
+
|
1223
|
+
rxp->ctxt = ruby_xml_parser_context_new();
|
1224
|
+
data = (rx_string_data *)rxp->data;
|
1225
|
+
data->str = str;
|
1226
|
+
|
1227
|
+
Data_Get_Struct(rxp->ctxt, ruby_xml_parser_context, rxpc);
|
1228
|
+
rxpc->ctxt = xmlCreateMemoryParserCtxt(StringValuePtr(data->str), RSTRING_LEN(data->str));
|
1229
|
+
if ( rxpc->ctxt == NULL )
|
1230
|
+
rb_raise(eXMLParserParseError,"Cannot initialize parser with given string (maybe empty?)");
|
1231
|
+
|
1232
|
+
return(data->str);
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
static void
|
1236
|
+
libxml_xmlErrorFuncHandler(ATTRIBUTE_UNUSED void *ctx, const char *msg, ...)
|
1237
|
+
{
|
1238
|
+
VALUE message;
|
1239
|
+
va_list ap;
|
1240
|
+
char str[1000];
|
1241
|
+
|
1242
|
+
va_start(ap, msg);
|
1243
|
+
if (vsnprintf(str, 999, msg, ap) >= 998) str[999] = 0;
|
1244
|
+
va_end(ap);
|
1245
|
+
|
1246
|
+
message = rb_str_new2(str);
|
1247
|
+
rb_funcall(cXMLParser, rb_intern("xml_error_func_handler"), 1, message);
|
1248
|
+
}
|
1249
|
+
|
1250
|
+
/* #define RUBY_XML_PARSER_ENABLED_INIT(func, method) \
|
1251
|
+
rb_define_singleton_method(cXMLParser, method, \
|
1252
|
+
ruby_xml_parser_enabled_##func##_q, 0); */
|
1253
|
+
|
1254
|
+
///#include "cbg.c"
|
1255
|
+
///
|
1256
|
+
///VALUE ruby_register_deb(VALUE self) {
|
1257
|
+
/// deb_register_cbg();
|
1258
|
+
/// return(Qtrue);
|
1259
|
+
///}
|
1260
|
+
|
1261
|
+
// Rdoc needs to know
|
1262
|
+
#ifdef RDOC_NEVER_DEFINED
|
1263
|
+
mLibXML = rb_define_module("LibXML");
|
1264
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
1265
|
+
#endif
|
1266
|
+
|
1267
|
+
void
|
1268
|
+
ruby_init_parser(void) {
|
1269
|
+
cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
|
1270
|
+
eXMLParserParseError = rb_define_class_under(cXMLParser, "ParseError",
|
1271
|
+
rb_eRuntimeError);
|
1272
|
+
|
1273
|
+
/* Constants */
|
1274
|
+
rb_define_const(cXMLParser, "LIBXML_VERSION",
|
1275
|
+
rb_str_new2(LIBXML_DOTTED_VERSION));
|
1276
|
+
rb_define_const(cXMLParser, "VERSION", rb_str_new2(RUBY_LIBXML_VERSION));
|
1277
|
+
rb_define_const(cXMLParser, "VERNUM", INT2NUM(RUBY_LIBXML_VERNUM));
|
1278
|
+
|
1279
|
+
/* Question-esqe Class Methods */
|
1280
|
+
/* RDoc won't have them defined by a macro... */
|
1281
|
+
rb_define_singleton_method(cXMLParser, "enabled_automata?",
|
1282
|
+
ruby_xml_parser_enabled_automata_q, 0);
|
1283
|
+
rb_define_singleton_method(cXMLParser, "enabled_c14n?",
|
1284
|
+
ruby_xml_parser_enabled_c14n_q, 0);
|
1285
|
+
rb_define_singleton_method(cXMLParser, "enabled_catalog?",
|
1286
|
+
ruby_xml_parser_enabled_catalog_q, 0);
|
1287
|
+
rb_define_singleton_method(cXMLParser, "enabled_debug?",
|
1288
|
+
ruby_xml_parser_enabled_debug_q, 0);
|
1289
|
+
rb_define_singleton_method(cXMLParser, "enabled_docbook?",
|
1290
|
+
ruby_xml_parser_enabled_docbook_q, 0);
|
1291
|
+
rb_define_singleton_method(cXMLParser, "enabled_ftp?",
|
1292
|
+
ruby_xml_parser_enabled_ftp_q, 0);
|
1293
|
+
rb_define_singleton_method(cXMLParser, "enabled_http?",
|
1294
|
+
ruby_xml_parser_enabled_http_q, 0);
|
1295
|
+
rb_define_singleton_method(cXMLParser, "enabled_html?",
|
1296
|
+
ruby_xml_parser_enabled_html_q, 0);
|
1297
|
+
rb_define_singleton_method(cXMLParser, "enabled_iconv?",
|
1298
|
+
ruby_xml_parser_enabled_iconv_q, 0);
|
1299
|
+
rb_define_singleton_method(cXMLParser, "enabled_memory_debug?",
|
1300
|
+
ruby_xml_parser_enabled_memory_debug_location_q, 0);
|
1301
|
+
rb_define_singleton_method(cXMLParser, "enabled_regexp?",
|
1302
|
+
ruby_xml_parser_enabled_regexp_q, 0);
|
1303
|
+
rb_define_singleton_method(cXMLParser, "enabled_schemas?",
|
1304
|
+
ruby_xml_parser_enabled_schemas_q, 0);
|
1305
|
+
rb_define_singleton_method(cXMLParser, "enabled_thread?",
|
1306
|
+
ruby_xml_parser_enabled_thread_q, 0);
|
1307
|
+
rb_define_singleton_method(cXMLParser, "enabled_unicode?",
|
1308
|
+
ruby_xml_parser_enabled_unicode_q, 0);
|
1309
|
+
rb_define_singleton_method(cXMLParser, "enabled_xinclude?",
|
1310
|
+
ruby_xml_parser_enabled_xinclude_q, 0);
|
1311
|
+
rb_define_singleton_method(cXMLParser, "enabled_xpath?",
|
1312
|
+
ruby_xml_parser_enabled_xpath_q, 0);
|
1313
|
+
rb_define_singleton_method(cXMLParser, "enabled_xpointer?",
|
1314
|
+
ruby_xml_parser_enabled_xpointer_q, 0);
|
1315
|
+
rb_define_singleton_method(cXMLParser, "enabled_zlib?",
|
1316
|
+
ruby_xml_parser_enabled_zlib_q, 0);
|
1317
|
+
|
1318
|
+
/* Other Class Methods */
|
1319
|
+
/// rb_define_singleton_method(cXMLParser, "register_deb",
|
1320
|
+
/// ruby_register_deb, 0);
|
1321
|
+
|
1322
|
+
// TODO Maybe a set of 'xxxx_catalog' aliases might be more Ruby?
|
1323
|
+
rb_define_singleton_method(cXMLParser, "catalog_dump",
|
1324
|
+
ruby_xml_parser_catalog_dump, 0);
|
1325
|
+
rb_define_singleton_method(cXMLParser, "catalog_remove",
|
1326
|
+
ruby_xml_parser_catalog_remove, 1);
|
1327
|
+
rb_define_singleton_method(cXMLParser, "check_lib_versions",
|
1328
|
+
ruby_xml_parser_check_lib_versions, 0);
|
1329
|
+
|
1330
|
+
// TODO should this be debug_entities_q / debug_entities_set?
|
1331
|
+
// should all these default attribute pairs work that way?
|
1332
|
+
rb_define_singleton_method(cXMLParser, "debug_entities",
|
1333
|
+
ruby_xml_parser_debug_entities_get, 0);
|
1334
|
+
rb_define_singleton_method(cXMLParser, "debug_entities=",
|
1335
|
+
ruby_xml_parser_debug_entities_set, 1);
|
1336
|
+
rb_define_singleton_method(cXMLParser, "default_compression",
|
1337
|
+
ruby_xml_parser_default_compression_get, 0);
|
1338
|
+
rb_define_singleton_method(cXMLParser, "default_compression=",
|
1339
|
+
ruby_xml_parser_default_compression_set, 1);
|
1340
|
+
rb_define_singleton_method(cXMLParser, "default_keep_blanks",
|
1341
|
+
ruby_xml_parser_default_keep_blanks_get, 0);
|
1342
|
+
rb_define_singleton_method(cXMLParser, "default_keep_blanks=",
|
1343
|
+
ruby_xml_parser_default_keep_blanks_set, 1);
|
1344
|
+
rb_define_singleton_method(cXMLParser, "default_load_external_dtd",
|
1345
|
+
ruby_xml_parser_default_load_external_dtd_get, 0);
|
1346
|
+
rb_define_singleton_method(cXMLParser, "default_load_external_dtd=",
|
1347
|
+
ruby_xml_parser_default_load_external_dtd_set, 1);
|
1348
|
+
rb_define_singleton_method(cXMLParser, "default_line_numbers",
|
1349
|
+
ruby_xml_parser_default_line_numbers_get, 0);
|
1350
|
+
rb_define_singleton_method(cXMLParser, "default_line_numbers=",
|
1351
|
+
ruby_xml_parser_default_line_numbers_set, 1);
|
1352
|
+
rb_define_singleton_method(cXMLParser, "default_pedantic_parser",
|
1353
|
+
ruby_xml_parser_default_pedantic_parser_get, 0);
|
1354
|
+
rb_define_singleton_method(cXMLParser, "default_pedantic_parser=",
|
1355
|
+
ruby_xml_parser_default_pedantic_parser_set, 1);
|
1356
|
+
rb_define_singleton_method(cXMLParser, "default_substitute_entities",
|
1357
|
+
ruby_xml_parser_default_substitute_entities_get, 0);
|
1358
|
+
rb_define_singleton_method(cXMLParser, "default_substitute_entities=",
|
1359
|
+
ruby_xml_parser_default_substitute_entities_set, 1);
|
1360
|
+
rb_define_singleton_method(cXMLParser, "default_tree_indent_string",
|
1361
|
+
ruby_xml_parser_default_tree_indent_string_get, 0);
|
1362
|
+
rb_define_singleton_method(cXMLParser, "default_tree_indent_string=",
|
1363
|
+
ruby_xml_parser_default_tree_indent_string_set, 1);
|
1364
|
+
rb_define_singleton_method(cXMLParser, "default_validity_checking",
|
1365
|
+
ruby_xml_parser_default_validity_checking_get, 0);
|
1366
|
+
rb_define_singleton_method(cXMLParser, "default_validity_checking=",
|
1367
|
+
ruby_xml_parser_default_validity_checking_set, 1);
|
1368
|
+
rb_define_singleton_method(cXMLParser, "default_warnings",
|
1369
|
+
ruby_xml_parser_default_warnings_get, 0);
|
1370
|
+
rb_define_singleton_method(cXMLParser, "default_warnings=",
|
1371
|
+
ruby_xml_parser_default_warnings_set, 1);
|
1372
|
+
|
1373
|
+
rb_define_singleton_method(cXMLParser, "features", ruby_xml_parser_features, 0);
|
1374
|
+
rb_define_singleton_method(cXMLParser, "file", ruby_xml_parser_new_file, 1);
|
1375
|
+
rb_define_singleton_method(cXMLParser, "indent_tree_output", ruby_xml_parser_indent_tree_output_get, 0);
|
1376
|
+
rb_define_singleton_method(cXMLParser, "indent_tree_output=", ruby_xml_parser_indent_tree_output_set, 1);
|
1377
|
+
rb_define_singleton_method(cXMLParser, "io", ruby_xml_parser_new_io, 1);
|
1378
|
+
rb_define_singleton_method(cXMLParser, "memory_dump",
|
1379
|
+
ruby_xml_parser_memory_dump, 0);
|
1380
|
+
rb_define_singleton_method(cXMLParser, "memory_used",
|
1381
|
+
ruby_xml_parser_memory_used, 0);
|
1382
|
+
rb_define_singleton_method(cXMLParser, "new", ruby_xml_parser_new, 0);
|
1383
|
+
rb_define_singleton_method(cXMLParser, "string", ruby_xml_parser_new_string, 1);
|
1384
|
+
rb_define_method(cXMLParser, "filename", ruby_xml_parser_filename_get, 0);
|
1385
|
+
rb_define_method(cXMLParser, "filename=", ruby_xml_parser_filename_set, 1);
|
1386
|
+
rb_define_method(cXMLParser, "io", ruby_xml_parser_io_get, 0);
|
1387
|
+
rb_define_method(cXMLParser, "io=", ruby_xml_parser_io_set, 1);
|
1388
|
+
rb_define_method(cXMLParser, "parse", ruby_xml_parser_parse, 0);
|
1389
|
+
rb_define_method(cXMLParser, "context", ruby_xml_parser_context_get, 0);
|
1390
|
+
rb_define_method(cXMLParser, "string", ruby_xml_parser_str_get, 0);
|
1391
|
+
rb_define_method(cXMLParser, "string=", ruby_xml_parser_str_set, 1);
|
1392
|
+
|
1393
|
+
// set up error handling
|
1394
|
+
xmlSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
|
1395
|
+
xmlThrDefSetGenericErrorFunc(NULL, libxml_xmlErrorFuncHandler);
|
1396
|
+
|
1397
|
+
id_call = rb_intern("call");
|
1398
|
+
}
|