libxml-ruby 0.9.5-x86-mswin32-60 → 0.9.6-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/CHANGES +28 -0
  2. data/README +8 -12
  3. data/ext/libxml/cbg.c +86 -86
  4. data/ext/libxml/libxml.c +875 -899
  5. data/ext/libxml/ruby_libxml.h +91 -65
  6. data/ext/libxml/ruby_xml_attr.c +485 -485
  7. data/ext/libxml/ruby_xml_attr.h +3 -3
  8. data/ext/libxml/ruby_xml_attributes.h +2 -2
  9. data/ext/libxml/ruby_xml_document.c +124 -307
  10. data/ext/libxml/ruby_xml_document.h +3 -3
  11. data/ext/libxml/ruby_xml_dtd.c +119 -119
  12. data/ext/libxml/ruby_xml_dtd.h +2 -2
  13. data/ext/libxml/ruby_xml_error.c +1 -1
  14. data/ext/libxml/ruby_xml_error.h +2 -2
  15. data/ext/libxml/ruby_xml_html_parser.c +119 -119
  16. data/ext/libxml/ruby_xml_html_parser.h +3 -3
  17. data/ext/libxml/ruby_xml_input.c +13 -11
  18. data/ext/libxml/ruby_xml_input.h +3 -3
  19. data/ext/libxml/ruby_xml_input_cbg.c +197 -197
  20. data/ext/libxml/ruby_xml_namespace.c +158 -0
  21. data/ext/libxml/ruby_xml_namespace.h +12 -0
  22. data/ext/libxml/ruby_xml_namespaces.c +303 -0
  23. data/ext/libxml/{ruby_xml_ns.h → ruby_xml_namespaces.h} +4 -5
  24. data/ext/libxml/ruby_xml_node.c +88 -293
  25. data/ext/libxml/ruby_xml_node.h +4 -4
  26. data/ext/libxml/ruby_xml_parser.c +152 -152
  27. data/ext/libxml/ruby_xml_parser.h +3 -3
  28. data/ext/libxml/ruby_xml_parser_context.c +630 -657
  29. data/ext/libxml/ruby_xml_parser_context.h +3 -3
  30. data/ext/libxml/ruby_xml_reader.c +899 -904
  31. data/ext/libxml/ruby_xml_reader.h +2 -2
  32. data/ext/libxml/ruby_xml_relaxng.h +2 -2
  33. data/ext/libxml/ruby_xml_sax_parser.c +175 -175
  34. data/ext/libxml/ruby_xml_sax_parser.h +3 -3
  35. data/ext/libxml/ruby_xml_schema.c +165 -165
  36. data/ext/libxml/ruby_xml_schema.h +2 -2
  37. data/ext/libxml/ruby_xml_state.h +2 -2
  38. data/ext/libxml/ruby_xml_xinclude.c +24 -24
  39. data/ext/libxml/ruby_xml_xinclude.h +3 -3
  40. data/ext/libxml/ruby_xml_xpath.c +108 -108
  41. data/ext/libxml/ruby_xml_xpath.h +3 -3
  42. data/ext/libxml/ruby_xml_xpath_context.c +84 -35
  43. data/ext/libxml/ruby_xml_xpath_context.h +3 -3
  44. data/ext/libxml/ruby_xml_xpath_expression.c +5 -7
  45. data/ext/libxml/ruby_xml_xpath_expression.h +2 -2
  46. data/ext/libxml/ruby_xml_xpath_object.c +7 -7
  47. data/ext/libxml/ruby_xml_xpath_object.h +2 -2
  48. data/ext/libxml/ruby_xml_xpointer.c +107 -107
  49. data/ext/libxml/ruby_xml_xpointer.h +3 -3
  50. data/ext/libxml/version.h +2 -2
  51. data/ext/mingw/libxml_ruby.dll.a +0 -0
  52. data/ext/mingw/libxml_ruby.so +0 -0
  53. data/ext/vc/libxml_ruby.vcproj +13 -5
  54. data/lib/libxml.rb +4 -1
  55. data/lib/libxml/document.rb +40 -6
  56. data/lib/libxml/hpricot.rb +76 -76
  57. data/lib/libxml/namespace.rb +60 -0
  58. data/lib/libxml/namespaces.rb +36 -0
  59. data/lib/libxml/node.rb +90 -26
  60. data/lib/libxml/ns.rb +20 -0
  61. data/test/model/bands.xml +5 -0
  62. data/test/tc_attributes.rb +1 -1
  63. data/test/tc_document.rb +24 -41
  64. data/test/tc_document_write.rb +87 -115
  65. data/test/tc_namespace.rb +59 -0
  66. data/test/tc_namespaces.rb +174 -0
  67. data/test/tc_node.rb +41 -33
  68. data/test/tc_node_copy.rb +1 -1
  69. data/test/tc_node_edit.rb +6 -0
  70. data/test/tc_node_write.rb +76 -0
  71. data/test/tc_xinclude.rb +2 -9
  72. data/test/tc_xpath.rb +38 -11
  73. data/test/test_suite.rb +3 -1
  74. metadata +16 -9
  75. data/ext/libxml/ruby_xml_ns.c +0 -150
  76. data/test/ets_copy_bug.rb +0 -21
  77. data/test/ets_copy_bug3.rb +0 -38
  78. data/test/model/default_validation_bug.rb +0 -0
  79. data/test/tc_ns.rb +0 -18
