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