libxml-ruby 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +21 -0
- data/RAKEFILE +213 -0
- data/README +32 -11
- data/doc/rdoc/classes/LibXML.html +4 -0
- data/doc/rdoc/classes/LibXML/XML.html +7 -0
- data/doc/rdoc/classes/LibXML/XML/Attr.html +187 -177
- data/doc/rdoc/classes/LibXML/XML/Attributes.html +62 -61
- data/doc/rdoc/classes/LibXML/XML/Document.html +318 -254
- data/doc/rdoc/classes/LibXML/XML/Dtd.html +62 -8
- data/doc/rdoc/classes/LibXML/XML/Error.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +59 -41
- data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +12 -6
- data/doc/rdoc/classes/LibXML/XML/NS.html +65 -50
- data/doc/rdoc/classes/LibXML/XML/Node.html +671 -630
- data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +12 -0
- data/doc/rdoc/classes/LibXML/XML/Node/Set.html +64 -60
- data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +12 -0
- data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +12 -0
- data/doc/rdoc/classes/LibXML/XML/Parser.html +407 -383
- data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +241 -219
- data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +12 -0
- data/doc/rdoc/classes/LibXML/XML/Reader.html +421 -331
- data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +237 -0
- data/doc/rdoc/classes/LibXML/XML/SaxParser.html +79 -60
- data/doc/rdoc/classes/LibXML/XML/Schema.html +109 -22
- data/doc/rdoc/classes/LibXML/XML/State.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/XInclude.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/XPath.html +4 -48
- data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +6 -5
- data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +61 -0
- data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +12 -8
- data/doc/rdoc/classes/LibXML/XML/XPointer.html +14 -8
- data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +6 -0
- data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +13 -0
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/CHANGES.html +38 -10
- data/doc/rdoc/files/LICENSE.html +1 -1
- data/doc/rdoc/files/README.html +57 -23
- data/doc/rdoc/files/VERSION.html +1 -1
- data/doc/rdoc/files/ext/libxml/cbg_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/libxml_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +1 -1
- data/doc/rdoc/{classes/XML.html → files/ext/libxml/ruby_xml_relaxng_c.html} +16 -35
- data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +1 -1
- data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +1 -1
- data/doc/rdoc/files/lib/libxml/attr_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/attributes_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/document_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/node_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/node_set_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/parser_options_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/parser_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/properties_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml/tree_rb.html +1 -1
- data/doc/rdoc/files/lib/libxml_rb.html +2 -2
- data/doc/rdoc/files/lib/xml/libxml_rb.html +12 -2
- data/doc/rdoc/files/lib/xml_rb.html +134 -0
- data/doc/rdoc/fr_class_index.html +1 -1
- data/doc/rdoc/fr_file_index.html +2 -0
- data/doc/rdoc/fr_method_index.html +349 -344
- data/ext/libxml/libxml.c +2 -1
- data/ext/libxml/ruby_libxml.h +1 -0
- data/ext/libxml/ruby_xml_attr.c +8 -2
- data/ext/libxml/ruby_xml_attributes.c +5 -5
- data/ext/libxml/ruby_xml_document.c +41 -2
- data/ext/libxml/ruby_xml_dtd.c +169 -169
- data/ext/libxml/ruby_xml_html_parser.c +449 -449
- data/ext/libxml/ruby_xml_input_cbg.c +165 -165
- data/ext/libxml/ruby_xml_node.c +1 -1
- data/ext/libxml/ruby_xml_node_set.c +172 -172
- data/ext/libxml/ruby_xml_ns.c +145 -145
- data/ext/libxml/ruby_xml_parser.c +1398 -1398
- data/ext/libxml/ruby_xml_parser_context.c +697 -697
- data/ext/libxml/ruby_xml_reader.c +44 -0
- data/ext/libxml/ruby_xml_reader.h +14 -14
- data/ext/libxml/ruby_xml_relaxng.c +97 -0
- data/ext/libxml/ruby_xml_relaxng.h +15 -0
- data/ext/libxml/ruby_xml_sax_parser.c +486 -486
- data/ext/libxml/ruby_xml_schema.c +1 -1
- data/ext/libxml/ruby_xml_state.c +4 -4
- data/ext/libxml/ruby_xml_xinclude.c +21 -21
- data/ext/libxml/ruby_xml_xpath.c +89 -89
- data/ext/libxml/ruby_xml_xpath_context.c +283 -283
- data/ext/libxml/ruby_xml_xpath_object.c +5 -5
- data/ext/libxml/ruby_xml_xpointer.c +104 -104
- data/ext/libxml/ruby_xml_xpointer_context.c +22 -22
- data/ext/libxml/version.h +2 -2
- data/ext/libxml/version.h.rej +17 -0
- data/ext/mingw/Rakefile +41 -0
- data/lib/libxml.rb +15 -4
- data/lib/xml.rb +14 -0
- data/lib/xml/libxml.rb +4 -1
- data/test/etc_doc_to_s.rb +1 -1
- data/test/ets_copy_bug.rb +1 -1
- data/test/ets_copy_bug3.rb +1 -1
- data/test/ets_doc_file.rb +1 -1
- data/test/ets_doc_to_s.rb +1 -1
- data/test/ets_node_gc.rb +1 -1
- data/test/ets_tsr.rb +1 -1
- data/test/model/shiporder.rnc +28 -0
- data/test/model/shiporder.rng +86 -0
- data/test/{tc_xml_attributes.rb → tc_attributes.rb} +1 -10
- data/test/{tc_xml_document.rb → tc_document.rb} +1 -1
- data/test/{tc_xml_document_write.rb → tc_document_write.rb} +1 -1
- data/test/{tc_xml_dtd.rb → tc_dtd.rb} +1 -1
- data/test/{tc_xml_html_parser.rb → tc_html_parser.rb} +1 -1
- data/test/{tc_xml_node.rb → tc_node.rb} +1 -1
- data/test/{tc_xml_node_attr.rb → tc_node_attr.rb} +1 -1
- data/test/{tc_xml_node_cdata.rb → tc_node_cdata.rb} +24 -5
- data/test/{tc_xml_node_comment.rb → tc_node_comment.rb} +1 -1
- data/test/{tc_xml_node_copy.rb → tc_node_copy.rb} +1 -1
- data/test/{tc_xml_node_edit.rb → tc_node_edit.rb} +1 -1
- data/test/{tc_xml_node_set.rb → tc_node_set.rb} +1 -1
- data/test/{tc_xml_node_set2.rb → tc_node_set2.rb} +1 -1
- data/test/{tc_xml_node_text.rb → tc_node_text.rb} +1 -1
- data/test/{tc_xml_node_xlink.rb → tc_node_xlink.rb} +2 -2
- data/test/{tc_xml_parser.rb → tc_parser.rb} +1 -1
- data/test/{tc_xml_parser_context.rb → tc_parser_context.rb} +1 -1
- data/test/{tc_xml_properties.rb → tc_properties.rb} +1 -7
- data/test/{tc_xml_reader.rb → tc_reader.rb} +1 -1
- data/test/tc_relaxng.rb +39 -0
- data/test/{tc_xml_sax_parser.rb → tc_sax_parser.rb} +1 -1
- data/test/{tc_xml_schema.rb → tc_schema.rb} +1 -1
- data/test/{tc_xml_traversal.rb → tc_traversal.rb} +1 -1
- data/test/{tc_xml_xinclude.rb → tc_xinclude.rb} +1 -1
- data/test/{tc_xml_xpath.rb → tc_xpath.rb} +1 -1
- data/test/{tc_xml_xpath_context.rb → tc_xpath_context.rb} +1 -1
- data/test/{tc_xml_xpointer.rb → tc_xpointer.rb} +1 -1
- data/test/test_suite.rb +26 -25
- metadata +100 -100
- data/benchmark/depixelate.rb +0 -632
- data/benchmark/hamlet.xml +0 -9055
- data/benchmark/sock_entries.xml +0 -507
- data/benchmark/throughput.rb +0 -39
- data/benchmark/xml_benchmarks.rb +0 -227
- data/mingw/libiconv-2.dll +0 -0
- data/mingw/libxml2-2.dll +0 -0
- data/mingw/libxml_ruby.so +0 -0
- data/test/gc.log +0 -0
- data/vc/libxml_ruby.sln +0 -20
- data/vc/libxml_ruby.vcproj +0 -389
@@ -23,6 +23,11 @@ __rb_str_new_and_free(xmlChar *x)
|
|
23
23
|
VALUE cXMLReader;
|
24
24
|
static ID error_handler_block_ivar_id;
|
25
25
|
|
26
|
+
static int
|
27
|
+
ctxtRead(FILE *f, char * buf, size_t len) {
|
28
|
+
return(fread(buf, 1, len, f));
|
29
|
+
}
|
30
|
+
|
26
31
|
static VALUE
|
27
32
|
ruby_xml_reader_new(VALUE class, xmlTextReaderPtr reader)
|
28
33
|
{
|
@@ -63,6 +68,44 @@ ruby_xml_reader_new_file(int argc, VALUE *argv, VALUE self)
|
|
63
68
|
return ruby_xml_reader_new(self, reader);
|
64
69
|
}
|
65
70
|
|
71
|
+
/*
|
72
|
+
* call-seq:
|
73
|
+
* XML::Reader.io(io, url=nil, encoding=nil, options=0) -> reader
|
74
|
+
*
|
75
|
+
* Parse an XML file from a file handle. The parsing flags options are
|
76
|
+
* a combination of xmlParserOption.
|
77
|
+
*/
|
78
|
+
static VALUE
|
79
|
+
ruby_xml_reader_new_io(int argc, VALUE *argv, VALUE self)
|
80
|
+
{
|
81
|
+
xmlTextReaderPtr reader;
|
82
|
+
VALUE io, url, encoding, options;
|
83
|
+
OpenFile *fptr;
|
84
|
+
FILE *f;
|
85
|
+
|
86
|
+
#ifdef _WIN32
|
87
|
+
rb_raise(rb_eRuntimeError, "Reading an io stream is not supported on Windows");
|
88
|
+
#endif
|
89
|
+
|
90
|
+
rb_scan_args(argc, argv, "13", &io, &url, &encoding, &options);
|
91
|
+
|
92
|
+
if (!rb_obj_is_kind_of(io, rb_cIO))
|
93
|
+
rb_raise(rb_eTypeError, "need an IO object");
|
94
|
+
|
95
|
+
GetOpenFile(io, fptr);
|
96
|
+
rb_io_check_readable(fptr);
|
97
|
+
f = GetWriteFile(fptr);
|
98
|
+
|
99
|
+
reader = xmlReaderForIO((xmlInputReadCallback) ctxtRead, NULL, f,
|
100
|
+
NIL_P(url) ? NULL : RVAL2CSTR(url),
|
101
|
+
NIL_P(encoding) ? NULL : RVAL2CSTR(encoding),
|
102
|
+
NIL_P(options) ? 0 : FIX2INT(options));
|
103
|
+
if (reader == NULL)
|
104
|
+
rb_raise(rb_eRuntimeError, "cannot create text reader for given stream");
|
105
|
+
|
106
|
+
return ruby_xml_reader_new(self, reader);
|
107
|
+
}
|
108
|
+
|
66
109
|
/*
|
67
110
|
* call-seq:
|
68
111
|
* XML::Reader.walker(doc) -> reader
|
@@ -800,6 +843,7 @@ ruby_init_xml_reader(void)
|
|
800
843
|
error_handler_block_ivar_id = rb_intern("@__error_handler_callback__");
|
801
844
|
|
802
845
|
rb_define_singleton_method(cXMLReader, "file", ruby_xml_reader_new_file, -1);
|
846
|
+
rb_define_singleton_method(cXMLReader, "io", ruby_xml_reader_new_io, -1);
|
803
847
|
rb_define_singleton_method(cXMLReader, "walker", ruby_xml_reader_new_walker, 1);
|
804
848
|
rb_define_alias(CLASS_OF(cXMLReader), "document", "walker");
|
805
849
|
rb_define_singleton_method(cXMLReader, "new", ruby_xml_reader_new_data, -1);
|
@@ -1,14 +1,14 @@
|
|
1
|
-
/* Copyright (c) 2006 Apple Computer Inc.
|
2
|
-
* Please see the LICENSE file for copyright and distribution information. */
|
3
|
-
|
4
|
-
#ifndef __RUBY_XML_READER__
|
5
|
-
#define __RUBY_XML_READER__
|
6
|
-
|
7
|
-
extern VALUE cXMLReader;
|
8
|
-
|
9
|
-
void ruby_init_xml_reader(void);
|
10
|
-
|
11
|
-
/* Exported to be used by XML::Document#reader */
|
12
|
-
VALUE ruby_xml_reader_new_walker(VALUE self, VALUE doc);
|
13
|
-
|
14
|
-
#endif /* __RUBY_XML_READER__ */
|
1
|
+
/* Copyright (c) 2006 Apple Computer Inc.
|
2
|
+
* Please see the LICENSE file for copyright and distribution information. */
|
3
|
+
|
4
|
+
#ifndef __RUBY_XML_READER__
|
5
|
+
#define __RUBY_XML_READER__
|
6
|
+
|
7
|
+
extern VALUE cXMLReader;
|
8
|
+
|
9
|
+
void ruby_init_xml_reader(void);
|
10
|
+
|
11
|
+
/* Exported to be used by XML::Document#reader */
|
12
|
+
VALUE ruby_xml_reader_new_walker(VALUE self, VALUE doc);
|
13
|
+
|
14
|
+
#endif /* __RUBY_XML_READER__ */
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#include "ruby_libxml.h"
|
2
|
+
#include "ruby_xml_relaxng.h"
|
3
|
+
|
4
|
+
VALUE cXMLRelaxNG;
|
5
|
+
|
6
|
+
// Rdoc needs to know
|
7
|
+
#ifdef RDOC_NEVER_DEFINED
|
8
|
+
mLibXML = rb_define_module("LibXML");
|
9
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
10
|
+
#endif
|
11
|
+
|
12
|
+
static void
|
13
|
+
ruby_xml_relaxng_mark(ruby_xml_relaxng *rxrelaxng) {
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
|
17
|
+
void
|
18
|
+
ruby_xml_relaxng_free(ruby_xml_relaxng *rxrelaxng) {
|
19
|
+
if (rxrelaxng->relaxng != NULL) {
|
20
|
+
xmlRelaxNGFree(rxrelaxng->relaxng);
|
21
|
+
rxrelaxng->relaxng = NULL;
|
22
|
+
}
|
23
|
+
|
24
|
+
ruby_xfree(rxrelaxng);
|
25
|
+
}
|
26
|
+
|
27
|
+
/*
|
28
|
+
* call-seq:
|
29
|
+
* XML::Relaxng.new(relaxng_uri) -> relaxng
|
30
|
+
*
|
31
|
+
* Create a new relaxng from the specified URI.
|
32
|
+
*/
|
33
|
+
VALUE
|
34
|
+
ruby_xml_relaxng_init_from_uri(VALUE class, VALUE uri) {
|
35
|
+
xmlRelaxNGParserCtxtPtr parser;
|
36
|
+
ruby_xml_relaxng *relaxng;
|
37
|
+
|
38
|
+
Check_Type(uri, T_STRING);
|
39
|
+
|
40
|
+
parser = xmlRelaxNGNewParserCtxt(StringValuePtr(uri));
|
41
|
+
relaxng = ALLOC(ruby_xml_relaxng);
|
42
|
+
relaxng->relaxng = xmlRelaxNGParse(parser);
|
43
|
+
xmlRelaxNGFreeParserCtxt(parser);
|
44
|
+
|
45
|
+
return Data_Wrap_Struct(cXMLRelaxNG, ruby_xml_relaxng_mark, ruby_xml_relaxng_free, relaxng);
|
46
|
+
}
|
47
|
+
|
48
|
+
/*
|
49
|
+
* call-seq:
|
50
|
+
* XML::RelaxNG.document(document) -> relaxng
|
51
|
+
*
|
52
|
+
* Create a new relaxng from the specified document.
|
53
|
+
*/
|
54
|
+
VALUE
|
55
|
+
ruby_xml_relaxng_init_from_document(VALUE class, VALUE document) {
|
56
|
+
ruby_xml_document_t *rdoc;
|
57
|
+
ruby_xml_relaxng *relaxng;
|
58
|
+
xmlRelaxNGParserCtxtPtr parser;
|
59
|
+
|
60
|
+
Data_Get_Struct(document, ruby_xml_document_t, rdoc);
|
61
|
+
|
62
|
+
parser = xmlRelaxNGNewDocParserCtxt(rdoc->doc);
|
63
|
+
relaxng = ALLOC(ruby_xml_relaxng);
|
64
|
+
relaxng->relaxng = xmlRelaxNGParse(parser);
|
65
|
+
xmlRelaxNGFreeParserCtxt(parser);
|
66
|
+
|
67
|
+
return Data_Wrap_Struct(cXMLRelaxNG, ruby_xml_relaxng_mark, ruby_xml_relaxng_free, relaxng);
|
68
|
+
}
|
69
|
+
|
70
|
+
/*
|
71
|
+
* call-seq:
|
72
|
+
* XML::RelaxNG.string("relaxng_data") -> "value"
|
73
|
+
*
|
74
|
+
* Create a new relaxng using the specified string.
|
75
|
+
*/
|
76
|
+
VALUE
|
77
|
+
ruby_xml_relaxng_init_from_string(VALUE self, VALUE relaxng_str) {
|
78
|
+
xmlRelaxNGParserCtxtPtr parser;
|
79
|
+
ruby_xml_relaxng *rxrelaxng;
|
80
|
+
|
81
|
+
Check_Type(relaxng_str, T_STRING);
|
82
|
+
|
83
|
+
parser = xmlRelaxNGNewMemParserCtxt(StringValuePtr(relaxng_str), strlen(StringValuePtr(relaxng_str)));
|
84
|
+
rxrelaxng = ALLOC(ruby_xml_relaxng);
|
85
|
+
rxrelaxng->relaxng = xmlRelaxNGParse(parser);
|
86
|
+
xmlRelaxNGFreeParserCtxt(parser);
|
87
|
+
|
88
|
+
return Data_Wrap_Struct(cXMLRelaxNG, ruby_xml_relaxng_mark, ruby_xml_relaxng_free, rxrelaxng);
|
89
|
+
}
|
90
|
+
|
91
|
+
void ruby_init_xml_relaxng(void) {
|
92
|
+
cXMLRelaxNG = rb_define_class_under(mXML, "RelaxNG", rb_cObject);
|
93
|
+
rb_define_singleton_method(cXMLRelaxNG, "new", ruby_xml_relaxng_init_from_uri, 1);
|
94
|
+
rb_define_singleton_method(cXMLRelaxNG, "from_string", ruby_xml_relaxng_init_from_string, 1);
|
95
|
+
rb_define_singleton_method(cXMLRelaxNG, "document", ruby_xml_relaxng_init_from_document, 1);
|
96
|
+
}
|
97
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#ifndef __RUBY_XML_RELAXNG__
|
2
|
+
#define __RUBY_XML_RELAXNG__
|
3
|
+
|
4
|
+
#include <libxml/relaxng.h>
|
5
|
+
|
6
|
+
extern VALUE cXMLRelaxNG;
|
7
|
+
|
8
|
+
typedef struct rxp_relaxng {
|
9
|
+
xmlRelaxNGPtr relaxng; /* RelaxNG interface */
|
10
|
+
} ruby_xml_relaxng;
|
11
|
+
|
12
|
+
void ruby_init_xml_relaxng(void);
|
13
|
+
void ruby_relaxng_free(ruby_xml_relaxng *rxs);
|
14
|
+
#endif
|
15
|
+
|
@@ -1,486 +1,486 @@
|
|
1
|
-
/* $Id: ruby_xml_sax_parser.c 461 2008-07-15 21:35:56Z cfis $ */
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
#include "ruby_libxml.h"
|
6
|
-
#include "ruby_xml_sax_parser.h"
|
7
|
-
|
8
|
-
VALUE cXMLSaxParser;
|
9
|
-
VALUE mXMLSaxParserCallbacks;
|
10
|
-
|
11
|
-
VALUE cbidOnInternalSubset;
|
12
|
-
VALUE cbidOnIsStandalone;
|
13
|
-
VALUE cbidOnHasInternalSubset;
|
14
|
-
VALUE cbidOnHasExternalSubset;
|
15
|
-
VALUE cbidOnStartDocument;
|
16
|
-
VALUE cbidOnEndDocument;
|
17
|
-
VALUE cbidOnStartElement;
|
18
|
-
VALUE cbidOnEndElement;
|
19
|
-
VALUE cbidOnReference;
|
20
|
-
VALUE cbidOnCharacters;
|
21
|
-
VALUE cbidOnProcessingInstruction;
|
22
|
-
VALUE cbidOnComment;
|
23
|
-
VALUE cbidOnXmlParserWarning;
|
24
|
-
VALUE cbidOnXmlParserError;
|
25
|
-
VALUE cbidOnXmlParserFatalError;
|
26
|
-
VALUE cbidOnCdataBlock;
|
27
|
-
VALUE cbidOnExternalSubset;
|
28
|
-
|
29
|
-
#include "sax_parser_callbacks.inc"
|
30
|
-
|
31
|
-
void
|
32
|
-
ruby_xml_sax_parser_free(ruby_xml_sax_parser *nodesp) {
|
33
|
-
/* Apparently this isn't needed: time will tell */
|
34
|
-
/* if (nodesp->xsh != NULL) */
|
35
|
-
/* xmlFreeSax_Parser(nodesp->sax_parser); */
|
36
|
-
}
|
37
|
-
|
38
|
-
void
|
39
|
-
ruby_xml_sax_parser_mark(ruby_xml_sax_parser *nodesp) {
|
40
|
-
if (nodesp->callbackHandler && (nodesp->callbackHandler != Qnil)) {
|
41
|
-
rb_gc_mark(nodesp->callbackHandler);
|
42
|
-
}
|
43
|
-
|
44
|
-
if (nodesp->filename && (nodesp->filename != Qnil)) {
|
45
|
-
rb_gc_mark(nodesp->filename);
|
46
|
-
}
|
47
|
-
|
48
|
-
if (nodesp->str && (nodesp->str != Qnil)) {
|
49
|
-
rb_gc_mark(nodesp->str);
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
/*
|
54
|
-
* call-seq:
|
55
|
-
* XML::SaxParser.new -> sax_parser
|
56
|
-
*
|
57
|
-
* Create a new XML::SaxParser instance.
|
58
|
-
*/
|
59
|
-
VALUE
|
60
|
-
ruby_xml_sax_parser_new(VALUE class) {
|
61
|
-
ruby_xml_sax_parser *nodesp;
|
62
|
-
|
63
|
-
nodesp = ALLOC(ruby_xml_sax_parser);
|
64
|
-
nodesp->xsh = &rubySAXHandlerStruct;
|
65
|
-
|
66
|
-
nodesp->callbackHandler = Qnil;
|
67
|
-
nodesp->xpc = NULL;
|
68
|
-
nodesp->filename = Qnil;
|
69
|
-
nodesp->str = Qnil;
|
70
|
-
|
71
|
-
return(Data_Wrap_Struct(class, ruby_xml_sax_parser_mark,
|
72
|
-
ruby_xml_sax_parser_free, nodesp));
|
73
|
-
}
|
74
|
-
|
75
|
-
|
76
|
-
/*
|
77
|
-
* call-seq:
|
78
|
-
* sax_parser.callbacks -> #<XML::SaxParser::Callbacks subclass>
|
79
|
-
*
|
80
|
-
* Obtain the callbacks used by this parser.
|
81
|
-
*/
|
82
|
-
VALUE
|
83
|
-
ruby_xml_sax_parser_callbacks_get(VALUE self) {
|
84
|
-
ruby_xml_sax_parser *nodesp;
|
85
|
-
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
86
|
-
return(nodesp->callbackHandler);
|
87
|
-
}
|
88
|
-
|
89
|
-
|
90
|
-
/*
|
91
|
-
* call-seq:
|
92
|
-
* sax_parser.callbacks = #<XML::SaxParser::Callbacks subclass>
|
93
|
-
*
|
94
|
-
* Set the callbacks used by this parser. The value assigned to
|
95
|
-
* this attributesibute will usually be an object that extends the the
|
96
|
-
* XML::SaxParser::Callbacks module, overriding the callbacks it
|
97
|
-
* wishes to process.
|
98
|
-
*/
|
99
|
-
VALUE
|
100
|
-
ruby_xml_sax_parser_callbacks_set(VALUE self, VALUE callbacks) {
|
101
|
-
ruby_xml_sax_parser *nodesp;
|
102
|
-
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
103
|
-
nodesp->callbackHandler = callbacks;
|
104
|
-
return(nodesp->callbackHandler);
|
105
|
-
}
|
106
|
-
|
107
|
-
|
108
|
-
/*
|
109
|
-
* call-seq:
|
110
|
-
* sax_parser.filename -> "filename"
|
111
|
-
*
|
112
|
-
* Obtain the filename this parser reads from.
|
113
|
-
*/
|
114
|
-
VALUE
|
115
|
-
ruby_xml_sax_parser_filename_get(VALUE self) {
|
116
|
-
ruby_xml_sax_parser *nodesp;
|
117
|
-
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
118
|
-
return(nodesp->filename);
|
119
|
-
}
|
120
|
-
|
121
|
-
|
122
|
-
/*
|
123
|
-
* call-seq:
|
124
|
-
* sax_parser.filename = "filename"
|
125
|
-
*
|
126
|
-
* Set the filename this parser reads from.
|
127
|
-
*/
|
128
|
-
VALUE
|
129
|
-
ruby_xml_sax_parser_filename_set(VALUE self, VALUE filename) {
|
130
|
-
ruby_xml_sax_parser *nodesp;
|
131
|
-
Check_Type(filename, T_STRING);
|
132
|
-
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
133
|
-
nodesp->filename = filename;
|
134
|
-
return(nodesp->filename);
|
135
|
-
}
|
136
|
-
|
137
|
-
|
138
|
-
/*
|
139
|
-
* call-seq:
|
140
|
-
* parser.parse -> (true|false)
|
141
|
-
*
|
142
|
-
* Parse the input XML, generating callbacks to the object
|
143
|
-
* registered via the +callbacks+ attributesibute.
|
144
|
-
*/
|
145
|
-
VALUE
|
146
|
-
ruby_xml_sax_parser_parse(VALUE self) {
|
147
|
-
char *str;
|
148
|
-
int status = 1;
|
149
|
-
ruby_xml_sax_parser *nodesp;
|
150
|
-
|
151
|
-
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
152
|
-
|
153
|
-
if (nodesp->filename != Qnil) {
|
154
|
-
status = xmlSAXUserParseFile(nodesp->xsh, nodesp, StringValuePtr(nodesp->filename));
|
155
|
-
} else if (nodesp->str != Qnil) {
|
156
|
-
str = StringValuePtr(nodesp->str);
|
157
|
-
status = //ruby_xml_document_new(cXMLDocument,
|
158
|
-
xmlSAXUserParseMemory(nodesp->xsh, nodesp,
|
159
|
-
str, strlen(str)); //);
|
160
|
-
}
|
161
|
-
|
162
|
-
/* XXX This should return an exception for the various error codes
|
163
|
-
* that can come back in status, but I'm too lazy to do that right
|
164
|
-
* now. */
|
165
|
-
if (status)
|
166
|
-
return(Qfalse);
|
167
|
-
else
|
168
|
-
return(Qtrue);
|
169
|
-
}
|
170
|
-
|
171
|
-
|
172
|
-
/*
|
173
|
-
* call-seq:
|
174
|
-
* parser.string -> "xml"
|
175
|
-
*
|
176
|
-
* Obtain the parser's input string.
|
177
|
-
*/
|
178
|
-
VALUE
|
179
|
-
ruby_xml_sax_parser_str_get(VALUE self) {
|
180
|
-
ruby_xml_sax_parser *nodesp;
|
181
|
-
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
182
|
-
return(nodesp->str);
|
183
|
-
}
|
184
|
-
|
185
|
-
|
186
|
-
/*
|
187
|
-
* call-seq:
|
188
|
-
* parser.string = "xml"
|
189
|
-
*
|
190
|
-
* Set the parser's input string.
|
191
|
-
*/
|
192
|
-
VALUE
|
193
|
-
ruby_xml_sax_parser_str_set(VALUE self, VALUE str) {
|
194
|
-
ruby_xml_sax_parser *nodesp;
|
195
|
-
Check_Type(str, T_STRING);
|
196
|
-
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
197
|
-
nodesp->str = str;
|
198
|
-
return(nodesp->str);
|
199
|
-
}
|
200
|
-
|
201
|
-
|
202
|
-
/****** SaxCallbacks ******/
|
203
|
-
/* These are all the same. Bloody Rdoc... */
|
204
|
-
|
205
|
-
/*
|
206
|
-
* call-seq:
|
207
|
-
* callbacks.on_internal_subset(name, external_id, system_id)
|
208
|
-
*
|
209
|
-
* Called for an internal subset event.
|
210
|
-
*/
|
211
|
-
VALUE
|
212
|
-
ruby_xml_sax_callbacks_on_internal_subset(int argc, VALUE *argv, VALUE self) {
|
213
|
-
return Qnil;
|
214
|
-
}
|
215
|
-
|
216
|
-
|
217
|
-
/*
|
218
|
-
* call-seq:
|
219
|
-
* callbacks.on_is_standalone()
|
220
|
-
*
|
221
|
-
* Called for 'is standalone' event.
|
222
|
-
*/
|
223
|
-
VALUE
|
224
|
-
ruby_xml_sax_callbacks_on_is_standalone(int argc, VALUE *argv, VALUE self) {
|
225
|
-
return Qnil;
|
226
|
-
}
|
227
|
-
|
228
|
-
|
229
|
-
/*
|
230
|
-
* call-seq:
|
231
|
-
* callbacks.on_has_internal_subset()
|
232
|
-
*
|
233
|
-
* Called for an internal subset notification event.
|
234
|
-
*/
|
235
|
-
VALUE
|
236
|
-
ruby_xml_sax_callbacks_on_has_internal_subset(int argc, VALUE *argv, VALUE self) {
|
237
|
-
return Qnil;
|
238
|
-
}
|
239
|
-
|
240
|
-
|
241
|
-
/*
|
242
|
-
* call-seq:
|
243
|
-
* callbacks.on_has_external_subset()
|
244
|
-
*
|
245
|
-
* Called for an external subset notification event.
|
246
|
-
*/
|
247
|
-
VALUE
|
248
|
-
ruby_xml_sax_callbacks_on_has_external_subset(int argc, VALUE *argv, VALUE self) {
|
249
|
-
return Qnil;
|
250
|
-
}
|
251
|
-
|
252
|
-
|
253
|
-
/*
|
254
|
-
* call-seq:
|
255
|
-
* callbacks.on_start_document()
|
256
|
-
*
|
257
|
-
* Called for a start document event.
|
258
|
-
*/
|
259
|
-
VALUE
|
260
|
-
ruby_xml_sax_callbacks_on_start_document(int argc, VALUE *argv, VALUE self) {
|
261
|
-
return Qnil;
|
262
|
-
}
|
263
|
-
|
264
|
-
|
265
|
-
/*
|
266
|
-
* call-seq:
|
267
|
-
* callbacks.on_end_document()
|
268
|
-
*
|
269
|
-
* Called for an end document event.
|
270
|
-
*/
|
271
|
-
VALUE
|
272
|
-
ruby_xml_sax_callbacks_on_end_document(int argc, VALUE *argv, VALUE self) {
|
273
|
-
return Qnil;
|
274
|
-
}
|
275
|
-
|
276
|
-
|
277
|
-
/*
|
278
|
-
* call-seq:
|
279
|
-
* callbacks.on_start_element(name, attributes_hash)
|
280
|
-
*
|
281
|
-
* Called for an element start event.
|
282
|
-
*/
|
283
|
-
VALUE
|
284
|
-
ruby_xml_sax_callbacks_on_start_element(int argc, VALUE *argv, VALUE self) {
|
285
|
-
return Qnil;
|
286
|
-
}
|
287
|
-
|
288
|
-
|
289
|
-
/*
|
290
|
-
* call-seq:
|
291
|
-
* callbacks.on_end_element(name)
|
292
|
-
*
|
293
|
-
* Called for an element end event.
|
294
|
-
*/
|
295
|
-
VALUE
|
296
|
-
ruby_xml_sax_callbacks_on_end_element(int argc, VALUE *argv, VALUE self) {
|
297
|
-
return Qnil;
|
298
|
-
}
|
299
|
-
|
300
|
-
|
301
|
-
/*
|
302
|
-
* call-seq:
|
303
|
-
* callbacks.on_reference(name)
|
304
|
-
*
|
305
|
-
* Called for a reference event.
|
306
|
-
*/
|
307
|
-
VALUE
|
308
|
-
ruby_xml_sax_callbacks_on_reference(int argc, VALUE *argv, VALUE self) {
|
309
|
-
return Qnil;
|
310
|
-
}
|
311
|
-
|
312
|
-
|
313
|
-
/*
|
314
|
-
* call-seq:
|
315
|
-
* callbacks.on_characters(chars)
|
316
|
-
*
|
317
|
-
* Called for a characters event.
|
318
|
-
*/
|
319
|
-
VALUE
|
320
|
-
ruby_xml_sax_callbacks_on_characters(int argc, VALUE *argv, VALUE self) {
|
321
|
-
return Qnil;
|
322
|
-
}
|
323
|
-
|
324
|
-
|
325
|
-
/*
|
326
|
-
* call-seq:
|
327
|
-
* callbacks.on_processing_instruction(target, data)
|
328
|
-
*
|
329
|
-
* Called for an processing instruction event.
|
330
|
-
*/
|
331
|
-
VALUE
|
332
|
-
ruby_xml_sax_callbacks_on_processing_instruction(int argc, VALUE *argv, VALUE self) {
|
333
|
-
return Qnil;
|
334
|
-
}
|
335
|
-
|
336
|
-
|
337
|
-
/*
|
338
|
-
* call-seq:
|
339
|
-
* callbacks.on_comment(msg)
|
340
|
-
*
|
341
|
-
* Called for a comment event.
|
342
|
-
*/
|
343
|
-
VALUE
|
344
|
-
ruby_xml_sax_callbacks_on_comment(int argc, VALUE *argv, VALUE self) {
|
345
|
-
return Qnil;
|
346
|
-
}
|
347
|
-
|
348
|
-
|
349
|
-
/*
|
350
|
-
* call-seq:
|
351
|
-
* callbacks.on_parser_warning(msg)
|
352
|
-
*
|
353
|
-
* Called for parser warnings.
|
354
|
-
*/
|
355
|
-
VALUE
|
356
|
-
ruby_xml_sax_callbacks_on_parser_warning(int argc, VALUE *argv, VALUE self) {
|
357
|
-
return Qnil;
|
358
|
-
}
|
359
|
-
|
360
|
-
|
361
|
-
/*
|
362
|
-
* call-seq:
|
363
|
-
* callbacks.on_parser_error(msg)
|
364
|
-
*
|
365
|
-
* Called for parser errors.
|
366
|
-
*/
|
367
|
-
VALUE
|
368
|
-
ruby_xml_sax_callbacks_on_parser_error(int argc, VALUE *argv, VALUE self) {
|
369
|
-
return Qnil;
|
370
|
-
}
|
371
|
-
|
372
|
-
|
373
|
-
/*
|
374
|
-
* call-seq:
|
375
|
-
* callbacks.on_parser_fatal_error(msg)
|
376
|
-
*
|
377
|
-
* Called for fatal parser errors.
|
378
|
-
*/
|
379
|
-
VALUE
|
380
|
-
ruby_xml_sax_callbacks_on_parser_fatal_error(int argc, VALUE *argv, VALUE self) {
|
381
|
-
return Qnil;
|
382
|
-
}
|
383
|
-
|
384
|
-
/*
|
385
|
-
* call-seq:
|
386
|
-
* callbacks.on_cdata_block(cdata)
|
387
|
-
*
|
388
|
-
* Called for a CDATA block event.
|
389
|
-
*/
|
390
|
-
VALUE
|
391
|
-
ruby_xml_sax_callbacks_on_cdata_block(int argc, VALUE *argv, VALUE self) {
|
392
|
-
return Qnil;
|
393
|
-
}
|
394
|
-
|
395
|
-
/*
|
396
|
-
* call-seq:
|
397
|
-
* callbacks.on_external_subset(name, external_id, system_id)
|
398
|
-
*
|
399
|
-
* Called for an external subset event.
|
400
|
-
*/
|
401
|
-
VALUE
|
402
|
-
ruby_xml_sax_callbacks_on_external_subset(int argc, VALUE *argv, VALUE self) {
|
403
|
-
return Qnil;
|
404
|
-
}
|
405
|
-
|
406
|
-
|
407
|
-
// Rdoc needs to know
|
408
|
-
#ifdef RDOC_NEVER_DEFINED
|
409
|
-
mLibXML = rb_define_module("LibXML");
|
410
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
411
|
-
#endif
|
412
|
-
|
413
|
-
void
|
414
|
-
ruby_init_xml_sax_parser(void) {
|
415
|
-
cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject);
|
416
|
-
mXMLSaxParserCallbacks = rb_define_module_under(cXMLSaxParser, "Callbacks");
|
417
|
-
|
418
|
-
/* SaxParser */
|
419
|
-
rb_define_singleton_method(cXMLSaxParser, "new", ruby_xml_sax_parser_new, 0);
|
420
|
-
|
421
|
-
rb_define_method(cXMLSaxParser, "filename",
|
422
|
-
ruby_xml_sax_parser_filename_get, 0);
|
423
|
-
rb_define_method(cXMLSaxParser, "filename=",
|
424
|
-
ruby_xml_sax_parser_filename_set, 1);
|
425
|
-
rb_define_method(cXMLSaxParser, "callbacks",
|
426
|
-
ruby_xml_sax_parser_callbacks_get, 0);
|
427
|
-
rb_define_method(cXMLSaxParser, "callbacks=",
|
428
|
-
ruby_xml_sax_parser_callbacks_set, 1);
|
429
|
-
rb_define_method(cXMLSaxParser, "parse", ruby_xml_sax_parser_parse, 0);
|
430
|
-
rb_define_method(cXMLSaxParser, "string", ruby_xml_sax_parser_str_get, 0);
|
431
|
-
rb_define_method(cXMLSaxParser, "string=", ruby_xml_sax_parser_str_set, 1);
|
432
|
-
|
433
|
-
/* SaxCallbacks */
|
434
|
-
cbidOnInternalSubset = rb_intern("on_internal_subset");
|
435
|
-
cbidOnIsStandalone = rb_intern("on_is_standalone");
|
436
|
-
cbidOnHasInternalSubset = rb_intern("on_has_internal_subset");
|
437
|
-
cbidOnHasExternalSubset = rb_intern("on_has_external_subset");
|
438
|
-
cbidOnStartDocument = rb_intern("on_start_document");
|
439
|
-
cbidOnEndDocument = rb_intern("on_end_document");
|
440
|
-
cbidOnStartElement = rb_intern("on_start_element");
|
441
|
-
cbidOnEndElement = rb_intern("on_end_element");
|
442
|
-
cbidOnReference = rb_intern("on_reference");
|
443
|
-
cbidOnCharacters = rb_intern("on_characters");
|
444
|
-
cbidOnProcessingInstruction = rb_intern("on_processing_instruction");
|
445
|
-
cbidOnComment = rb_intern("on_comment");
|
446
|
-
cbidOnXmlParserWarning = rb_intern("on_parser_warning");
|
447
|
-
cbidOnXmlParserError = rb_intern("on_parser_error");
|
448
|
-
cbidOnXmlParserFatalError = rb_intern("on_parser_fatal_error");
|
449
|
-
cbidOnCdataBlock = rb_intern("on_cdata_block");
|
450
|
-
cbidOnExternalSubset = rb_intern("on_external_subset");
|
451
|
-
|
452
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_internal_subset",
|
453
|
-
ruby_xml_sax_callbacks_on_internal_subset, -1);
|
454
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_is_standalone",
|
455
|
-
ruby_xml_sax_callbacks_on_is_standalone, -1);
|
456
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_has_internal_subset",
|
457
|
-
ruby_xml_sax_callbacks_on_has_internal_subset, -1);
|
458
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_has_external_subset",
|
459
|
-
ruby_xml_sax_callbacks_on_has_external_subset, -1);
|
460
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_start_document",
|
461
|
-
ruby_xml_sax_callbacks_on_start_document, -1);
|
462
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_end_document",
|
463
|
-
ruby_xml_sax_callbacks_on_end_document, -1);
|
464
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_start_element",
|
465
|
-
ruby_xml_sax_callbacks_on_start_element, -1);
|
466
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_end_element",
|
467
|
-
ruby_xml_sax_callbacks_on_end_element, -1);
|
468
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_reference",
|
469
|
-
ruby_xml_sax_callbacks_on_reference, -1);
|
470
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_characters",
|
471
|
-
ruby_xml_sax_callbacks_on_characters, -1);
|
472
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_processing_instruction",
|
473
|
-
ruby_xml_sax_callbacks_on_processing_instruction, -1);
|
474
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_comment",
|
475
|
-
ruby_xml_sax_callbacks_on_comment, -1);
|
476
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_parser_warning",
|
477
|
-
ruby_xml_sax_callbacks_on_parser_warning, -1);
|
478
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_parser_error",
|
479
|
-
ruby_xml_sax_callbacks_on_parser_error, -1);
|
480
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_parser_fatal_error",
|
481
|
-
ruby_xml_sax_callbacks_on_parser_fatal_error, -1);
|
482
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_cdata_block",
|
483
|
-
ruby_xml_sax_callbacks_on_cdata_block, -1);
|
484
|
-
rb_define_method(mXMLSaxParserCallbacks, "on_external_subset",
|
485
|
-
ruby_xml_sax_callbacks_on_external_subset, -1);
|
486
|
-
}
|
1
|
+
/* $Id: ruby_xml_sax_parser.c 461 2008-07-15 21:35:56Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "ruby_libxml.h"
|
6
|
+
#include "ruby_xml_sax_parser.h"
|
7
|
+
|
8
|
+
VALUE cXMLSaxParser;
|
9
|
+
VALUE mXMLSaxParserCallbacks;
|
10
|
+
|
11
|
+
VALUE cbidOnInternalSubset;
|
12
|
+
VALUE cbidOnIsStandalone;
|
13
|
+
VALUE cbidOnHasInternalSubset;
|
14
|
+
VALUE cbidOnHasExternalSubset;
|
15
|
+
VALUE cbidOnStartDocument;
|
16
|
+
VALUE cbidOnEndDocument;
|
17
|
+
VALUE cbidOnStartElement;
|
18
|
+
VALUE cbidOnEndElement;
|
19
|
+
VALUE cbidOnReference;
|
20
|
+
VALUE cbidOnCharacters;
|
21
|
+
VALUE cbidOnProcessingInstruction;
|
22
|
+
VALUE cbidOnComment;
|
23
|
+
VALUE cbidOnXmlParserWarning;
|
24
|
+
VALUE cbidOnXmlParserError;
|
25
|
+
VALUE cbidOnXmlParserFatalError;
|
26
|
+
VALUE cbidOnCdataBlock;
|
27
|
+
VALUE cbidOnExternalSubset;
|
28
|
+
|
29
|
+
#include "sax_parser_callbacks.inc"
|
30
|
+
|
31
|
+
void
|
32
|
+
ruby_xml_sax_parser_free(ruby_xml_sax_parser *nodesp) {
|
33
|
+
/* Apparently this isn't needed: time will tell */
|
34
|
+
/* if (nodesp->xsh != NULL) */
|
35
|
+
/* xmlFreeSax_Parser(nodesp->sax_parser); */
|
36
|
+
}
|
37
|
+
|
38
|
+
void
|
39
|
+
ruby_xml_sax_parser_mark(ruby_xml_sax_parser *nodesp) {
|
40
|
+
if (nodesp->callbackHandler && (nodesp->callbackHandler != Qnil)) {
|
41
|
+
rb_gc_mark(nodesp->callbackHandler);
|
42
|
+
}
|
43
|
+
|
44
|
+
if (nodesp->filename && (nodesp->filename != Qnil)) {
|
45
|
+
rb_gc_mark(nodesp->filename);
|
46
|
+
}
|
47
|
+
|
48
|
+
if (nodesp->str && (nodesp->str != Qnil)) {
|
49
|
+
rb_gc_mark(nodesp->str);
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
* call-seq:
|
55
|
+
* XML::SaxParser.new -> sax_parser
|
56
|
+
*
|
57
|
+
* Create a new XML::SaxParser instance.
|
58
|
+
*/
|
59
|
+
VALUE
|
60
|
+
ruby_xml_sax_parser_new(VALUE class) {
|
61
|
+
ruby_xml_sax_parser *nodesp;
|
62
|
+
|
63
|
+
nodesp = ALLOC(ruby_xml_sax_parser);
|
64
|
+
nodesp->xsh = &rubySAXHandlerStruct;
|
65
|
+
|
66
|
+
nodesp->callbackHandler = Qnil;
|
67
|
+
nodesp->xpc = NULL;
|
68
|
+
nodesp->filename = Qnil;
|
69
|
+
nodesp->str = Qnil;
|
70
|
+
|
71
|
+
return(Data_Wrap_Struct(class, ruby_xml_sax_parser_mark,
|
72
|
+
ruby_xml_sax_parser_free, nodesp));
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
/*
|
77
|
+
* call-seq:
|
78
|
+
* sax_parser.callbacks -> #<XML::SaxParser::Callbacks subclass>
|
79
|
+
*
|
80
|
+
* Obtain the callbacks used by this parser.
|
81
|
+
*/
|
82
|
+
VALUE
|
83
|
+
ruby_xml_sax_parser_callbacks_get(VALUE self) {
|
84
|
+
ruby_xml_sax_parser *nodesp;
|
85
|
+
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
86
|
+
return(nodesp->callbackHandler);
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
/*
|
91
|
+
* call-seq:
|
92
|
+
* sax_parser.callbacks = #<XML::SaxParser::Callbacks subclass>
|
93
|
+
*
|
94
|
+
* Set the callbacks used by this parser. The value assigned to
|
95
|
+
* this attributesibute will usually be an object that extends the the
|
96
|
+
* XML::SaxParser::Callbacks module, overriding the callbacks it
|
97
|
+
* wishes to process.
|
98
|
+
*/
|
99
|
+
VALUE
|
100
|
+
ruby_xml_sax_parser_callbacks_set(VALUE self, VALUE callbacks) {
|
101
|
+
ruby_xml_sax_parser *nodesp;
|
102
|
+
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
103
|
+
nodesp->callbackHandler = callbacks;
|
104
|
+
return(nodesp->callbackHandler);
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
/*
|
109
|
+
* call-seq:
|
110
|
+
* sax_parser.filename -> "filename"
|
111
|
+
*
|
112
|
+
* Obtain the filename this parser reads from.
|
113
|
+
*/
|
114
|
+
VALUE
|
115
|
+
ruby_xml_sax_parser_filename_get(VALUE self) {
|
116
|
+
ruby_xml_sax_parser *nodesp;
|
117
|
+
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
118
|
+
return(nodesp->filename);
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
/*
|
123
|
+
* call-seq:
|
124
|
+
* sax_parser.filename = "filename"
|
125
|
+
*
|
126
|
+
* Set the filename this parser reads from.
|
127
|
+
*/
|
128
|
+
VALUE
|
129
|
+
ruby_xml_sax_parser_filename_set(VALUE self, VALUE filename) {
|
130
|
+
ruby_xml_sax_parser *nodesp;
|
131
|
+
Check_Type(filename, T_STRING);
|
132
|
+
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
133
|
+
nodesp->filename = filename;
|
134
|
+
return(nodesp->filename);
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
/*
|
139
|
+
* call-seq:
|
140
|
+
* parser.parse -> (true|false)
|
141
|
+
*
|
142
|
+
* Parse the input XML, generating callbacks to the object
|
143
|
+
* registered via the +callbacks+ attributesibute.
|
144
|
+
*/
|
145
|
+
VALUE
|
146
|
+
ruby_xml_sax_parser_parse(VALUE self) {
|
147
|
+
char *str;
|
148
|
+
int status = 1;
|
149
|
+
ruby_xml_sax_parser *nodesp;
|
150
|
+
|
151
|
+
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
152
|
+
|
153
|
+
if (nodesp->filename != Qnil) {
|
154
|
+
status = xmlSAXUserParseFile(nodesp->xsh, nodesp, StringValuePtr(nodesp->filename));
|
155
|
+
} else if (nodesp->str != Qnil) {
|
156
|
+
str = StringValuePtr(nodesp->str);
|
157
|
+
status = //ruby_xml_document_new(cXMLDocument,
|
158
|
+
xmlSAXUserParseMemory(nodesp->xsh, nodesp,
|
159
|
+
str, strlen(str)); //);
|
160
|
+
}
|
161
|
+
|
162
|
+
/* XXX This should return an exception for the various error codes
|
163
|
+
* that can come back in status, but I'm too lazy to do that right
|
164
|
+
* now. */
|
165
|
+
if (status)
|
166
|
+
return(Qfalse);
|
167
|
+
else
|
168
|
+
return(Qtrue);
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
/*
|
173
|
+
* call-seq:
|
174
|
+
* parser.string -> "xml"
|
175
|
+
*
|
176
|
+
* Obtain the parser's input string.
|
177
|
+
*/
|
178
|
+
VALUE
|
179
|
+
ruby_xml_sax_parser_str_get(VALUE self) {
|
180
|
+
ruby_xml_sax_parser *nodesp;
|
181
|
+
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
182
|
+
return(nodesp->str);
|
183
|
+
}
|
184
|
+
|
185
|
+
|
186
|
+
/*
|
187
|
+
* call-seq:
|
188
|
+
* parser.string = "xml"
|
189
|
+
*
|
190
|
+
* Set the parser's input string.
|
191
|
+
*/
|
192
|
+
VALUE
|
193
|
+
ruby_xml_sax_parser_str_set(VALUE self, VALUE str) {
|
194
|
+
ruby_xml_sax_parser *nodesp;
|
195
|
+
Check_Type(str, T_STRING);
|
196
|
+
Data_Get_Struct(self, ruby_xml_sax_parser, nodesp);
|
197
|
+
nodesp->str = str;
|
198
|
+
return(nodesp->str);
|
199
|
+
}
|
200
|
+
|
201
|
+
|
202
|
+
/****** SaxCallbacks ******/
|
203
|
+
/* These are all the same. Bloody Rdoc... */
|
204
|
+
|
205
|
+
/*
|
206
|
+
* call-seq:
|
207
|
+
* callbacks.on_internal_subset(name, external_id, system_id)
|
208
|
+
*
|
209
|
+
* Called for an internal subset event.
|
210
|
+
*/
|
211
|
+
VALUE
|
212
|
+
ruby_xml_sax_callbacks_on_internal_subset(int argc, VALUE *argv, VALUE self) {
|
213
|
+
return Qnil;
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
/*
|
218
|
+
* call-seq:
|
219
|
+
* callbacks.on_is_standalone()
|
220
|
+
*
|
221
|
+
* Called for 'is standalone' event.
|
222
|
+
*/
|
223
|
+
VALUE
|
224
|
+
ruby_xml_sax_callbacks_on_is_standalone(int argc, VALUE *argv, VALUE self) {
|
225
|
+
return Qnil;
|
226
|
+
}
|
227
|
+
|
228
|
+
|
229
|
+
/*
|
230
|
+
* call-seq:
|
231
|
+
* callbacks.on_has_internal_subset()
|
232
|
+
*
|
233
|
+
* Called for an internal subset notification event.
|
234
|
+
*/
|
235
|
+
VALUE
|
236
|
+
ruby_xml_sax_callbacks_on_has_internal_subset(int argc, VALUE *argv, VALUE self) {
|
237
|
+
return Qnil;
|
238
|
+
}
|
239
|
+
|
240
|
+
|
241
|
+
/*
|
242
|
+
* call-seq:
|
243
|
+
* callbacks.on_has_external_subset()
|
244
|
+
*
|
245
|
+
* Called for an external subset notification event.
|
246
|
+
*/
|
247
|
+
VALUE
|
248
|
+
ruby_xml_sax_callbacks_on_has_external_subset(int argc, VALUE *argv, VALUE self) {
|
249
|
+
return Qnil;
|
250
|
+
}
|
251
|
+
|
252
|
+
|
253
|
+
/*
|
254
|
+
* call-seq:
|
255
|
+
* callbacks.on_start_document()
|
256
|
+
*
|
257
|
+
* Called for a start document event.
|
258
|
+
*/
|
259
|
+
VALUE
|
260
|
+
ruby_xml_sax_callbacks_on_start_document(int argc, VALUE *argv, VALUE self) {
|
261
|
+
return Qnil;
|
262
|
+
}
|
263
|
+
|
264
|
+
|
265
|
+
/*
|
266
|
+
* call-seq:
|
267
|
+
* callbacks.on_end_document()
|
268
|
+
*
|
269
|
+
* Called for an end document event.
|
270
|
+
*/
|
271
|
+
VALUE
|
272
|
+
ruby_xml_sax_callbacks_on_end_document(int argc, VALUE *argv, VALUE self) {
|
273
|
+
return Qnil;
|
274
|
+
}
|
275
|
+
|
276
|
+
|
277
|
+
/*
|
278
|
+
* call-seq:
|
279
|
+
* callbacks.on_start_element(name, attributes_hash)
|
280
|
+
*
|
281
|
+
* Called for an element start event.
|
282
|
+
*/
|
283
|
+
VALUE
|
284
|
+
ruby_xml_sax_callbacks_on_start_element(int argc, VALUE *argv, VALUE self) {
|
285
|
+
return Qnil;
|
286
|
+
}
|
287
|
+
|
288
|
+
|
289
|
+
/*
|
290
|
+
* call-seq:
|
291
|
+
* callbacks.on_end_element(name)
|
292
|
+
*
|
293
|
+
* Called for an element end event.
|
294
|
+
*/
|
295
|
+
VALUE
|
296
|
+
ruby_xml_sax_callbacks_on_end_element(int argc, VALUE *argv, VALUE self) {
|
297
|
+
return Qnil;
|
298
|
+
}
|
299
|
+
|
300
|
+
|
301
|
+
/*
|
302
|
+
* call-seq:
|
303
|
+
* callbacks.on_reference(name)
|
304
|
+
*
|
305
|
+
* Called for a reference event.
|
306
|
+
*/
|
307
|
+
VALUE
|
308
|
+
ruby_xml_sax_callbacks_on_reference(int argc, VALUE *argv, VALUE self) {
|
309
|
+
return Qnil;
|
310
|
+
}
|
311
|
+
|
312
|
+
|
313
|
+
/*
|
314
|
+
* call-seq:
|
315
|
+
* callbacks.on_characters(chars)
|
316
|
+
*
|
317
|
+
* Called for a characters event.
|
318
|
+
*/
|
319
|
+
VALUE
|
320
|
+
ruby_xml_sax_callbacks_on_characters(int argc, VALUE *argv, VALUE self) {
|
321
|
+
return Qnil;
|
322
|
+
}
|
323
|
+
|
324
|
+
|
325
|
+
/*
|
326
|
+
* call-seq:
|
327
|
+
* callbacks.on_processing_instruction(target, data)
|
328
|
+
*
|
329
|
+
* Called for an processing instruction event.
|
330
|
+
*/
|
331
|
+
VALUE
|
332
|
+
ruby_xml_sax_callbacks_on_processing_instruction(int argc, VALUE *argv, VALUE self) {
|
333
|
+
return Qnil;
|
334
|
+
}
|
335
|
+
|
336
|
+
|
337
|
+
/*
|
338
|
+
* call-seq:
|
339
|
+
* callbacks.on_comment(msg)
|
340
|
+
*
|
341
|
+
* Called for a comment event.
|
342
|
+
*/
|
343
|
+
VALUE
|
344
|
+
ruby_xml_sax_callbacks_on_comment(int argc, VALUE *argv, VALUE self) {
|
345
|
+
return Qnil;
|
346
|
+
}
|
347
|
+
|
348
|
+
|
349
|
+
/*
|
350
|
+
* call-seq:
|
351
|
+
* callbacks.on_parser_warning(msg)
|
352
|
+
*
|
353
|
+
* Called for parser warnings.
|
354
|
+
*/
|
355
|
+
VALUE
|
356
|
+
ruby_xml_sax_callbacks_on_parser_warning(int argc, VALUE *argv, VALUE self) {
|
357
|
+
return Qnil;
|
358
|
+
}
|
359
|
+
|
360
|
+
|
361
|
+
/*
|
362
|
+
* call-seq:
|
363
|
+
* callbacks.on_parser_error(msg)
|
364
|
+
*
|
365
|
+
* Called for parser errors.
|
366
|
+
*/
|
367
|
+
VALUE
|
368
|
+
ruby_xml_sax_callbacks_on_parser_error(int argc, VALUE *argv, VALUE self) {
|
369
|
+
return Qnil;
|
370
|
+
}
|
371
|
+
|
372
|
+
|
373
|
+
/*
|
374
|
+
* call-seq:
|
375
|
+
* callbacks.on_parser_fatal_error(msg)
|
376
|
+
*
|
377
|
+
* Called for fatal parser errors.
|
378
|
+
*/
|
379
|
+
VALUE
|
380
|
+
ruby_xml_sax_callbacks_on_parser_fatal_error(int argc, VALUE *argv, VALUE self) {
|
381
|
+
return Qnil;
|
382
|
+
}
|
383
|
+
|
384
|
+
/*
|
385
|
+
* call-seq:
|
386
|
+
* callbacks.on_cdata_block(cdata)
|
387
|
+
*
|
388
|
+
* Called for a CDATA block event.
|
389
|
+
*/
|
390
|
+
VALUE
|
391
|
+
ruby_xml_sax_callbacks_on_cdata_block(int argc, VALUE *argv, VALUE self) {
|
392
|
+
return Qnil;
|
393
|
+
}
|
394
|
+
|
395
|
+
/*
|
396
|
+
* call-seq:
|
397
|
+
* callbacks.on_external_subset(name, external_id, system_id)
|
398
|
+
*
|
399
|
+
* Called for an external subset event.
|
400
|
+
*/
|
401
|
+
VALUE
|
402
|
+
ruby_xml_sax_callbacks_on_external_subset(int argc, VALUE *argv, VALUE self) {
|
403
|
+
return Qnil;
|
404
|
+
}
|
405
|
+
|
406
|
+
|
407
|
+
// Rdoc needs to know
|
408
|
+
#ifdef RDOC_NEVER_DEFINED
|
409
|
+
mLibXML = rb_define_module("LibXML");
|
410
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
411
|
+
#endif
|
412
|
+
|
413
|
+
void
|
414
|
+
ruby_init_xml_sax_parser(void) {
|
415
|
+
cXMLSaxParser = rb_define_class_under(mXML, "SaxParser", rb_cObject);
|
416
|
+
mXMLSaxParserCallbacks = rb_define_module_under(cXMLSaxParser, "Callbacks");
|
417
|
+
|
418
|
+
/* SaxParser */
|
419
|
+
rb_define_singleton_method(cXMLSaxParser, "new", ruby_xml_sax_parser_new, 0);
|
420
|
+
|
421
|
+
rb_define_method(cXMLSaxParser, "filename",
|
422
|
+
ruby_xml_sax_parser_filename_get, 0);
|
423
|
+
rb_define_method(cXMLSaxParser, "filename=",
|
424
|
+
ruby_xml_sax_parser_filename_set, 1);
|
425
|
+
rb_define_method(cXMLSaxParser, "callbacks",
|
426
|
+
ruby_xml_sax_parser_callbacks_get, 0);
|
427
|
+
rb_define_method(cXMLSaxParser, "callbacks=",
|
428
|
+
ruby_xml_sax_parser_callbacks_set, 1);
|
429
|
+
rb_define_method(cXMLSaxParser, "parse", ruby_xml_sax_parser_parse, 0);
|
430
|
+
rb_define_method(cXMLSaxParser, "string", ruby_xml_sax_parser_str_get, 0);
|
431
|
+
rb_define_method(cXMLSaxParser, "string=", ruby_xml_sax_parser_str_set, 1);
|
432
|
+
|
433
|
+
/* SaxCallbacks */
|
434
|
+
cbidOnInternalSubset = rb_intern("on_internal_subset");
|
435
|
+
cbidOnIsStandalone = rb_intern("on_is_standalone");
|
436
|
+
cbidOnHasInternalSubset = rb_intern("on_has_internal_subset");
|
437
|
+
cbidOnHasExternalSubset = rb_intern("on_has_external_subset");
|
438
|
+
cbidOnStartDocument = rb_intern("on_start_document");
|
439
|
+
cbidOnEndDocument = rb_intern("on_end_document");
|
440
|
+
cbidOnStartElement = rb_intern("on_start_element");
|
441
|
+
cbidOnEndElement = rb_intern("on_end_element");
|
442
|
+
cbidOnReference = rb_intern("on_reference");
|
443
|
+
cbidOnCharacters = rb_intern("on_characters");
|
444
|
+
cbidOnProcessingInstruction = rb_intern("on_processing_instruction");
|
445
|
+
cbidOnComment = rb_intern("on_comment");
|
446
|
+
cbidOnXmlParserWarning = rb_intern("on_parser_warning");
|
447
|
+
cbidOnXmlParserError = rb_intern("on_parser_error");
|
448
|
+
cbidOnXmlParserFatalError = rb_intern("on_parser_fatal_error");
|
449
|
+
cbidOnCdataBlock = rb_intern("on_cdata_block");
|
450
|
+
cbidOnExternalSubset = rb_intern("on_external_subset");
|
451
|
+
|
452
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_internal_subset",
|
453
|
+
ruby_xml_sax_callbacks_on_internal_subset, -1);
|
454
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_is_standalone",
|
455
|
+
ruby_xml_sax_callbacks_on_is_standalone, -1);
|
456
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_has_internal_subset",
|
457
|
+
ruby_xml_sax_callbacks_on_has_internal_subset, -1);
|
458
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_has_external_subset",
|
459
|
+
ruby_xml_sax_callbacks_on_has_external_subset, -1);
|
460
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_start_document",
|
461
|
+
ruby_xml_sax_callbacks_on_start_document, -1);
|
462
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_end_document",
|
463
|
+
ruby_xml_sax_callbacks_on_end_document, -1);
|
464
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_start_element",
|
465
|
+
ruby_xml_sax_callbacks_on_start_element, -1);
|
466
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_end_element",
|
467
|
+
ruby_xml_sax_callbacks_on_end_element, -1);
|
468
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_reference",
|
469
|
+
ruby_xml_sax_callbacks_on_reference, -1);
|
470
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_characters",
|
471
|
+
ruby_xml_sax_callbacks_on_characters, -1);
|
472
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_processing_instruction",
|
473
|
+
ruby_xml_sax_callbacks_on_processing_instruction, -1);
|
474
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_comment",
|
475
|
+
ruby_xml_sax_callbacks_on_comment, -1);
|
476
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_parser_warning",
|
477
|
+
ruby_xml_sax_callbacks_on_parser_warning, -1);
|
478
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_parser_error",
|
479
|
+
ruby_xml_sax_callbacks_on_parser_error, -1);
|
480
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_parser_fatal_error",
|
481
|
+
ruby_xml_sax_callbacks_on_parser_fatal_error, -1);
|
482
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_cdata_block",
|
483
|
+
ruby_xml_sax_callbacks_on_cdata_block, -1);
|
484
|
+
rb_define_method(mXMLSaxParserCallbacks, "on_external_subset",
|
485
|
+
ruby_xml_sax_callbacks_on_external_subset, -1);
|
486
|
+
}
|