@@ -1,14 +1,14 @@
1
- /* $Id: ruby_xml_node.h 649 2008-11-30 03:15:57Z cfis $ */
1
+ /* $Id: ruby_xml_node.h 666 2008-12-07 00:16:50Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
5
- #ifndef __rxml_NODE__
6
- #define __rxml_NODE__
5
+ #ifndef __RXML_NODE__
6
+ #define __RXML_NODE__
7
7
 
8
8
  extern VALUE cXMLNode;
9
9
 
10
10
  void ruby_init_xml_node(void);
11
11
  void rxml_node_mark_common(xmlNodePtr xnode);
12
- VALUE rxml_node_wrap(VALUE class, xmlNodePtr xnode);
12
+ VALUE rxml_node_wrap(VALUE klass, xmlNodePtr xnode);
13
13
  VALUE check_string_or_symbol(VALUE val);
14
14
  #endif
@@ -1,152 +1,152 @@
1
- /* $Id: ruby_xml_parser.c 650 2008-11-30 03:40:22Z 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
- VALUE cXMLParser;
9
- static ID INPUT_ATTR;
10
- static ID CONTEXT_ATTR;
11
-
12
- /*
13
- * Document-class: LibXML::XML::Parser
14
- *
15
- * The XML::Parser provides a tree based API for processing
16
- * xml documents, in contract to XML::Reader's stream
17
- * based api and XML::SaxParser callback based API.
18
- *
19
- * As a result, parsing a document creates an in-memory document object
20
- * that consist of any number of XML::Node instances. This is simple
21
- * and powerful model, but has the major limitation that the size of
22
- * the document that can be processed is limited by the amount of
23
- * memory available. In such cases, it is better to use the XML::Reader.
24
- *
25
- * Using the parser is simple:
26
- *
27
- * parser = XML::Parser.new
28
- * parser.file = 'my_file'
29
- * doc = parser.parse
30
- *
31
- * You can also parse strings (see XML::Parser.string) and io objects (see
32
- * XML::Parser.io).
33
- */
34
-
35
- /*
36
- * call-seq:
37
- * parser.initialize -> parser
38
- *
39
- * Initiliazes instance of parser.
40
- */
41
- static VALUE rxml_parser_initialize(VALUE self)
42
- {
43
- VALUE input = rb_class_new_instance(0, NULL, cXMLInput);
44
- rb_iv_set(self, "@input", input);
45
- rb_iv_set(self, "@context", Qnil);
46
- return self;
47
- }
48
-
49
- static xmlParserCtxtPtr rxml_parser_filename_ctxt(VALUE input)
50
- {
51
- xmlParserCtxtPtr ctxt;
52
- int retry_count = 0;
53
- VALUE filename = rb_ivar_get(input, FILE_ATTR);
54
-
55
- retry: ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename));
56
- if (ctxt == NULL)
57
- {
58
- if ((errno == EMFILE || errno == ENFILE) && retry_count == 0)
59
- {
60
- retry_count++;
61
- rb_gc();
62
- goto retry;
63
- }
64
- else
65
- {
66
- rb_raise(rb_eIOError, StringValuePtr(filename));
67
- }
68
- }
69
-
70
- return ctxt;
71
- }
72
-
73
- static xmlParserCtxtPtr rxml_parser_str_ctxt(VALUE input)
74
- {
75
- VALUE str = rb_ivar_get(input, STRING_ATTR);
76
- return xmlCreateMemoryParserCtxt(StringValuePtr(str), RSTRING_LEN(str));
77
- }
78
-
79
- static xmlParserCtxtPtr rxml_parser_io_ctxt(VALUE input)
80
- {
81
- VALUE io = rb_ivar_get(input, IO_ATTR);
82
- VALUE encoding = rb_ivar_get(input, ENCODING_ATTR);
83
- xmlCharEncoding xmlEncoding = NUM2INT(encoding);
84
-
85
- return xmlCreateIOParserCtxt(NULL, NULL,
86
- (xmlInputReadCallback) rxml_read_callback, NULL, (void *) io, xmlEncoding);
87
- }
88
-
89
- /*
90
- * call-seq:
91
- * parser.parse -> document
92
- *
93
- * Parse the input XML and create an XML::Document with
94
- * it's content. If an error occurs, XML::Parser::ParseError
95
- * is thrown.
96
- */
97
- static VALUE rxml_parser_parse(VALUE self)
98
- {
99
- xmlParserCtxtPtr ctxt;
100
- VALUE context;
101
- VALUE input = rb_ivar_get(self, INPUT_ATTR);
102
-
103
- context = rb_ivar_get(self, CONTEXT_ATTR);
104
- if (context != Qnil)
105
- rb_raise(rb_eRuntimeError, "You cannot parse a data source twice");
106
-
107
- if (rb_ivar_get(input, FILE_ATTR) != Qnil)
108
- ctxt = rxml_parser_filename_ctxt(input);
109
- else if (rb_ivar_get(input, STRING_ATTR) != Qnil)
110
- ctxt = rxml_parser_str_ctxt(input);
111
- /*else if (rb_ivar_get(input, DOCUMENT_ATTR) != Qnil)
112
- ctxt = rxml_parser_parse_document(input);*/
113
- else if (rb_ivar_get(input, IO_ATTR) != Qnil)
114
- ctxt = rxml_parser_io_ctxt(input);
115
- else
116
- rb_raise(rb_eArgError, "You must specify a parser data source");
117
-
118
- if (!ctxt)
119
- rxml_raise(&xmlLastError);
120
-
121
- context = rxml_parser_context_wrap(ctxt);
122
- rb_ivar_set(self, CONTEXT_ATTR, context);
123
-
124
- if (xmlParseDocument(ctxt) == -1 || !ctxt->wellFormed)
125
- {
126
- xmlFreeDoc(ctxt->myDoc);
127
- rxml_raise(&ctxt->lastError);
128
- }
129
-
130
- return rxml_document_wrap(ctxt->myDoc);
131
- }
132
-
133
- // Rdoc needs to know
134
- #ifdef RDOC_NEVER_DEFINED
135
- mLibXML = rb_define_module("LibXML");
136
- mXML = rb_define_module_under(mLibXML, "XML");
137
- #endif
138
-
139
- void ruby_init_parser(void)
140
- {
141
- cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
142
-
143
- /* Atributes */
144
- INPUT_ATTR = rb_intern("@input");
145
- CONTEXT_ATTR = rb_intern("@context");
146
- rb_define_attr(cXMLParser, "input", 1, 0);
147
- rb_define_attr(cXMLParser, "context", 1, 0);
148
-
149
- /* Instance Methods */
150
- rb_define_method(cXMLParser, "initialize", rxml_parser_initialize, 0);
151
- rb_define_method(cXMLParser, "parse", rxml_parser_parse, 0);
152
- }
1
+ /* $Id: ruby_xml_parser.c 650 2008-11-30 03:40:22Z 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
+ VALUE cXMLParser;
9
+ static ID INPUT_ATTR;
10
+ static ID CONTEXT_ATTR;
11
+
12
+ /*
13
+ * Document-class: LibXML::XML::Parser
14
+ *
15
+ * The XML::Parser provides a tree based API for processing
16
+ * xml documents, in contract to XML::Reader's stream
17
+ * based api and XML::SaxParser callback based API.
18
+ *
19
+ * As a result, parsing a document creates an in-memory document object
20
+ * that consist of any number of XML::Node instances. This is simple
21
+ * and powerful model, but has the major limitation that the size of
22
+ * the document that can be processed is limited by the amount of
23
+ * memory available. In such cases, it is better to use the XML::Reader.
24
+ *
25
+ * Using the parser is simple:
26
+ *
27
+ * parser = XML::Parser.new
28
+ * parser.file = 'my_file'
29
+ * doc = parser.parse
30
+ *
31
+ * You can also parse strings (see XML::Parser.string) and io objects (see
32
+ * XML::Parser.io).
33
+ */
34
+
35
+ /*
36
+ * call-seq:
37
+ * parser.initialize -> parser
38
+ *
39
+ * Initiliazes instance of parser.
40
+ */
41
+ static VALUE rxml_parser_initialize(VALUE self)
42
+ {
43
+ VALUE input = rb_class_new_instance(0, NULL, cXMLInput);
44
+ rb_iv_set(self, "@input", input);
45
+ rb_iv_set(self, "@context", Qnil);
46
+ return self;
47
+ }
48
+
49
+ static xmlParserCtxtPtr rxml_parser_filename_ctxt(VALUE input)
50
+ {
51
+ xmlParserCtxtPtr ctxt;
52
+ int retry_count = 0;
53
+ VALUE filename = rb_ivar_get(input, FILE_ATTR);
54
+
55
+ retry: ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename));
56
+ if (ctxt == NULL)
57
+ {
58
+ if ((errno == EMFILE || errno == ENFILE) && retry_count == 0)
59
+ {
60
+ retry_count++;
61
+ rb_gc();
62
+ goto retry;
63
+ }
64
+ else
65
+ {
66
+ rb_raise(rb_eIOError, StringValuePtr(filename));
67
+ }
68
+ }
69
+
70
+ return ctxt;
71
+ }
72
+
73
+ static xmlParserCtxtPtr rxml_parser_str_ctxt(VALUE input)
74
+ {
75
+ VALUE str = rb_ivar_get(input, STRING_ATTR);
76
+ return xmlCreateMemoryParserCtxt(StringValuePtr(str), RSTRING_LEN(str));
77
+ }
78
+
79
+ static xmlParserCtxtPtr rxml_parser_io_ctxt(VALUE input)
80
+ {
81
+ VALUE io = rb_ivar_get(input, IO_ATTR);
82
+ VALUE encoding = rb_ivar_get(input, ENCODING_ATTR);
83
+ xmlCharEncoding xmlEncoding = NUM2INT(encoding);
84
+
85
+ return xmlCreateIOParserCtxt(NULL, NULL,
86
+ (xmlInputReadCallback) rxml_read_callback, NULL, (void *) io, xmlEncoding);
87
+ }
88
+
89
+ /*
90
+ * call-seq:
91
+ * parser.parse -> document
92
+ *
93
+ * Parse the input XML and create an XML::Document with
94
+ * it's content. If an error occurs, XML::Parser::ParseError
95
+ * is thrown.
96
+ */
97
+ static VALUE rxml_parser_parse(VALUE self)
98
+ {
99
+ xmlParserCtxtPtr ctxt;
100
+ VALUE context;
101
+ VALUE input = rb_ivar_get(self, INPUT_ATTR);
102
+
103
+ context = rb_ivar_get(self, CONTEXT_ATTR);
104
+ if (context != Qnil)
105
+ rb_raise(rb_eRuntimeError, "You cannot parse a data source twice");
106
+
107
+ if (rb_ivar_get(input, FILE_ATTR) != Qnil)
108
+ ctxt = rxml_parser_filename_ctxt(input);
109
+ else if (rb_ivar_get(input, STRING_ATTR) != Qnil)
110
+ ctxt = rxml_parser_str_ctxt(input);
111
+ /*else if (rb_ivar_get(input, DOCUMENT_ATTR) != Qnil)
112
+ ctxt = rxml_parser_parse_document(input);*/
113
+ else if (rb_ivar_get(input, IO_ATTR) != Qnil)
114
+ ctxt = rxml_parser_io_ctxt(input);
115
+ else
116
+ rb_raise(rb_eArgError, "You must specify a parser data source");
117
+
118
+ if (!ctxt)
119
+ rxml_raise(&xmlLastError);
120
+
121
+ context = rxml_parser_context_wrap(ctxt);
122
+ rb_ivar_set(self, CONTEXT_ATTR, context);
123
+
124
+ if (xmlParseDocument(ctxt) == -1 || !ctxt->wellFormed)
125
+ {
126
+ xmlFreeDoc(ctxt->myDoc);
127
+ rxml_raise(&ctxt->lastError);
128
+ }
129
+
130
+ return rxml_document_wrap(ctxt->myDoc);
131
+ }
132
+
133
+ // Rdoc needs to know
134
+ #ifdef RDOC_NEVER_DEFINED
135
+ mLibXML = rb_define_module("LibXML");
136
+ mXML = rb_define_module_under(mLibXML, "XML");
137
+ #endif
138
+
139
+ void ruby_init_parser(void)
140
+ {
141
+ cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
142
+
143
+ /* Atributes */
144
+ INPUT_ATTR = rb_intern("@input");
145
+ CONTEXT_ATTR = rb_intern("@context");
146
+ rb_define_attr(cXMLParser, "input", 1, 0);
147
+ rb_define_attr(cXMLParser, "context", 1, 0);
148
+
149
+ /* Instance Methods */
150
+ rb_define_method(cXMLParser, "initialize", rxml_parser_initialize, 0);
151
+ rb_define_method(cXMLParser, "parse", rxml_parser_parse, 0);
152
+ }
@@ -1,9 +1,9 @@
1
- /* $Id: ruby_xml_parser.h 614 2008-11-22 08:04:39Z cfis $ */
1
+ /* $Id: ruby_xml_parser.h 666 2008-12-07 00:16:50Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
5
- #ifndef __rxml_PARSER__
6
- #define __rxml_PARSER__
5
+ #ifndef __RXML_PARSER__
6
+ #define __RXML_PARSER__
7
7
 
8
8
  #define MAX_LIBXML_FEATURES_LEN 50
9
9
 
@@ -1,657 +1,630 @@
1
- /* $Id: ruby_xml_parser_context.c 650 2008-11-30 03:40:22Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #include "ruby_libxml.h"
6
- #include "ruby_xml_parser_context.h"
7
-
8
- VALUE cXMLParserContext;
9
-
10
- /*
11
- * Document-class: LibXML::XML::Parser::Context
12
- *
13
- * The XML::Parser::Context class provides in-depth control over how
14
- * a document is parsed.
15
- */
16
-
17
- static void rxml_parser_context_free(xmlParserCtxtPtr ctxt)
18
- {
19
- if (ctxt != NULL)
20
- xmlFreeParserCtxt(ctxt);
21
- }
22
-
23
- VALUE rxml_parser_context_wrap(xmlParserCtxtPtr ctxt)
24
- {
25
- return Data_Wrap_Struct(cXMLParserContext, NULL, rxml_parser_context_free,
26
- ctxt);
27
- }
28
-
29
- /*
30
- * call-seq:
31
- * context.data_directory -> "dir"
32
- *
33
- * Obtain the data directory associated with this context.
34
- */
35
- static VALUE rxml_parser_context_data_directory_get(VALUE self)
36
- {
37
- xmlParserCtxtPtr ctxt;
38
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
39
-
40
- if (ctxt->directory == NULL)
41
- return (Qnil);
42
- else
43
- return (rb_str_new2(ctxt->directory));
44
- }
45
-
46
- /*
47
- * call-seq:
48
- * context.depth -> num
49
- *
50
- * Obtain the depth of this context.
51
- */
52
- static VALUE rxml_parser_context_depth_get(VALUE self)
53
- {
54
- xmlParserCtxtPtr ctxt;
55
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
56
-
57
- return (INT2NUM(ctxt->depth));
58
- }
59
-
60
- /*
61
- * call-seq:
62
- * context.disable_sax? -> (true|false)
63
- *
64
- * Determine whether SAX-based processing is disabled
65
- * in this context.
66
- */
67
- static VALUE rxml_parser_context_disable_sax_q(VALUE self)
68
- {
69
- xmlParserCtxtPtr ctxt;
70
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
71
-
72
- if (ctxt->disableSAX)
73
- return (Qtrue);
74
- else
75
- return (Qfalse);
76
- }
77
-
78
- /*
79
- * call-seq:
80
- * context.docbook? -> (true|false)
81
- *
82
- * Determine whether this is a docbook context.
83
- */
84
- static VALUE rxml_parser_context_docbook_q(VALUE self)
85
- {
86
- xmlParserCtxtPtr ctxt;
87
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
88
-
89
- if (ctxt->html == 2) // TODO check this
90
- return (Qtrue);
91
- else
92
- return (Qfalse);
93
- }
94
-
95
- /*
96
- * call-seq:
97
- * context.encoding -> "encoding"
98
- *
99
- * Obtain the character encoding identifier used in
100
- * this context.
101
- */
102
- static VALUE rxml_parser_context_encoding_get(VALUE self)
103
- {
104
- xmlParserCtxtPtr ctxt;
105
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
106
-
107
- if (ctxt->encoding == NULL)
108
- return (Qnil);
109
- else
110
- return (rb_str_new2((const char*) ctxt->encoding));
111
- }
112
-
113
- /*
114
- * call-seq:
115
- * context.errno -> num
116
- *
117
- * Obtain the last-error number in this context.
118
- */
119
- static VALUE rxml_parser_context_errno_get(VALUE self)
120
- {
121
- xmlParserCtxtPtr ctxt;
122
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
123
-
124
- return (INT2NUM(ctxt->errNo));
125
- }
126
-
127
- /*
128
- * call-seq:
129
- * context.html? -> (true|false)
130
- *
131
- * Determine whether this is an html context.
132
- */
133
- static VALUE rxml_parser_context_html_q(VALUE self)
134
- {
135
- xmlParserCtxtPtr ctxt;
136
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
137
-
138
- if (ctxt->html == 1)
139
- return (Qtrue);
140
- else
141
- return (Qfalse);
142
- }
143
-
144
- /*
145
- * call-seq:
146
- * context.max_num_streams -> num
147
- *
148
- * Obtain the limit on the number of IO streams opened in
149
- * this context.
150
- */
151
- static VALUE rxml_parser_context_io_max_num_streams_get(VALUE self)
152
- {
153
- // TODO alias to max_streams and dep this?
154
- xmlParserCtxtPtr ctxt;
155
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
156
-
157
- return (INT2NUM(ctxt->inputMax));
158
- }
159
-
160
- /*
161
- * call-seq:
162
- * context.num_streams -> "dir"
163
- *
164
- * Obtain the actual number of IO streams in this
165
- * context.
166
- */
167
- static VALUE rxml_parser_context_io_num_streams_get(VALUE self)
168
- {
169
- xmlParserCtxtPtr ctxt;
170
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
171
-
172
- return (INT2NUM(ctxt->inputNr));
173
- }
174
-
175
- /*
176
- * call-seq:
177
- * context.keep_blanks? -> (true|false)
178
- *
179
- * Determine whether parsers in this context retain
180
- * whitespace.
181
- */
182
- static VALUE rxml_parser_context_keep_blanks_q(VALUE self)
183
- {
184
- xmlParserCtxtPtr ctxt;
185
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
186
-
187
- if (ctxt->keepBlanks)
188
- return (Qtrue);
189
- else
190
- return (Qfalse);
191
- }
192
-
193
- /*
194
- * call-seq:
195
- * context.name_depth -> num
196
- *
197
- * Obtain the name depth for this context.
198
- */
199
- static VALUE rxml_parser_context_name_depth_get(VALUE self)
200
- {
201
- xmlParserCtxtPtr ctxt;
202
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
203
-
204
- return (INT2NUM(ctxt->nameNr));
205
- }
206
-
207
- /*
208
- * call-seq:
209
- * context.name_depth_max -> num
210
- *
211
- * Obtain the maximum name depth for this context.
212
- */
213
- static VALUE rxml_parser_context_name_depth_max_get(VALUE self)
214
- {
215
- xmlParserCtxtPtr ctxt;
216
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
217
-
218
- return (INT2NUM(ctxt->nameMax));
219
- }
220
-
221
- /*
222
- * call-seq:
223
- * context.name_node -> "name"
224
- *
225
- * Obtain the name node for this context.
226
- */
227
- static VALUE rxml_parser_context_name_node_get(VALUE self)
228
- {
229
- xmlParserCtxtPtr ctxt;
230
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
231
-
232
- if (ctxt->name == NULL)
233
- return (Qnil);
234
- else
235
- return (rb_str_new2((const char*) ctxt->name));
236
- }
237
-
238
- /*
239
- * call-seq:
240
- * context.name_tab -> ["name", ..., "name"]
241
- *
242
- * Obtain the name table for this context.
243
- */
244
- static VALUE rxml_parser_context_name_tab_get(VALUE self)
245
- {
246
- int i;
247
- xmlParserCtxtPtr ctxt;
248
- VALUE tab_ary;
249
-
250
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
251
-
252
- if (ctxt->nameTab == NULL)
253
- return (Qnil);
254
-
255
- tab_ary = rb_ary_new();
256
-
257
- for (i = (ctxt->nameNr - 1); i >= 0; i--)
258
- {
259
- if (ctxt->nameTab[i] == NULL)
260
- continue;
261
- else
262
- rb_ary_push(tab_ary, rb_str_new2((const char*) ctxt->nameTab[i]));
263
- }
264
-
265
- return (tab_ary);
266
- }
267
-
268
- /*
269
- * call-seq:
270
- * context.node_depth -> num
271
- *
272
- * Obtain the node depth for this context.
273
- */
274
- static VALUE rxml_parser_context_node_depth_get(VALUE self)
275
- {
276
- xmlParserCtxtPtr ctxt;
277
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
278
-
279
- return (INT2NUM(ctxt->nodeNr));
280
- }
281
-
282
- /*
283
- * call-seq:
284
- * context.node -> node
285
- *
286
- * Obtain the root node of this context.
287
- */
288
- static VALUE rxml_parser_context_node_get(VALUE self)
289
- {
290
- xmlParserCtxtPtr ctxt;
291
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
292
-
293
- if (ctxt->node == NULL)
294
- return (Qnil);
295
- else
296
- return (rxml_node_wrap(cXMLNode, ctxt->node));
297
- }
298
-
299
- /*
300
- * call-seq:
301
- * context.node_depth_max -> num
302
- *
303
- * Obtain the maximum node depth for this context.
304
- */
305
- static VALUE rxml_parser_context_node_depth_max_get(VALUE self)
306
- {
307
- xmlParserCtxtPtr ctxt;
308
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
309
-
310
- return (INT2NUM(ctxt->nodeMax));
311
- }
312
-
313
- /*
314
- * call-seq:
315
- * context.num_chars -> num
316
- *
317
- * Obtain the number of characters in this context.
318
- */
319
- static VALUE rxml_parser_context_num_chars_get(VALUE self)
320
- {
321
- xmlParserCtxtPtr ctxt;
322
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
323
-
324
- return (LONG2NUM(ctxt->nbChars));
325
- }
326
-
327
- /*
328
- * call-seq:
329
- * context.replace_entities? -> (true|false)
330
- *
331
- * Determine whether external entity replacement is enabled in this
332
- * context.
333
- */
334
- static VALUE rxml_parser_context_replace_entities_q(VALUE self)
335
- {
336
- xmlParserCtxtPtr ctxt;
337
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
338
-
339
- if (ctxt->replaceEntities)
340
- return (Qtrue);
341
- else
342
- return (Qfalse);
343
- }
344
-
345
- /*
346
- * call-seq:
347
- * context.replace_entities = true|false
348
- *
349
- * Control whether external entity replacement is enabled in this
350
- * context.
351
- */
352
- static VALUE rxml_parser_context_replace_entities_set(VALUE self, VALUE bool)
353
- {
354
- xmlParserCtxtPtr ctxt;
355
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
356
-
357
- if (TYPE(bool) == T_FALSE)
358
- {
359
- ctxt->replaceEntities = 0;
360
- return (Qfalse);
361
- }
362
- else
363
- {
364
- ctxt->replaceEntities = 1;
365
- return (Qfalse);
366
- }
367
- }
368
-
369
- /*
370
- * call-seq:
371
- * context.space_depth -> num
372
- *
373
- * Obtain the space depth for this context.
374
- */
375
- static VALUE rxml_parser_context_space_depth_get(VALUE self)
376
- {
377
- xmlParserCtxtPtr ctxt;
378
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
379
-
380
- return (INT2NUM(ctxt->spaceNr));
381
- }
382
-
383
- /*
384
- * call-seq:
385
- * context.space_depth -> num
386
- *
387
- * Obtain the maximum space depth for this context.
388
- */
389
- static VALUE rxml_parser_context_space_depth_max_get(VALUE self)
390
- {
391
- xmlParserCtxtPtr ctxt;
392
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
393
-
394
- return (INT2NUM(ctxt->spaceMax));
395
- }
396
-
397
- /*
398
- * call-seq:
399
- * context.subset_external? -> (true|false)
400
- *
401
- * Determine whether this context is a subset of an
402
- * external context.
403
- */
404
- static VALUE rxml_parser_context_subset_external_q(VALUE self)
405
- {
406
- xmlParserCtxtPtr ctxt;
407
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
408
-
409
- if (ctxt->inSubset == 2)
410
- return (Qtrue);
411
- else
412
- return (Qfalse);
413
- }
414
-
415
- /*
416
- * call-seq:
417
- * context.subset_internal? -> (true|false)
418
- *
419
- * Determine whether this context is a subset of an
420
- * internal context.
421
- */
422
- static VALUE rxml_parser_context_subset_internal_q(VALUE self)
423
- {
424
- xmlParserCtxtPtr ctxt;
425
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
426
-
427
- if (ctxt->inSubset == 1)
428
- return (Qtrue);
429
- else
430
- return (Qfalse);
431
- }
432
-
433
- /*
434
- * call-seq:
435
- * context.subset_name -> "name"
436
- *
437
- * Obtain this context's subset name (valid only if
438
- * either of subset_external? or subset_internal?
439
- * is true).
440
- */
441
- static VALUE rxml_parser_context_subset_name_get(VALUE self)
442
- {
443
- xmlParserCtxtPtr ctxt;
444
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
445
-
446
- if (ctxt->intSubName == NULL)
447
- return (Qnil);
448
- else
449
- return (rb_str_new2((const char*) ctxt->intSubName));
450
- }
451
-
452
- /*
453
- * call-seq:
454
- * context.subset_external_uri -> "uri"
455
- *
456
- * Obtain this context's external subset URI. (valid only if
457
- * either of subset_external? or subset_internal?
458
- * is true).
459
- */
460
- static VALUE rxml_parser_context_subset_external_uri_get(VALUE self)
461
- {
462
- xmlParserCtxtPtr ctxt;
463
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
464
-
465
- if (ctxt->extSubURI == NULL)
466
- return (Qnil);
467
- else
468
- return (rb_str_new2((const char*) ctxt->extSubURI));
469
- }
470
-
471
- /*
472
- * call-seq:
473
- * context.subset_external_system_id -> "system_id"
474
- *
475
- * Obtain this context's external subset system identifier.
476
- * (valid only if either of subset_external? or subset_internal?
477
- * is true).
478
- */
479
- static VALUE rxml_parser_context_subset_external_system_id_get(VALUE self)
480
- {
481
- xmlParserCtxtPtr ctxt;
482
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
483
-
484
- if (ctxt->extSubSystem == NULL)
485
- return (Qnil);
486
- else
487
- return (rb_str_new2((const char*) ctxt->extSubSystem));
488
- }
489
-
490
- /*
491
- * call-seq:
492
- * context.standalone? -> (true|false)
493
- *
494
- * Determine whether this is a standalone context.
495
- */
496
- static VALUE rxml_parser_context_standalone_q(VALUE self)
497
- {
498
- xmlParserCtxtPtr ctxt;
499
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
500
-
501
- if (ctxt->standalone)
502
- return (Qtrue);
503
- else
504
- return (Qfalse);
505
- }
506
-
507
- /*
508
- * call-seq:
509
- * context.stats? -> (true|false)
510
- *
511
- * Determine whether this context maintains statistics.
512
- */
513
- static VALUE rxml_parser_context_stats_q(VALUE self)
514
- {
515
- xmlParserCtxtPtr ctxt;
516
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
517
-
518
- if (ctxt->record_info)
519
- return (Qtrue);
520
- else
521
- return (Qfalse);
522
- }
523
-
524
- /*
525
- * call-seq:
526
- * context.valid? -> (true|false)
527
- *
528
- * Determine whether this context is valid.
529
- */
530
- static VALUE rxml_parser_context_valid_q(VALUE self)
531
- {
532
- xmlParserCtxtPtr ctxt;
533
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
534
-
535
- if (ctxt->valid)
536
- return (Qtrue);
537
- else
538
- return (Qfalse);
539
- }
540
-
541
- /*
542
- * call-seq:
543
- * context.validate? -> (true|false)
544
- *
545
- * Determine whether validation is enabled in this context.
546
- */
547
- static VALUE rxml_parser_context_validate_q(VALUE self)
548
- {
549
- xmlParserCtxtPtr ctxt;
550
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
551
-
552
- if (ctxt->validate)
553
- return (Qtrue);
554
- else
555
- return (Qfalse);
556
- }
557
-
558
- /*
559
- * call-seq:
560
- * context.version -> "version"
561
- *
562
- * Obtain this context's version identifier.
563
- */
564
- static VALUE rxml_parser_context_version_get(VALUE self)
565
- {
566
- xmlParserCtxtPtr ctxt;
567
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
568
-
569
- if (ctxt->version == NULL)
570
- return (Qnil);
571
- else
572
- return (rb_str_new2((const char*) ctxt->version));
573
- }
574
-
575
- /*
576
- * call-seq:
577
- * context.well_formed? -> (true|false)
578
- *
579
- * Determine whether this context contains well-formed XML.
580
- */
581
- static VALUE rxml_parser_context_well_formed_q(VALUE self)
582
- {
583
- xmlParserCtxtPtr ctxt;
584
- Data_Get_Struct(self, xmlParserCtxt, ctxt);
585
-
586
- if (ctxt->wellFormed)
587
- return (Qtrue);
588
- else
589
- return (Qfalse);
590
- }
591
-
592
- void ruby_init_xml_parser_context(void)
593
- {
594
- cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
595
- rb_undef_alloc_func(cXMLParserContext);
596
-
597
- rb_define_method(cXMLParserContext, "data_directory",
598
- rxml_parser_context_data_directory_get, 0);
599
- rb_define_method(cXMLParserContext, "depth", rxml_parser_context_depth_get, 0);
600
- rb_define_method(cXMLParserContext, "disable_sax?",
601
- rxml_parser_context_disable_sax_q, 0);
602
- rb_define_method(cXMLParserContext, "docbook?",
603
- rxml_parser_context_docbook_q, 0);
604
- rb_define_method(cXMLParserContext, "encoding",
605
- rxml_parser_context_encoding_get, 0);
606
- rb_define_method(cXMLParserContext, "errno", rxml_parser_context_errno_get, 0);
607
- rb_define_method(cXMLParserContext, "html?", rxml_parser_context_html_q, 0);
608
- rb_define_method(cXMLParserContext, "io_max_num_streams",
609
- rxml_parser_context_io_max_num_streams_get, 0);
610
- rb_define_method(cXMLParserContext, "io_num_streams",
611
- rxml_parser_context_io_num_streams_get, 0);
612
- rb_define_method(cXMLParserContext, "keep_blanks?",
613
- rxml_parser_context_keep_blanks_q, 0);
614
- rb_define_method(cXMLParserContext, "name_node",
615
- rxml_parser_context_name_node_get, 0);
616
- rb_define_method(cXMLParserContext, "name_depth",
617
- rxml_parser_context_name_depth_get, 0);
618
- rb_define_method(cXMLParserContext, "name_depth_max",
619
- rxml_parser_context_name_depth_max_get, 0);
620
- rb_define_method(cXMLParserContext, "name_tab",
621
- rxml_parser_context_name_tab_get, 0);
622
- rb_define_method(cXMLParserContext, "node", rxml_parser_context_node_get, 0);
623
- rb_define_method(cXMLParserContext, "node_depth",
624
- rxml_parser_context_node_depth_get, 0);
625
- rb_define_method(cXMLParserContext, "node_depth_max",
626
- rxml_parser_context_node_depth_max_get, 0);
627
- rb_define_method(cXMLParserContext, "num_chars",
628
- rxml_parser_context_num_chars_get, 0);
629
- rb_define_method(cXMLParserContext, "replace_entities?",
630
- rxml_parser_context_replace_entities_q, 0);
631
- rb_define_method(cXMLParserContext, "replace_entities=",
632
- rxml_parser_context_replace_entities_set, 1);
633
- rb_define_method(cXMLParserContext, "space_depth",
634
- rxml_parser_context_space_depth_get, 0);
635
- rb_define_method(cXMLParserContext, "space_depth_max",
636
- rxml_parser_context_space_depth_max_get, 0);
637
- rb_define_method(cXMLParserContext, "subset_external?",
638
- rxml_parser_context_subset_external_q, 0);
639
- rb_define_method(cXMLParserContext, "subset_external_system_id",
640
- rxml_parser_context_subset_external_system_id_get, 0);
641
- rb_define_method(cXMLParserContext, "subset_external_uri",
642
- rxml_parser_context_subset_name_get, 0);
643
- rb_define_method(cXMLParserContext, "subset_internal?",
644
- rxml_parser_context_subset_internal_q, 0);
645
- rb_define_method(cXMLParserContext, "subset_internal_name",
646
- rxml_parser_context_subset_name_get, 0);
647
- rb_define_method(cXMLParserContext, "stats?", rxml_parser_context_stats_q, 0);
648
- rb_define_method(cXMLParserContext, "standalone?",
649
- rxml_parser_context_standalone_q, 0);
650
- rb_define_method(cXMLParserContext, "valid", rxml_parser_context_valid_q, 0);
651
- rb_define_method(cXMLParserContext, "validate?",
652
- rxml_parser_context_validate_q, 0);
653
- rb_define_method(cXMLParserContext, "version",
654
- rxml_parser_context_version_get, 0);
655
- rb_define_method(cXMLParserContext, "well_formed?",
656
- rxml_parser_context_well_formed_q, 0);
657
- }
1
+ /* $Id: ruby_xml_parser_context.c 659 2008-12-01 17:08:58Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #include "ruby_libxml.h"
6
+ #include "ruby_xml_parser_context.h"
7
+
8
+ VALUE cXMLParserContext;
9
+
10
+ /*
11
+ * Document-class: LibXML::XML::Parser::Context
12
+ *
13
+ * The XML::Parser::Context class provides in-depth control over how
14
+ * a document is parsed.
15
+ */
16
+
17
+ static void rxml_parser_context_free(xmlParserCtxtPtr ctxt)
18
+ {
19
+ if (ctxt != NULL)
20
+ xmlFreeParserCtxt(ctxt);
21
+ }
22
+
23
+ VALUE rxml_parser_context_wrap(xmlParserCtxtPtr ctxt)
24
+ {
25
+ return Data_Wrap_Struct(cXMLParserContext, NULL, rxml_parser_context_free,
26
+ ctxt);
27
+ }
28
+
29
+ /*
30
+ * call-seq:
31
+ * context.data_directory -> "dir"
32
+ *
33
+ * Obtain the data directory associated with this context.
34
+ */
35
+ static VALUE rxml_parser_context_data_directory_get(VALUE self)
36
+ {
37
+ xmlParserCtxtPtr ctxt;
38
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
39
+
40
+ if (ctxt->directory == NULL)
41
+ return (Qnil);
42
+ else
43
+ return (rb_str_new2(ctxt->directory));
44
+ }
45
+
46
+ /*
47
+ * call-seq:
48
+ * context.depth -> num
49
+ *
50
+ * Obtain the depth of this context.
51
+ */
52
+ static VALUE rxml_parser_context_depth_get(VALUE self)
53
+ {
54
+ xmlParserCtxtPtr ctxt;
55
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
56
+
57
+ return (INT2NUM(ctxt->depth));
58
+ }
59
+
60
+ /*
61
+ * call-seq:
62
+ * context.disable_sax? -> (true|false)
63
+ *
64
+ * Determine whether SAX-based processing is disabled
65
+ * in this context.
66
+ */
67
+ static VALUE rxml_parser_context_disable_sax_q(VALUE self)
68
+ {
69
+ xmlParserCtxtPtr ctxt;
70
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
71
+
72
+ if (ctxt->disableSAX)
73
+ return (Qtrue);
74
+ else
75
+ return (Qfalse);
76
+ }
77
+
78
+ /*
79
+ * call-seq:
80
+ * context.docbook? -> (true|false)
81
+ *
82
+ * Determine whether this is a docbook context.
83
+ */
84
+ static VALUE rxml_parser_context_docbook_q(VALUE self)
85
+ {
86
+ xmlParserCtxtPtr ctxt;
87
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
88
+
89
+ if (ctxt->html == 2) // TODO check this
90
+ return (Qtrue);
91
+ else
92
+ return (Qfalse);
93
+ }
94
+
95
+ /*
96
+ * call-seq:
97
+ * context.encoding -> "encoding"
98
+ *
99
+ * Obtain the character encoding identifier used in
100
+ * this context.
101
+ */
102
+ static VALUE rxml_parser_context_encoding_get(VALUE self)
103
+ {
104
+ xmlParserCtxtPtr ctxt;
105
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
106
+
107
+ if (ctxt->encoding == NULL)
108
+ return (Qnil);
109
+ else
110
+ return (rb_str_new2((const char*) ctxt->encoding));
111
+ }
112
+
113
+ /*
114
+ * call-seq:
115
+ * context.errno -> num
116
+ *
117
+ * Obtain the last-error number in this context.
118
+ */
119
+ static VALUE rxml_parser_context_errno_get(VALUE self)
120
+ {
121
+ xmlParserCtxtPtr ctxt;
122
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
123
+
124
+ return (INT2NUM(ctxt->errNo));
125
+ }
126
+
127
+ /*
128
+ * call-seq:
129
+ * context.html? -> (true|false)
130
+ *
131
+ * Determine whether this is an html context.
132
+ */
133
+ static VALUE rxml_parser_context_html_q(VALUE self)
134
+ {
135
+ xmlParserCtxtPtr ctxt;
136
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
137
+
138
+ if (ctxt->html == 1)
139
+ return (Qtrue);
140
+ else
141
+ return (Qfalse);
142
+ }
143
+
144
+ /*
145
+ * call-seq:
146
+ * context.max_num_streams -> num
147
+ *
148
+ * Obtain the limit on the number of IO streams opened in
149
+ * this context.
150
+ */
151
+ static VALUE rxml_parser_context_io_max_num_streams_get(VALUE self)
152
+ {
153
+ // TODO alias to max_streams and dep this?
154
+ xmlParserCtxtPtr ctxt;
155
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
156
+
157
+ return (INT2NUM(ctxt->inputMax));
158
+ }
159
+
160
+ /*
161
+ * call-seq:
162
+ * context.num_streams -> "dir"
163
+ *
164
+ * Obtain the actual number of IO streams in this
165
+ * context.
166
+ */
167
+ static VALUE rxml_parser_context_io_num_streams_get(VALUE self)
168
+ {
169
+ xmlParserCtxtPtr ctxt;
170
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
171
+
172
+ return (INT2NUM(ctxt->inputNr));
173
+ }
174
+
175
+ /*
176
+ * call-seq:
177
+ * context.keep_blanks? -> (true|false)
178
+ *
179
+ * Determine whether parsers in this context retain
180
+ * whitespace.
181
+ */
182
+ static VALUE rxml_parser_context_keep_blanks_q(VALUE self)
183
+ {
184
+ xmlParserCtxtPtr ctxt;
185
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
186
+
187
+ if (ctxt->keepBlanks)
188
+ return (Qtrue);
189
+ else
190
+ return (Qfalse);
191
+ }
192
+
193
+ /*
194
+ * call-seq:
195
+ * context.name_depth -> num
196
+ *
197
+ * Obtain the name depth for this context.
198
+ */
199
+ static VALUE rxml_parser_context_name_depth_get(VALUE self)
200
+ {
201
+ xmlParserCtxtPtr ctxt;
202
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
203
+
204
+ return (INT2NUM(ctxt->nameNr));
205
+ }
206
+
207
+ /*
208
+ * call-seq:
209
+ * context.name_depth_max -> num
210
+ *
211
+ * Obtain the maximum name depth for this context.
212
+ */
213
+ static VALUE rxml_parser_context_name_depth_max_get(VALUE self)
214
+ {
215
+ xmlParserCtxtPtr ctxt;
216
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
217
+
218
+ return (INT2NUM(ctxt->nameMax));
219
+ }
220
+
221
+ /*
222
+ * call-seq:
223
+ * context.name_node -> "name"
224
+ *
225
+ * Obtain the name node for this context.
226
+ */
227
+ static VALUE rxml_parser_context_name_node_get(VALUE self)
228
+ {
229
+ xmlParserCtxtPtr ctxt;
230
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
231
+
232
+ if (ctxt->name == NULL)
233
+ return (Qnil);
234
+ else
235
+ return (rb_str_new2((const char*) ctxt->name));
236
+ }
237
+
238
+ /*
239
+ * call-seq:
240
+ * context.name_tab -> ["name", ..., "name"]
241
+ *
242
+ * Obtain the name table for this context.
243
+ */
244
+ static VALUE rxml_parser_context_name_tab_get(VALUE self)
245
+ {
246
+ int i;
247
+ xmlParserCtxtPtr ctxt;
248
+ VALUE tab_ary;
249
+
250
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
251
+
252
+ if (ctxt->nameTab == NULL)
253
+ return (Qnil);
254
+
255
+ tab_ary = rb_ary_new();
256
+
257
+ for (i = (ctxt->nameNr - 1); i >= 0; i--)
258
+ {
259
+ if (ctxt->nameTab[i] == NULL)
260
+ continue;
261
+ else
262
+ rb_ary_push(tab_ary, rb_str_new2((const char*) ctxt->nameTab[i]));
263
+ }
264
+
265
+ return (tab_ary);
266
+ }
267
+
268
+ /*
269
+ * call-seq:
270
+ * context.node_depth -> num
271
+ *
272
+ * Obtain the node depth for this context.
273
+ */
274
+ static VALUE rxml_parser_context_node_depth_get(VALUE self)
275
+ {
276
+ xmlParserCtxtPtr ctxt;
277
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
278
+
279
+ return (INT2NUM(ctxt->nodeNr));
280
+ }
281
+
282
+ /*
283
+ * call-seq:
284
+ * context.node -> node
285
+ *
286
+ * Obtain the root node of this context.
287
+ */
288
+ static VALUE rxml_parser_context_node_get(VALUE self)
289
+ {
290
+ xmlParserCtxtPtr ctxt;
291
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
292
+
293
+ if (ctxt->node == NULL)
294
+ return (Qnil);
295
+ else
296
+ return (rxml_node_wrap(cXMLNode, ctxt->node));
297
+ }
298
+
299
+ /*
300
+ * call-seq:
301
+ * context.node_depth_max -> num
302
+ *
303
+ * Obtain the maximum node depth for this context.
304
+ */
305
+ static VALUE rxml_parser_context_node_depth_max_get(VALUE self)
306
+ {
307
+ xmlParserCtxtPtr ctxt;
308
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
309
+
310
+ return (INT2NUM(ctxt->nodeMax));
311
+ }
312
+
313
+ /*
314
+ * call-seq:
315
+ * context.num_chars -> num
316
+ *
317
+ * Obtain the number of characters in this context.
318
+ */
319
+ static VALUE rxml_parser_context_num_chars_get(VALUE self)
320
+ {
321
+ xmlParserCtxtPtr ctxt;
322
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
323
+
324
+ return (LONG2NUM(ctxt->nbChars));
325
+ }
326
+
327
+ /*
328
+ * call-seq:
329
+ * context.replace_entities? -> (true|false)
330
+ *
331
+ * Determine whether external entity replacement is enabled in this
332
+ * context.
333
+ */
334
+ static VALUE rxml_parser_context_replace_entities_q(VALUE self)
335
+ {
336
+ xmlParserCtxtPtr ctxt;
337
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
338
+
339
+ if (ctxt->replaceEntities)
340
+ return (Qtrue);
341
+ else
342
+ return (Qfalse);
343
+ }
344
+
345
+ /*
346
+ * call-seq:
347
+ * context.replace_entities = true|false
348
+ *
349
+ * Control whether external entity replacement is enabled in this
350
+ * context.
351
+ */
352
+ static VALUE rxml_parser_context_replace_entities_set(VALUE self, VALUE bool)
353
+ {
354
+ xmlParserCtxtPtr ctxt;
355
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
356
+
357
+ if (TYPE(bool) == T_FALSE)
358
+ {
359
+ ctxt->replaceEntities = 0;
360
+ return (Qfalse);
361
+ }
362
+ else
363
+ {
364
+ ctxt->replaceEntities = 1;
365
+ return (Qfalse);
366
+ }
367
+ }
368
+
369
+ /*
370
+ * call-seq:
371
+ * context.space_depth -> num
372
+ *
373
+ * Obtain the space depth for this context.
374
+ */
375
+ static VALUE rxml_parser_context_space_depth_get(VALUE self)
376
+ {
377
+ xmlParserCtxtPtr ctxt;
378
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
379
+
380
+ return (INT2NUM(ctxt->spaceNr));
381
+ }
382
+
383
+ /*
384
+ * call-seq:
385
+ * context.space_depth -> num
386
+ *
387
+ * Obtain the maximum space depth for this context.
388
+ */
389
+ static VALUE rxml_parser_context_space_depth_max_get(VALUE self)
390
+ {
391
+ xmlParserCtxtPtr ctxt;
392
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
393
+
394
+ return (INT2NUM(ctxt->spaceMax));
395
+ }
396
+
397
+ /*
398
+ * call-seq:
399
+ * context.subset_external? -> (true|false)
400
+ *
401
+ * Determine whether this context is a subset of an
402
+ * external context.
403
+ */
404
+ static VALUE rxml_parser_context_subset_external_q(VALUE self)
405
+ {
406
+ xmlParserCtxtPtr ctxt;
407
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
408
+
409
+ if (ctxt->inSubset == 2)
410
+ return (Qtrue);
411
+ else
412
+ return (Qfalse);
413
+ }
414
+
415
+ /*
416
+ * call-seq:
417
+ * context.subset_internal? -> (true|false)
418
+ *
419
+ * Determine whether this context is a subset of an
420
+ * internal context.
421
+ */
422
+ static VALUE rxml_parser_context_subset_internal_q(VALUE self)
423
+ {
424
+ xmlParserCtxtPtr ctxt;
425
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
426
+
427
+ if (ctxt->inSubset == 1)
428
+ return (Qtrue);
429
+ else
430
+ return (Qfalse);
431
+ }
432
+
433
+ /*
434
+ * call-seq:
435
+ * context.subset_internal_name -> "name"
436
+ *
437
+ * Obtain this context's subset name (valid only if
438
+ * either of subset_external? or subset_internal?
439
+ * is true).
440
+ */
441
+ static VALUE rxml_parser_context_subset_name_get(VALUE self)
442
+ {
443
+ xmlParserCtxtPtr ctxt;
444
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
445
+
446
+ if (ctxt->intSubName == NULL)
447
+ return (Qnil);
448
+ else
449
+ return (rb_str_new2((const char*) ctxt->intSubName));
450
+ }
451
+
452
+ /*
453
+ * call-seq:
454
+ * context.subset_external_uri -> "uri"
455
+ *
456
+ * Obtain this context's external subset URI. (valid only if
457
+ * either of subset_external? or subset_internal?
458
+ * is true).
459
+ */
460
+ static VALUE rxml_parser_context_subset_external_uri_get(VALUE self)
461
+ {
462
+ xmlParserCtxtPtr ctxt;
463
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
464
+
465
+ if (ctxt->extSubURI == NULL)
466
+ return (Qnil);
467
+ else
468
+ return (rb_str_new2((const char*) ctxt->extSubURI));
469
+ }
470
+
471
+ /*
472
+ * call-seq:
473
+ * context.subset_external_system_id -> "system_id"
474
+ *
475
+ * Obtain this context's external subset system identifier.
476
+ * (valid only if either of subset_external? or subset_internal?
477
+ * is true).
478
+ */
479
+ static VALUE rxml_parser_context_subset_external_system_id_get(VALUE self)
480
+ {
481
+ xmlParserCtxtPtr ctxt;
482
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
483
+
484
+ if (ctxt->extSubSystem == NULL)
485
+ return (Qnil);
486
+ else
487
+ return (rb_str_new2((const char*) ctxt->extSubSystem));
488
+ }
489
+
490
+ /*
491
+ * call-seq:
492
+ * context.standalone? -> (true|false)
493
+ *
494
+ * Determine whether this is a standalone context.
495
+ */
496
+ static VALUE rxml_parser_context_standalone_q(VALUE self)
497
+ {
498
+ xmlParserCtxtPtr ctxt;
499
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
500
+
501
+ if (ctxt->standalone)
502
+ return (Qtrue);
503
+ else
504
+ return (Qfalse);
505
+ }
506
+
507
+ /*
508
+ * call-seq:
509
+ * context.stats? -> (true|false)
510
+ *
511
+ * Determine whether this context maintains statistics.
512
+ */
513
+ static VALUE rxml_parser_context_stats_q(VALUE self)
514
+ {
515
+ xmlParserCtxtPtr ctxt;
516
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
517
+
518
+ if (ctxt->record_info)
519
+ return (Qtrue);
520
+ else
521
+ return (Qfalse);
522
+ }
523
+
524
+ /*
525
+ * call-seq:
526
+ * context.valid? -> (true|false)
527
+ *
528
+ * Determine whether this context is valid.
529
+ */
530
+ static VALUE rxml_parser_context_valid_q(VALUE self)
531
+ {
532
+ xmlParserCtxtPtr ctxt;
533
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
534
+
535
+ if (ctxt->valid)
536
+ return (Qtrue);
537
+ else
538
+ return (Qfalse);
539
+ }
540
+
541
+ /*
542
+ * call-seq:
543
+ * context.validate? -> (true|false)
544
+ *
545
+ * Determine whether validation is enabled in this context.
546
+ */
547
+ static VALUE rxml_parser_context_validate_q(VALUE self)
548
+ {
549
+ xmlParserCtxtPtr ctxt;
550
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
551
+
552
+ if (ctxt->validate)
553
+ return (Qtrue);
554
+ else
555
+ return (Qfalse);
556
+ }
557
+
558
+ /*
559
+ * call-seq:
560
+ * context.version -> "version"
561
+ *
562
+ * Obtain this context's version identifier.
563
+ */
564
+ static VALUE rxml_parser_context_version_get(VALUE self)
565
+ {
566
+ xmlParserCtxtPtr ctxt;
567
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
568
+
569
+ if (ctxt->version == NULL)
570
+ return (Qnil);
571
+ else
572
+ return (rb_str_new2((const char*) ctxt->version));
573
+ }
574
+
575
+ /*
576
+ * call-seq:
577
+ * context.well_formed? -> (true|false)
578
+ *
579
+ * Determine whether this context contains well-formed XML.
580
+ */
581
+ static VALUE rxml_parser_context_well_formed_q(VALUE self)
582
+ {
583
+ xmlParserCtxtPtr ctxt;
584
+ Data_Get_Struct(self, xmlParserCtxt, ctxt);
585
+
586
+ if (ctxt->wellFormed)
587
+ return (Qtrue);
588
+ else
589
+ return (Qfalse);
590
+ }
591
+
592
+ void ruby_init_xml_parser_context(void)
593
+ {
594
+ cXMLParserContext = rb_define_class_under(cXMLParser, "Context", rb_cObject);
595
+ rb_undef_alloc_func(cXMLParserContext);
596
+
597
+ rb_define_method(cXMLParserContext, "data_directory", rxml_parser_context_data_directory_get, 0);
598
+ rb_define_method(cXMLParserContext, "depth", rxml_parser_context_depth_get, 0);
599
+ rb_define_method(cXMLParserContext, "disable_sax?", rxml_parser_context_disable_sax_q, 0);
600
+ rb_define_method(cXMLParserContext, "docbook?", rxml_parser_context_docbook_q, 0);
601
+ rb_define_method(cXMLParserContext, "encoding", rxml_parser_context_encoding_get, 0);
602
+ rb_define_method(cXMLParserContext, "errno", rxml_parser_context_errno_get, 0);
603
+ rb_define_method(cXMLParserContext, "html?", rxml_parser_context_html_q, 0);
604
+ rb_define_method(cXMLParserContext, "io_max_num_streams", rxml_parser_context_io_max_num_streams_get, 0);
605
+ rb_define_method(cXMLParserContext, "io_num_streams", rxml_parser_context_io_num_streams_get, 0);
606
+ rb_define_method(cXMLParserContext, "keep_blanks?", rxml_parser_context_keep_blanks_q, 0);
607
+ rb_define_method(cXMLParserContext, "name_node", rxml_parser_context_name_node_get, 0);
608
+ rb_define_method(cXMLParserContext, "name_depth", rxml_parser_context_name_depth_get, 0);
609
+ rb_define_method(cXMLParserContext, "name_depth_max", rxml_parser_context_name_depth_max_get, 0);
610
+ rb_define_method(cXMLParserContext, "name_tab", rxml_parser_context_name_tab_get, 0);
611
+ rb_define_method(cXMLParserContext, "node", rxml_parser_context_node_get, 0);
612
+ rb_define_method(cXMLParserContext, "node_depth", rxml_parser_context_node_depth_get, 0);
613
+ rb_define_method(cXMLParserContext, "node_depth_max", rxml_parser_context_node_depth_max_get, 0);
614
+ rb_define_method(cXMLParserContext, "num_chars", rxml_parser_context_num_chars_get, 0);
615
+ rb_define_method(cXMLParserContext, "replace_entities?", rxml_parser_context_replace_entities_q, 0);
616
+ rb_define_method(cXMLParserContext, "replace_entities=", rxml_parser_context_replace_entities_set, 1);
617
+ rb_define_method(cXMLParserContext, "space_depth", rxml_parser_context_space_depth_get, 0);
618
+ rb_define_method(cXMLParserContext, "space_depth_max", rxml_parser_context_space_depth_max_get, 0);
619
+ rb_define_method(cXMLParserContext, "subset_external?", rxml_parser_context_subset_external_q, 0);
620
+ rb_define_method(cXMLParserContext, "subset_external_system_id", rxml_parser_context_subset_external_system_id_get, 0);
621
+ rb_define_method(cXMLParserContext, "subset_external_uri", rxml_parser_context_subset_external_uri_get, 0);
622
+ rb_define_method(cXMLParserContext, "subset_internal?", rxml_parser_context_subset_internal_q, 0);
623
+ rb_define_method(cXMLParserContext, "subset_internal_name", rxml_parser_context_subset_name_get, 0);
624
+ rb_define_method(cXMLParserContext, "stats?", rxml_parser_context_stats_q, 0);
625
+ rb_define_method(cXMLParserContext, "standalone?", rxml_parser_context_standalone_q, 0);
626
+ rb_define_method(cXMLParserContext, "valid", rxml_parser_context_valid_q, 0);
627
+ rb_define_method(cXMLParserContext, "validate?", rxml_parser_context_validate_q, 0);
628
+ rb_define_method(cXMLParserContext, "version", rxml_parser_context_version_get, 0);
629
+ rb_define_method(cXMLParserContext, "well_formed?", rxml_parser_context_well_formed_q, 0);
630
+ }