libxml-ruby 0.9.4 → 0.9.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +22 -0
- data/README +3 -1
- data/ext/libxml/cbg.c +86 -76
- data/ext/libxml/extconf.rb +2 -1
- data/ext/libxml/libxml.c +899 -885
- data/ext/libxml/ruby_libxml.h +65 -70
- data/ext/libxml/ruby_xml_attr.c +485 -500
- data/ext/libxml/ruby_xml_attributes.c +107 -106
- data/ext/libxml/ruby_xml_document.c +355 -356
- data/ext/libxml/ruby_xml_dtd.c +119 -117
- data/ext/libxml/ruby_xml_error.c +1112 -581
- data/ext/libxml/ruby_xml_html_parser.c +35 -34
- data/ext/libxml/ruby_xml_input.c +182 -187
- data/ext/libxml/ruby_xml_input_cbg.c +197 -179
- data/ext/libxml/ruby_xml_node.c +1529 -1566
- data/ext/libxml/ruby_xml_node.h +2 -2
- data/ext/libxml/ruby_xml_ns.c +150 -156
- data/ext/libxml/ruby_xml_parser.c +37 -36
- data/ext/libxml/ruby_xml_parser_context.c +657 -659
- data/ext/libxml/ruby_xml_reader.c +203 -209
- data/ext/libxml/ruby_xml_relaxng.c +29 -25
- data/ext/libxml/ruby_xml_sax_parser.c +33 -32
- data/ext/libxml/ruby_xml_schema.c +165 -161
- data/ext/libxml/ruby_xml_state.c +19 -21
- data/ext/libxml/ruby_xml_xinclude.c +24 -25
- data/ext/libxml/ruby_xml_xpath.c +108 -108
- data/ext/libxml/ruby_xml_xpath_context.c +305 -293
- data/ext/libxml/ruby_xml_xpath_expression.c +24 -24
- data/ext/libxml/ruby_xml_xpath_object.c +89 -96
- data/ext/libxml/ruby_xml_xpointer.c +107 -109
- data/ext/libxml/ruby_xml_xpointer.h +13 -13
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/Rakefile +1 -1
- data/ext/vc/libxml_ruby.vcproj +1 -1
- data/lib/libxml/error.rb +4 -4
- data/test/tc_node_edit.rb +14 -2
- data/test/tc_node_text.rb +9 -9
- metadata +2 -2
data/ext/libxml/ruby_xml_node.h
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_node.h
|
1
|
+
/* $Id: ruby_xml_node.h 649 2008-11-30 03:15:57Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -9,6 +9,6 @@ extern VALUE cXMLNode;
|
|
9
9
|
|
10
10
|
void ruby_init_xml_node(void);
|
11
11
|
void rxml_node_mark_common(xmlNodePtr xnode);
|
12
|
-
VALUE
|
12
|
+
VALUE rxml_node_wrap(VALUE class, xmlNodePtr xnode);
|
13
13
|
VALUE check_string_or_symbol(VALUE val);
|
14
14
|
#endif
|
data/ext/libxml/ruby_xml_ns.c
CHANGED
@@ -1,156 +1,150 @@
|
|
1
|
-
/* $Id: ruby_xml_ns.c
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
#include "ruby_libxml.h"
|
6
|
-
#include "ruby_xml_ns.h"
|
7
|
-
|
8
|
-
VALUE cXMLNS;
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
*
|
26
|
-
*
|
27
|
-
*
|
28
|
-
*
|
29
|
-
*
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
*
|
56
|
-
*
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
return(
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
*
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
cXMLNS
|
148
|
-
|
149
|
-
rb_define_method(cXMLNS, "
|
150
|
-
|
151
|
-
rb_define_method(cXMLNS, "href?", rxml_ns_href_q, 0);
|
152
|
-
rb_define_method(cXMLNS, "next", rxml_ns_next, 0);
|
153
|
-
rb_define_method(cXMLNS, "prefix", rxml_ns_prefix_get, 0);
|
154
|
-
rb_define_method(cXMLNS, "prefix?", rxml_ns_prefix_q, 0);
|
155
|
-
rb_define_method(cXMLNS, "to_s", rxml_ns_prefix_get, 0);
|
156
|
-
}
|
1
|
+
/* $Id: ruby_xml_ns.c 650 2008-11-30 03:40:22Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "ruby_libxml.h"
|
6
|
+
#include "ruby_xml_ns.h"
|
7
|
+
|
8
|
+
VALUE cXMLNS;
|
9
|
+
|
10
|
+
/* Document-class: LibXML::XML::NS
|
11
|
+
*
|
12
|
+
* The NS class is used to query information about
|
13
|
+
* xml namespaces associated with particular nodes.
|
14
|
+
* It can also be used to associate new namespaces
|
15
|
+
* with an node. */
|
16
|
+
|
17
|
+
static VALUE rxml_ns_alloc(VALUE klass)
|
18
|
+
{
|
19
|
+
return Data_Wrap_Struct(klass, NULL, NULL, NULL);
|
20
|
+
}
|
21
|
+
|
22
|
+
/*
|
23
|
+
* call-seq:
|
24
|
+
* initialize(node, "href", "prefix")
|
25
|
+
*
|
26
|
+
* Create a new namespace attached to the specified node with the
|
27
|
+
* give prefix and namespace.
|
28
|
+
*
|
29
|
+
* XML::NS.new(node, "xlink", "http://www.w3.org/1999/xlink")
|
30
|
+
*/
|
31
|
+
static VALUE rxml_ns_initialize(VALUE self, VALUE node, VALUE href,
|
32
|
+
VALUE prefix)
|
33
|
+
{
|
34
|
+
xmlNodePtr xnode;
|
35
|
+
xmlChar *xmlPrefix;
|
36
|
+
xmlNsPtr xns;
|
37
|
+
|
38
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
39
|
+
/* Prefix can be null - that means its the default namespace */
|
40
|
+
xmlPrefix = NIL_P(prefix) ? NULL : StringValuePtr(prefix);
|
41
|
+
xns = xmlNewNs(xnode, (xmlChar*) StringValuePtr(href), xmlPrefix);
|
42
|
+
|
43
|
+
DATA_PTR( self) = xns;
|
44
|
+
return self;
|
45
|
+
}
|
46
|
+
|
47
|
+
VALUE rxml_ns_wrap(xmlNsPtr xns)
|
48
|
+
{
|
49
|
+
return (Data_Wrap_Struct(cXMLNS, NULL, NULL, xns));
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* call-seq:
|
54
|
+
* ns.href -> "href"
|
55
|
+
*
|
56
|
+
* Obtain the namespace's href.
|
57
|
+
*/
|
58
|
+
static VALUE rxml_ns_href_get(VALUE self)
|
59
|
+
{
|
60
|
+
xmlNsPtr xns;
|
61
|
+
Data_Get_Struct(self, xmlNs, xns);
|
62
|
+
if (xns == NULL || xns->href == NULL)
|
63
|
+
return (Qnil);
|
64
|
+
else
|
65
|
+
return (rb_str_new2((const char*) xns->href));
|
66
|
+
}
|
67
|
+
|
68
|
+
/*
|
69
|
+
* call-seq:
|
70
|
+
* ns.href? -> (true|false)
|
71
|
+
*
|
72
|
+
* Determine whether this namespace has an href.
|
73
|
+
*/
|
74
|
+
static VALUE rxml_ns_href_q(VALUE self)
|
75
|
+
{
|
76
|
+
xmlNsPtr xns;
|
77
|
+
Data_Get_Struct(self, xmlNs, xns);
|
78
|
+
if (xns == NULL || xns->href == NULL)
|
79
|
+
return (Qfalse);
|
80
|
+
else
|
81
|
+
return (Qtrue);
|
82
|
+
}
|
83
|
+
|
84
|
+
/*
|
85
|
+
* call-seq:
|
86
|
+
* ns.next -> ns
|
87
|
+
*
|
88
|
+
* Obtain the next namespace.
|
89
|
+
*/
|
90
|
+
static VALUE rxml_ns_next(VALUE self)
|
91
|
+
{
|
92
|
+
xmlNsPtr xns;
|
93
|
+
Data_Get_Struct(self, xmlNs, xns);
|
94
|
+
if (xns == NULL || xns->next == NULL)
|
95
|
+
return (Qnil);
|
96
|
+
else
|
97
|
+
return (rxml_ns_wrap(xns->next));
|
98
|
+
}
|
99
|
+
|
100
|
+
/*
|
101
|
+
* call-seq:
|
102
|
+
* ns.prefix -> "prefix"
|
103
|
+
* ns.to_s -> "prefix"
|
104
|
+
*
|
105
|
+
* Obtain the namespace's prefix.
|
106
|
+
*/
|
107
|
+
static VALUE rxml_ns_prefix_get(VALUE self)
|
108
|
+
{
|
109
|
+
xmlNsPtr xns;
|
110
|
+
Data_Get_Struct(self, xmlNs, xns);
|
111
|
+
if (xns == NULL || xns->prefix == NULL)
|
112
|
+
return (Qnil);
|
113
|
+
else
|
114
|
+
return (rb_str_new2((const char*) xns->prefix));
|
115
|
+
}
|
116
|
+
|
117
|
+
/*
|
118
|
+
* call-seq:
|
119
|
+
* ns.prefix? -> (true|false)
|
120
|
+
*
|
121
|
+
* Determine whether this namespace has a prefix.
|
122
|
+
*/
|
123
|
+
static VALUE rxml_ns_prefix_q(VALUE self)
|
124
|
+
{
|
125
|
+
xmlNsPtr xns;
|
126
|
+
Data_Get_Struct(self, xmlNs, xns);
|
127
|
+
if (xns == NULL || xns->prefix == NULL)
|
128
|
+
return (Qfalse);
|
129
|
+
else
|
130
|
+
return (Qtrue);
|
131
|
+
}
|
132
|
+
|
133
|
+
// Rdoc needs to know
|
134
|
+
#ifdef RDOC_NEVER_DEFINED
|
135
|
+
mLibXML = rb_define_module("LibXML");
|
136
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
137
|
+
#endif
|
138
|
+
|
139
|
+
void ruby_init_xml_ns(void)
|
140
|
+
{
|
141
|
+
cXMLNS = rb_define_class_under(mXML, "NS", rb_cObject);
|
142
|
+
rb_define_alloc_func(cXMLNS, rxml_ns_alloc);
|
143
|
+
rb_define_method(cXMLNS, "initialize", rxml_ns_initialize, 3);
|
144
|
+
rb_define_method(cXMLNS, "href", rxml_ns_href_get, 0);
|
145
|
+
rb_define_method(cXMLNS, "href?", rxml_ns_href_q, 0);
|
146
|
+
rb_define_method(cXMLNS, "next", rxml_ns_next, 0);
|
147
|
+
rb_define_method(cXMLNS, "prefix", rxml_ns_prefix_get, 0);
|
148
|
+
rb_define_method(cXMLNS, "prefix?", rxml_ns_prefix_q, 0);
|
149
|
+
rb_define_method(cXMLNS, "to_s", rxml_ns_prefix_get, 0);
|
150
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_parser.c
|
1
|
+
/* $Id: ruby_xml_parser.c 650 2008-11-30 03:40:22Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -18,7 +18,7 @@ static ID CONTEXT_ATTR;
|
|
18
18
|
*
|
19
19
|
* As a result, parsing a document creates an in-memory document object
|
20
20
|
* that consist of any number of XML::Node instances. This is simple
|
21
|
-
* and powerful model, but has the major limitation that the size of
|
21
|
+
* and powerful model, but has the major limitation that the size of
|
22
22
|
* the document that can be processed is limited by the amount of
|
23
23
|
* memory available. In such cases, it is better to use the XML::Reader.
|
24
24
|
*
|
@@ -27,39 +27,42 @@ static ID CONTEXT_ATTR;
|
|
27
27
|
* parser = XML::Parser.new
|
28
28
|
* parser.file = 'my_file'
|
29
29
|
* doc = parser.parse
|
30
|
-
*
|
31
|
-
* You can also parse strings (see XML::Parser.string) and io objects (see
|
30
|
+
*
|
31
|
+
* You can also parse strings (see XML::Parser.string) and io objects (see
|
32
32
|
* XML::Parser.io).
|
33
33
|
*/
|
34
34
|
|
35
35
|
/*
|
36
36
|
* call-seq:
|
37
37
|
* parser.initialize -> parser
|
38
|
-
*
|
38
|
+
*
|
39
39
|
* Initiliazes instance of parser.
|
40
40
|
*/
|
41
|
-
static VALUE
|
42
|
-
|
41
|
+
static VALUE rxml_parser_initialize(VALUE self)
|
42
|
+
{
|
43
43
|
VALUE input = rb_class_new_instance(0, NULL, cXMLInput);
|
44
44
|
rb_iv_set(self, "@input", input);
|
45
45
|
rb_iv_set(self, "@context", Qnil);
|
46
46
|
return self;
|
47
47
|
}
|
48
48
|
|
49
|
-
static xmlParserCtxtPtr
|
50
|
-
|
49
|
+
static xmlParserCtxtPtr rxml_parser_filename_ctxt(VALUE input)
|
50
|
+
{
|
51
51
|
xmlParserCtxtPtr ctxt;
|
52
52
|
int retry_count = 0;
|
53
53
|
VALUE filename = rb_ivar_get(input, FILE_ATTR);
|
54
|
-
|
55
|
-
retry:
|
56
|
-
ctxt
|
57
|
-
|
58
|
-
if ((errno == EMFILE || errno == ENFILE) && retry_count == 0)
|
54
|
+
|
55
|
+
retry: ctxt = xmlCreateFileParserCtxt(StringValuePtr(filename));
|
56
|
+
if (ctxt == NULL)
|
57
|
+
{
|
58
|
+
if ((errno == EMFILE || errno == ENFILE) && retry_count == 0)
|
59
|
+
{
|
59
60
|
retry_count++;
|
60
61
|
rb_gc();
|
61
62
|
goto retry;
|
62
|
-
}
|
63
|
+
}
|
64
|
+
else
|
65
|
+
{
|
63
66
|
rb_raise(rb_eIOError, StringValuePtr(filename));
|
64
67
|
}
|
65
68
|
}
|
@@ -67,34 +70,32 @@ rxml_parser_filename_ctxt(VALUE input) {
|
|
67
70
|
return ctxt;
|
68
71
|
}
|
69
72
|
|
70
|
-
static xmlParserCtxtPtr
|
71
|
-
|
73
|
+
static xmlParserCtxtPtr rxml_parser_str_ctxt(VALUE input)
|
74
|
+
{
|
72
75
|
VALUE str = rb_ivar_get(input, STRING_ATTR);
|
73
76
|
return xmlCreateMemoryParserCtxt(StringValuePtr(str), RSTRING_LEN(str));
|
74
77
|
}
|
75
78
|
|
76
|
-
static xmlParserCtxtPtr
|
77
|
-
|
79
|
+
static xmlParserCtxtPtr rxml_parser_io_ctxt(VALUE input)
|
80
|
+
{
|
78
81
|
VALUE io = rb_ivar_get(input, IO_ATTR);
|
79
82
|
VALUE encoding = rb_ivar_get(input, ENCODING_ATTR);
|
80
83
|
xmlCharEncoding xmlEncoding = NUM2INT(encoding);
|
81
84
|
|
82
85
|
return xmlCreateIOParserCtxt(NULL, NULL,
|
83
|
-
|
84
|
-
NULL, (void *)io, xmlEncoding);
|
86
|
+
(xmlInputReadCallback) rxml_read_callback, NULL, (void *) io, xmlEncoding);
|
85
87
|
}
|
86
88
|
|
87
|
-
|
88
89
|
/*
|
89
90
|
* call-seq:
|
90
91
|
* parser.parse -> document
|
91
|
-
*
|
92
|
+
*
|
92
93
|
* Parse the input XML and create an XML::Document with
|
93
94
|
* it's content. If an error occurs, XML::Parser::ParseError
|
94
95
|
* is thrown.
|
95
96
|
*/
|
96
|
-
static VALUE
|
97
|
-
|
97
|
+
static VALUE rxml_parser_parse(VALUE self)
|
98
|
+
{
|
98
99
|
xmlParserCtxtPtr ctxt;
|
99
100
|
VALUE context;
|
100
101
|
VALUE input = rb_ivar_get(self, INPUT_ATTR);
|
@@ -108,19 +109,20 @@ rxml_parser_parse(VALUE self) {
|
|
108
109
|
else if (rb_ivar_get(input, STRING_ATTR) != Qnil)
|
109
110
|
ctxt = rxml_parser_str_ctxt(input);
|
110
111
|
/*else if (rb_ivar_get(input, DOCUMENT_ATTR) != Qnil)
|
111
|
-
|
112
|
+
ctxt = rxml_parser_parse_document(input);*/
|
112
113
|
else if (rb_ivar_get(input, IO_ATTR) != Qnil)
|
113
114
|
ctxt = rxml_parser_io_ctxt(input);
|
114
115
|
else
|
115
116
|
rb_raise(rb_eArgError, "You must specify a parser data source");
|
116
|
-
|
117
|
+
|
117
118
|
if (!ctxt)
|
118
119
|
rxml_raise(&xmlLastError);
|
119
120
|
|
120
121
|
context = rxml_parser_context_wrap(ctxt);
|
121
122
|
rb_ivar_set(self, CONTEXT_ATTR, context);
|
122
|
-
|
123
|
-
if (xmlParseDocument(ctxt) == -1 || !ctxt->wellFormed)
|
123
|
+
|
124
|
+
if (xmlParseDocument(ctxt) == -1 || !ctxt->wellFormed)
|
125
|
+
{
|
124
126
|
xmlFreeDoc(ctxt->myDoc);
|
125
127
|
rxml_raise(&ctxt->lastError);
|
126
128
|
}
|
@@ -128,17 +130,16 @@ rxml_parser_parse(VALUE self) {
|
|
128
130
|
return rxml_document_wrap(ctxt->myDoc);
|
129
131
|
}
|
130
132
|
|
131
|
-
|
132
|
-
// Rdoc needs to know
|
133
|
+
// Rdoc needs to know
|
133
134
|
#ifdef RDOC_NEVER_DEFINED
|
134
|
-
|
135
|
-
|
135
|
+
mLibXML = rb_define_module("LibXML");
|
136
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
136
137
|
#endif
|
137
138
|
|
138
|
-
void
|
139
|
-
|
139
|
+
void ruby_init_parser(void)
|
140
|
+
{
|
140
141
|
cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
|
141
|
-
|
142
|
+
|
142
143
|
/* Atributes */
|
143
144
|
INPUT_ATTR = rb_intern("@input");
|
144
145
|
CONTEXT_ATTR = rb_intern("@context");
|