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