libxml-ruby 0.9.7-x86-mswin32-60 → 0.9.8-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +53 -0
- data/Rakefile +1 -0
- data/ext/libxml/build.log +4 -0
- data/ext/libxml/cbg.c +86 -86
- data/ext/libxml/libxml.c +878 -876
- data/ext/libxml/ruby_libxml.h +8 -4
- data/ext/libxml/ruby_xml_attr.c +36 -168
- data/ext/libxml/ruby_xml_attr.h +2 -4
- data/ext/libxml/ruby_xml_attr_decl.c +177 -0
- data/ext/libxml/ruby_xml_attr_decl.h +13 -0
- data/ext/libxml/ruby_xml_attributes.c +29 -20
- data/ext/libxml/ruby_xml_document.c +895 -898
- data/ext/libxml/ruby_xml_dtd.c +18 -1
- data/ext/libxml/ruby_xml_dtd.h +1 -0
- data/ext/libxml/ruby_xml_encoding.c +116 -0
- data/ext/libxml/ruby_xml_encoding.h +12 -0
- data/ext/libxml/ruby_xml_error.c +8 -2
- data/ext/libxml/ruby_xml_html_parser.c +53 -74
- data/ext/libxml/ruby_xml_html_parser.h +2 -3
- data/ext/libxml/ruby_xml_html_parser_context.c +145 -0
- data/ext/libxml/ruby_xml_html_parser_context.h +12 -0
- data/ext/libxml/ruby_xml_html_parser_options.c +48 -0
- data/ext/libxml/ruby_xml_html_parser_options.h +12 -0
- data/ext/libxml/ruby_xml_input_cbg.c +1 -1
- 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 +34 -16
- data/ext/libxml/ruby_xml_namespace.h +2 -2
- data/ext/libxml/ruby_xml_namespaces.c +6 -6
- data/ext/libxml/ruby_xml_node.c +1367 -1324
- data/ext/libxml/ruby_xml_node.h +2 -2
- data/ext/libxml/ruby_xml_parser.c +26 -78
- data/ext/libxml/ruby_xml_parser.h +1 -1
- data/ext/libxml/ruby_xml_parser_context.c +284 -13
- data/ext/libxml/ruby_xml_parser_context.h +1 -2
- data/ext/libxml/ruby_xml_parser_options.c +75 -0
- data/ext/libxml/ruby_xml_parser_options.h +14 -0
- data/ext/libxml/ruby_xml_reader.c +277 -183
- data/ext/libxml/ruby_xml_sax_parser.c +60 -57
- data/ext/libxml/ruby_xml_xpath_context.c +43 -8
- data/ext/libxml/ruby_xml_xpath_expression.c +6 -0
- data/ext/libxml/ruby_xml_xpath_object.c +107 -95
- data/ext/libxml/ruby_xml_xpath_object.h +9 -1
- data/ext/libxml/ruby_xml_xpointer.c +107 -107
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +43 -3
- data/lib/libxml.rb +2 -3
- data/lib/libxml/attr.rb +71 -2
- data/lib/libxml/attr_decl.rb +81 -0
- data/lib/libxml/document.rb +78 -14
- data/lib/libxml/html_parser.rb +75 -42
- data/lib/libxml/node.rb +11 -0
- data/lib/libxml/parser.rb +106 -62
- data/lib/libxml/reader.rb +12 -0
- data/lib/libxml/sax_parser.rb +42 -52
- data/lib/libxml/xpath_object.rb +15 -0
- data/test/model/atom.xml +12 -12
- data/test/model/bands.xml +4 -4
- data/test/model/books.xml +146 -147
- data/test/model/merge_bug_data.xml +1 -1
- data/test/model/rubynet.xml +1 -0
- data/test/model/shiporder.rng +1 -1
- data/test/model/shiporder.xml +22 -22
- data/test/model/shiporder.xsd +30 -30
- data/test/model/xinclude.xml +1 -1
- data/test/{tc_node_attr.rb → tc_attr.rb} +1 -1
- data/test/tc_attr_decl.rb +131 -0
- data/test/tc_deprecated_require.rb +1 -3
- data/test/tc_document.rb +13 -3
- data/test/tc_document_write.rb +5 -5
- data/test/tc_dtd.rb +13 -5
- data/test/tc_html_parser.rb +14 -26
- data/test/tc_node_cdata.rb +1 -3
- data/test/tc_node_comment.rb +2 -4
- data/test/tc_node_edit.rb +2 -3
- data/test/tc_node_text.rb +35 -1
- data/test/tc_node_write.rb +3 -3
- data/test/tc_node_xlink.rb +2 -4
- data/test/tc_parser.rb +163 -70
- data/test/tc_parser_context.rb +103 -42
- data/test/tc_reader.rb +173 -45
- data/test/tc_relaxng.rb +2 -2
- data/test/tc_sax_parser.rb +48 -52
- data/test/tc_schema.rb +2 -2
- data/test/tc_xpath.rb +37 -6
- data/test/tc_xpath_context.rb +7 -1
- data/test/tc_xpath_expression.rb +1 -3
- data/test/tc_xpointer.rb +1 -3
- data/test/test_suite.rb +2 -3
- metadata +20 -13
- data/ext/libxml/ruby_xml_input.c +0 -329
- data/ext/libxml/ruby_xml_input.h +0 -20
- data/lib/libxml/parser_context.rb +0 -17
- data/lib/libxml/parser_options.rb +0 -25
- data/test/model/simple.xml +0 -7
- data/test/tc_input.rb +0 -13
- data/test/tc_well_formed.rb +0 -11
@@ -0,0 +1,12 @@
|
|
1
|
+
/* $Id: ruby_xml_parser_context.h 666 2008-12-07 00:16:50Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RXML_HTML_PARSER_CONTEXT__
|
6
|
+
#define __RXML_HTML_PARSER_CONTEXT__
|
7
|
+
|
8
|
+
extern VALUE cXMLHtmlParserContext;
|
9
|
+
|
10
|
+
void ruby_init_html_parser_context(void);
|
11
|
+
|
12
|
+
#endif
|
@@ -0,0 +1,48 @@
|
|
1
|
+
/* $Id: ruby_xml_html_parser.c 710 2009-01-20 05:30:51Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "ruby_libxml.h"
|
6
|
+
|
7
|
+
|
8
|
+
/* Document-class: LibXML::XML::HTMLParserOptions
|
9
|
+
*
|
10
|
+
* Options that control the operation of the HTMLParser. The easiest
|
11
|
+
* way to set a parser's options is to use the methods
|
12
|
+
* XML::HTMLParser.file, XML::HTMLParser.io or XML::HTMLParser.string.
|
13
|
+
* For additional control, see XML::HTMLParser::Context#options=.
|
14
|
+
*/
|
15
|
+
|
16
|
+
VALUE mXMLHtmlParserOptions;
|
17
|
+
|
18
|
+
|
19
|
+
// Rdoc needs to know
|
20
|
+
#ifdef RDOC_NEVER_DEFINED
|
21
|
+
mLibXML = rb_define_module("LibXML");
|
22
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
23
|
+
cXMLHtmlParser = rb_define_class_under(mXML, "HTMLParser", rb_cObject);
|
24
|
+
#endif
|
25
|
+
|
26
|
+
void ruby_init_html_parser_options(void)
|
27
|
+
{
|
28
|
+
mXMLHtmlParserOptions = rb_define_module_under(cXMLHtmlParser, "Options");
|
29
|
+
|
30
|
+
#if LIBXML_VERSION >= 20621
|
31
|
+
/* Relaxed parsing */
|
32
|
+
rb_define_const(mXMLHtmlParserOptions, "RECOVER", INT2NUM(HTML_PARSE_RECOVER));
|
33
|
+
#endif
|
34
|
+
/* suppress error reports */
|
35
|
+
rb_define_const(mXMLHtmlParserOptions, "NOERROR", INT2NUM(HTML_PARSE_NOERROR));
|
36
|
+
/* suppress warning reports */
|
37
|
+
rb_define_const(mXMLHtmlParserOptions, "NOWARNING", INT2NUM(HTML_PARSE_NOWARNING));
|
38
|
+
/* pedantic error reporting */
|
39
|
+
rb_define_const(mXMLHtmlParserOptions, "PEDANTIC", INT2NUM(HTML_PARSE_PEDANTIC));
|
40
|
+
/* remove blank nodes */
|
41
|
+
rb_define_const(mXMLHtmlParserOptions, "NOBLANKS", INT2NUM(HTML_PARSE_NOBLANKS));
|
42
|
+
#if LIBXML_VERSION >= 20621
|
43
|
+
/* Forbid network access */
|
44
|
+
rb_define_const(mXMLHtmlParserOptions, "NONET", INT2NUM(HTML_PARSE_NONET));
|
45
|
+
/* compact small text nodes */
|
46
|
+
rb_define_const(mXMLHtmlParserOptions, "COMPACT", INT2NUM(HTML_PARSE_COMPACT));
|
47
|
+
#endif
|
48
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
/* $Id: ruby_xml_html_parser.h 666 2008-12-07 00:16:50Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RXML_HTML_PARSER_OPTIONS__
|
6
|
+
#define __RXML_HTML_PARSER_OPTIONS__
|
7
|
+
|
8
|
+
extern VALUE mXMLHtmlParserOptions;
|
9
|
+
|
10
|
+
void ruby_init_html_parser_options(void);
|
11
|
+
|
12
|
+
#endif
|
@@ -0,0 +1,30 @@
|
|
1
|
+
/* $Id: libxml.c 734 2009-01-22 04:41:07Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "ruby_libxml.h"
|
6
|
+
|
7
|
+
static ID READ_METHOD;
|
8
|
+
|
9
|
+
/* This method is called by libxml when it wants to read
|
10
|
+
more data from a stream. We go with the duck typing
|
11
|
+
solution to support StringIO objects. */
|
12
|
+
int rxml_read_callback(void *context, char *buffer, int len)
|
13
|
+
{
|
14
|
+
VALUE io = (VALUE) context;
|
15
|
+
VALUE string = rb_funcall(io, READ_METHOD, 1, INT2NUM(len));
|
16
|
+
int size;
|
17
|
+
|
18
|
+
if (string == Qnil)
|
19
|
+
return 0;
|
20
|
+
|
21
|
+
size = RSTRING_LEN(string);
|
22
|
+
memcpy(buffer, StringValuePtr(string), size);
|
23
|
+
|
24
|
+
return size;
|
25
|
+
}
|
26
|
+
|
27
|
+
void rxml_init_io(void)
|
28
|
+
{
|
29
|
+
READ_METHOD = rb_intern("read");
|
30
|
+
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_namespace.c
|
1
|
+
/* $Id: ruby_xml_namespace.c 740 2009-01-23 04:03:11Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -33,6 +33,24 @@ static VALUE rxml_namespace_alloc(VALUE klass)
|
|
33
33
|
return Data_Wrap_Struct(klass, NULL, rxml_namespace_free, NULL);
|
34
34
|
}
|
35
35
|
|
36
|
+
VALUE rxml_namespace_wrap(xmlNsPtr xns, RUBY_DATA_FUNC freeFunc)
|
37
|
+
{
|
38
|
+
if (xns->_private)
|
39
|
+
{
|
40
|
+
return (VALUE)xns->_private;
|
41
|
+
}
|
42
|
+
else
|
43
|
+
{
|
44
|
+
VALUE ns;
|
45
|
+
if (freeFunc == NULL)
|
46
|
+
freeFunc = (RUBY_DATA_FUNC)rxml_namespace_free;
|
47
|
+
|
48
|
+
ns = Data_Wrap_Struct(cXMLNamespace, NULL, freeFunc, xns);
|
49
|
+
xns->_private = (void*)ns;
|
50
|
+
return ns;
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
36
54
|
/*
|
37
55
|
* call-seq:
|
38
56
|
* initialize(node, "prefix", "href") -> XML::Namespace
|
@@ -63,20 +81,6 @@ static VALUE rxml_namespace_initialize(VALUE self, VALUE node, VALUE prefix,
|
|
63
81
|
return self;
|
64
82
|
}
|
65
83
|
|
66
|
-
VALUE rxml_namespace_wrap(xmlNsPtr xns)
|
67
|
-
{
|
68
|
-
if (xns->_private)
|
69
|
-
{
|
70
|
-
return (VALUE)xns->_private;
|
71
|
-
}
|
72
|
-
else
|
73
|
-
{
|
74
|
-
VALUE ns = Data_Wrap_Struct(cXMLNamespace, NULL, rxml_namespace_free, xns);
|
75
|
-
xns->_private = (void*)ns;
|
76
|
-
return ns;
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
84
|
/*
|
81
85
|
* call-seq:
|
82
86
|
* ns.href -> "href"
|
@@ -97,6 +101,19 @@ static VALUE rxml_namespace_href_get(VALUE self)
|
|
97
101
|
return rb_str_new2((const char*) xns->href);
|
98
102
|
}
|
99
103
|
|
104
|
+
/*
|
105
|
+
* call-seq:
|
106
|
+
* ns.node_type -> num
|
107
|
+
*
|
108
|
+
* Obtain this namespace's type identifier.
|
109
|
+
*/
|
110
|
+
static VALUE rxml_namespace_node_type(VALUE self)
|
111
|
+
{
|
112
|
+
xmlNsPtr xns;
|
113
|
+
Data_Get_Struct(self, xmlNs, xns);
|
114
|
+
return INT2NUM(xns->type);
|
115
|
+
}
|
116
|
+
|
100
117
|
/*
|
101
118
|
* call-seq:
|
102
119
|
* ns.prefix -> "prefix"
|
@@ -138,7 +155,7 @@ static VALUE rxml_namespace_next(VALUE self)
|
|
138
155
|
if (xns == NULL || xns->next == NULL)
|
139
156
|
return (Qnil);
|
140
157
|
else
|
141
|
-
return (rxml_namespace_wrap(xns->next));
|
158
|
+
return (rxml_namespace_wrap(xns->next, NULL));
|
142
159
|
}
|
143
160
|
|
144
161
|
// Rdoc needs to know
|
@@ -154,5 +171,6 @@ void ruby_init_xml_namespace(void)
|
|
154
171
|
rb_define_method(cXMLNamespace, "initialize", rxml_namespace_initialize, 3);
|
155
172
|
rb_define_method(cXMLNamespace, "href", rxml_namespace_href_get, 0);
|
156
173
|
rb_define_method(cXMLNamespace, "next", rxml_namespace_next, 0);
|
174
|
+
rb_define_method(cXMLNamespace, "node_type", rxml_namespace_node_type, 0);
|
157
175
|
rb_define_method(cXMLNamespace, "prefix", rxml_namespace_prefix_get, 0);
|
158
176
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_namespace.h
|
1
|
+
/* $Id: ruby_xml_namespace.h 739 2009-01-23 03:42:09Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -8,5 +8,5 @@
|
|
8
8
|
extern VALUE cXMLNamespace;
|
9
9
|
|
10
10
|
void ruby_init_xml_namespace(void);
|
11
|
-
VALUE rxml_namespace_wrap(xmlNsPtr
|
11
|
+
VALUE rxml_namespace_wrap(xmlNsPtr xns, RUBY_DATA_FUNC freeFunc);
|
12
12
|
#endif
|
@@ -92,7 +92,7 @@ static VALUE rxml_namespaces_definitions(VALUE self)
|
|
92
92
|
|
93
93
|
while (xns)
|
94
94
|
{
|
95
|
-
VALUE anamespace = rxml_namespace_wrap(xns);
|
95
|
+
VALUE anamespace = rxml_namespace_wrap(xns, NULL);
|
96
96
|
rb_ary_push(arr, anamespace);
|
97
97
|
xns = xns->next;
|
98
98
|
}
|
@@ -128,7 +128,7 @@ static VALUE rxml_namespaces_each(VALUE self)
|
|
128
128
|
|
129
129
|
for (xns = nsList; *xns != NULL; xns++)
|
130
130
|
{
|
131
|
-
VALUE ns = rxml_namespace_wrap(*xns);
|
131
|
+
VALUE ns = rxml_namespace_wrap(*xns, NULL);
|
132
132
|
rb_yield(ns);
|
133
133
|
}
|
134
134
|
xmlFree(nsList);
|
@@ -163,7 +163,7 @@ static VALUE rxml_namespaces_find_by_href(VALUE self, VALUE href)
|
|
163
163
|
|
164
164
|
xns = xmlSearchNsByHref(xnode->doc, xnode, (xmlChar*) StringValuePtr(href));
|
165
165
|
if (xns)
|
166
|
-
return rxml_namespace_wrap(xns);
|
166
|
+
return rxml_namespace_wrap(xns, NULL);
|
167
167
|
else
|
168
168
|
return Qnil;
|
169
169
|
}
|
@@ -202,7 +202,7 @@ static VALUE rxml_namespaces_find_by_prefix(VALUE self, VALUE prefix)
|
|
202
202
|
|
203
203
|
xns = xmlSearchNs(xnode->doc, xnode, xprefix);
|
204
204
|
if (xns)
|
205
|
-
return rxml_namespace_wrap(xns);
|
205
|
+
return rxml_namespace_wrap(xns, NULL);
|
206
206
|
else
|
207
207
|
return Qnil;
|
208
208
|
}
|
@@ -226,7 +226,7 @@ static VALUE rxml_namespaces_namespace_get(VALUE self)
|
|
226
226
|
Data_Get_Struct(self, xmlNode, xnode);
|
227
227
|
|
228
228
|
if (xnode->ns)
|
229
|
-
return rxml_namespace_wrap(xnode->ns);
|
229
|
+
return rxml_namespace_wrap(xnode->ns, NULL);
|
230
230
|
else
|
231
231
|
return Qnil;
|
232
232
|
}
|
@@ -274,7 +274,7 @@ static VALUE rxml_namespaces_node_get(VALUE self)
|
|
274
274
|
{
|
275
275
|
xmlNodePtr xnode;
|
276
276
|
Data_Get_Struct(self, xmlNode, xnode);
|
277
|
-
return rxml_node_wrap(
|
277
|
+
return rxml_node_wrap(xnode);
|
278
278
|
}
|
279
279
|
|
280
280
|
|
data/ext/libxml/ruby_xml_node.c
CHANGED
@@ -1,1324 +1,1367 @@
|
|
1
|
-
#include "ruby_libxml.h"
|
2
|
-
#include "ruby_xml_node.h"
|
3
|
-
|
4
|
-
VALUE cXMLNode;
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
-
if (xnode->
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
if (xnode
|
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
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
*
|
174
|
-
*
|
175
|
-
*
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
*
|
195
|
-
*
|
196
|
-
*
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
VALUE
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
name
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
*
|
227
|
-
*
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
*
|
256
|
-
*
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
*
|
275
|
-
*
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
*
|
298
|
-
*
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
*
|
315
|
-
*
|
316
|
-
*
|
317
|
-
*
|
318
|
-
*
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
}
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
*
|
344
|
-
*
|
345
|
-
*
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
*
|
364
|
-
*
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
return (
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
*
|
416
|
-
*
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
*
|
427
|
-
*
|
428
|
-
*
|
429
|
-
*
|
430
|
-
*
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
}
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
*
|
461
|
-
*
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
*
|
472
|
-
*
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
#
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
*
|
517
|
-
*
|
518
|
-
*
|
519
|
-
*
|
520
|
-
*
|
521
|
-
*
|
522
|
-
*
|
523
|
-
*
|
524
|
-
*
|
525
|
-
*
|
526
|
-
*
|
527
|
-
*
|
528
|
-
*
|
529
|
-
*
|
530
|
-
*
|
531
|
-
*
|
532
|
-
*
|
533
|
-
*
|
534
|
-
*
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
if (
|
561
|
-
|
562
|
-
|
563
|
-
if (
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
*
|
583
|
-
|
584
|
-
*
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
{
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
*
|
882
|
-
*
|
883
|
-
*
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
/*
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
*
|
925
|
-
*
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
if (
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
*
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
*
|
1036
|
-
*
|
1037
|
-
|
1038
|
-
|
1039
|
-
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
*
|
1061
|
-
*
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
return
|
1069
|
-
}
|
1070
|
-
|
1071
|
-
/*
|
1072
|
-
* call-seq:
|
1073
|
-
* node.
|
1074
|
-
*
|
1075
|
-
*
|
1076
|
-
*
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
*
|
1099
|
-
*
|
1100
|
-
*
|
1101
|
-
*
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
Data_Get_Struct(self, xmlNode,
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
}
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
|
1274
|
-
|
1275
|
-
|
1276
|
-
|
1277
|
-
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
rb_define_method(cXMLNode, "
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
rb_define_method(cXMLNode, "
|
1321
|
-
rb_define_method(cXMLNode, "
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1
|
+
#include "ruby_libxml.h"
|
2
|
+
#include "ruby_xml_node.h"
|
3
|
+
|
4
|
+
VALUE cXMLNode;
|
5
|
+
|
6
|
+
static VALUE kXMLStringText;
|
7
|
+
static VALUE kXMLStringTextNoenc;
|
8
|
+
|
9
|
+
/* Document-class: LibXML::XML::Node
|
10
|
+
*
|
11
|
+
* Nodes are the primary objects that make up an XML document.
|
12
|
+
* The node class represents most node types that are found in
|
13
|
+
* an XML document (but not Attributes, see LibXML::XML::Attribute).
|
14
|
+
* It exposes libxml's full API for creating, querying
|
15
|
+
* moving and deleting node objects. Many of these methods are
|
16
|
+
* documented in the DOM Level 3 specification found at:
|
17
|
+
* http://www.w3.org/TR/DOM-Level-3-Core/. */
|
18
|
+
|
19
|
+
static VALUE rxml_node_content_set(VALUE self, VALUE content);
|
20
|
+
|
21
|
+
VALUE check_string_or_symbol(VALUE val)
|
22
|
+
{
|
23
|
+
if (TYPE(val) != T_STRING && TYPE(val) != T_SYMBOL)
|
24
|
+
{
|
25
|
+
rb_raise(rb_eTypeError,
|
26
|
+
"wrong argument type %s (expected String or Symbol)", rb_obj_classname(
|
27
|
+
val));
|
28
|
+
}
|
29
|
+
return rb_obj_as_string(val);
|
30
|
+
}
|
31
|
+
|
32
|
+
/*
|
33
|
+
* memory2 implementation: xmlNode->_private holds a reference
|
34
|
+
* to the wrapping ruby object VALUE when there is one.
|
35
|
+
* traversal for marking is upward, and top levels are marked
|
36
|
+
* through and lower level mark entry.
|
37
|
+
*
|
38
|
+
* All ruby retrieval for an xml
|
39
|
+
* node will result in the same ruby instance. When all handles to them
|
40
|
+
* go out of scope, then ruby_xfree gets called and _private is set to NULL.
|
41
|
+
* If the xmlNode has no parent or document, then call xmlFree.
|
42
|
+
*/
|
43
|
+
void rxml_node_free(xmlNodePtr xnode)
|
44
|
+
{
|
45
|
+
/* Set _private to NULL so that we won't reuse the
|
46
|
+
same, freed, Ruby wrapper object later.*/
|
47
|
+
xnode->_private = NULL;
|
48
|
+
|
49
|
+
if (xnode->doc == NULL && xnode->parent == NULL)
|
50
|
+
xmlFreeNode(xnode);
|
51
|
+
}
|
52
|
+
|
53
|
+
void rxml_node_mark_common(xmlNodePtr xnode)
|
54
|
+
{
|
55
|
+
if (xnode->parent == NULL)
|
56
|
+
return;
|
57
|
+
|
58
|
+
if (xnode->doc != NULL)
|
59
|
+
{
|
60
|
+
if (xnode->doc->_private == NULL)
|
61
|
+
rb_bug("XmlNode Doc is not bound! (%s:%d)", __FILE__,__LINE__);
|
62
|
+
rb_gc_mark((VALUE) xnode->doc->_private);
|
63
|
+
}
|
64
|
+
else
|
65
|
+
{
|
66
|
+
while (xnode->parent != NULL)
|
67
|
+
xnode = xnode->parent;
|
68
|
+
|
69
|
+
if (xnode->_private == NULL)
|
70
|
+
rb_warning("XmlNode Root Parent is not bound! (%s:%d)", __FILE__,__LINE__);
|
71
|
+
else
|
72
|
+
rb_gc_mark((VALUE) xnode->_private);
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
void rxml_node_mark(xmlNodePtr xnode)
|
77
|
+
{
|
78
|
+
if (xnode == NULL)
|
79
|
+
return;
|
80
|
+
|
81
|
+
if (xnode->_private == NULL)
|
82
|
+
{
|
83
|
+
rb_warning("XmlNode is not bound! (%s:%d)", __FILE__, __LINE__);
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
|
87
|
+
rxml_node_mark_common(xnode);
|
88
|
+
}
|
89
|
+
|
90
|
+
VALUE rxml_node_wrap(xmlNodePtr xnode)
|
91
|
+
{
|
92
|
+
/* Is the node already wrapped? */
|
93
|
+
if (xnode->_private != NULL)
|
94
|
+
{
|
95
|
+
return (VALUE) xnode->_private;
|
96
|
+
}
|
97
|
+
else
|
98
|
+
{
|
99
|
+
VALUE node = Data_Wrap_Struct(cXMLNode, rxml_node_mark, rxml_node_free, xnode);
|
100
|
+
xnode->_private = (void*) node;
|
101
|
+
return node;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
105
|
+
static VALUE rxml_node_alloc(VALUE klass)
|
106
|
+
{
|
107
|
+
return Data_Wrap_Struct(klass, rxml_node_mark, rxml_node_free, NULL);
|
108
|
+
}
|
109
|
+
|
110
|
+
/*
|
111
|
+
* call-seq:
|
112
|
+
* XML::Node.new_cdata(content = nil) -> XML::Node
|
113
|
+
*
|
114
|
+
* Create a new #CDATA node, optionally setting
|
115
|
+
* the node's content.
|
116
|
+
*/
|
117
|
+
static VALUE rxml_node_new_cdata(int argc, VALUE *argv, VALUE klass)
|
118
|
+
{
|
119
|
+
VALUE content = Qnil;
|
120
|
+
xmlNodePtr xnode;
|
121
|
+
|
122
|
+
rb_scan_args(argc, argv, "01", &content);
|
123
|
+
|
124
|
+
if (NIL_P(content))
|
125
|
+
{
|
126
|
+
xnode = xmlNewCDataBlock(NULL, NULL, 0);
|
127
|
+
}
|
128
|
+
else
|
129
|
+
{
|
130
|
+
content = rb_obj_as_string(content);
|
131
|
+
xnode = xmlNewCDataBlock(NULL, (xmlChar*) StringValuePtr(content),
|
132
|
+
RSTRING_LEN(content));
|
133
|
+
}
|
134
|
+
|
135
|
+
if (xnode == NULL)
|
136
|
+
rxml_raise(&xmlLastError);
|
137
|
+
|
138
|
+
return rxml_node_wrap(xnode);
|
139
|
+
}
|
140
|
+
|
141
|
+
/*
|
142
|
+
* call-seq:
|
143
|
+
* XML::Node.new_comment(content = nil) -> XML::Node
|
144
|
+
*
|
145
|
+
* Create a new comment node, optionally setting
|
146
|
+
* the node's content.
|
147
|
+
*
|
148
|
+
*/
|
149
|
+
static VALUE rxml_node_new_comment(int argc, VALUE *argv, VALUE klass)
|
150
|
+
{
|
151
|
+
VALUE content = Qnil;
|
152
|
+
xmlNodePtr xnode;
|
153
|
+
|
154
|
+
rb_scan_args(argc, argv, "01", &content);
|
155
|
+
|
156
|
+
if (NIL_P(content))
|
157
|
+
{
|
158
|
+
xnode = xmlNewComment(NULL);
|
159
|
+
}
|
160
|
+
else
|
161
|
+
{
|
162
|
+
content = rb_obj_as_string(content);
|
163
|
+
xnode = xmlNewComment((xmlChar*) StringValueCStr(content));
|
164
|
+
}
|
165
|
+
|
166
|
+
if (xnode == NULL)
|
167
|
+
rxml_raise(&xmlLastError);
|
168
|
+
|
169
|
+
return rxml_node_wrap(xnode);
|
170
|
+
}
|
171
|
+
|
172
|
+
/*
|
173
|
+
* call-seq:
|
174
|
+
* XML::Node.new_text(content) -> XML::Node
|
175
|
+
*
|
176
|
+
* Create a new text node.
|
177
|
+
*
|
178
|
+
*/
|
179
|
+
static VALUE rxml_node_new_text(VALUE klass, VALUE content)
|
180
|
+
{
|
181
|
+
xmlNodePtr xnode;
|
182
|
+
Check_Type(content, T_STRING);
|
183
|
+
content = rb_obj_as_string(content);
|
184
|
+
|
185
|
+
xnode = xmlNewText((xmlChar*) StringValueCStr(content));
|
186
|
+
|
187
|
+
if (xnode == NULL)
|
188
|
+
rxml_raise(&xmlLastError);
|
189
|
+
|
190
|
+
return rxml_node_wrap(xnode);
|
191
|
+
}
|
192
|
+
|
193
|
+
/*
|
194
|
+
* call-seq:
|
195
|
+
* XML::Node.initialize(name, content = nil, namespace = nil) -> XML::Node
|
196
|
+
*
|
197
|
+
* Creates a new element with the specified name, content and
|
198
|
+
* namespace. The content and namespace may be nil.
|
199
|
+
*/
|
200
|
+
static VALUE rxml_node_initialize(int argc, VALUE *argv, VALUE self)
|
201
|
+
{
|
202
|
+
VALUE name;
|
203
|
+
VALUE content;
|
204
|
+
VALUE ns;
|
205
|
+
xmlNodePtr xnode = NULL;
|
206
|
+
xmlNsPtr xns = NULL;
|
207
|
+
|
208
|
+
rb_scan_args(argc, argv, "12", &name, &content, &ns);
|
209
|
+
|
210
|
+
name = check_string_or_symbol(name);
|
211
|
+
|
212
|
+
if (!NIL_P(ns))
|
213
|
+
Data_Get_Struct(ns, xmlNs, xns);
|
214
|
+
|
215
|
+
xnode = xmlNewNode(xns, (xmlChar*) StringValuePtr(name));
|
216
|
+
xnode->_private = (void*) self;
|
217
|
+
DATA_PTR( self) = xnode;
|
218
|
+
|
219
|
+
if (!NIL_P(content))
|
220
|
+
rxml_node_content_set(self, content);
|
221
|
+
|
222
|
+
return self;
|
223
|
+
}
|
224
|
+
|
225
|
+
/*
|
226
|
+
* call-seq:
|
227
|
+
* node.base_uri -> "uri"
|
228
|
+
*
|
229
|
+
* Obtain this node's base URI.
|
230
|
+
*/
|
231
|
+
static VALUE rxml_node_base_uri_get(VALUE self)
|
232
|
+
{
|
233
|
+
xmlNodePtr xnode;
|
234
|
+
xmlChar* base_uri;
|
235
|
+
VALUE result = Qnil;
|
236
|
+
|
237
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
238
|
+
|
239
|
+
if (xnode->doc == NULL)
|
240
|
+
return (result);
|
241
|
+
|
242
|
+
base_uri = xmlNodeGetBase(xnode->doc, xnode);
|
243
|
+
if (base_uri)
|
244
|
+
{
|
245
|
+
result = rb_str_new2((const char*) base_uri);
|
246
|
+
xmlFree(base_uri);
|
247
|
+
}
|
248
|
+
|
249
|
+
return (result);
|
250
|
+
}
|
251
|
+
|
252
|
+
// TODO node_base_set should support setting back to nil
|
253
|
+
|
254
|
+
/*
|
255
|
+
* call-seq:
|
256
|
+
* node.base_uri = "uri"
|
257
|
+
*
|
258
|
+
* Set this node's base URI.
|
259
|
+
*/
|
260
|
+
static VALUE rxml_node_base_uri_set(VALUE self, VALUE uri)
|
261
|
+
{
|
262
|
+
xmlNodePtr xnode;
|
263
|
+
|
264
|
+
Check_Type(uri, T_STRING);
|
265
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
266
|
+
if (xnode->doc == NULL)
|
267
|
+
return (Qnil);
|
268
|
+
|
269
|
+
xmlNodeSetBase(xnode, (xmlChar*) StringValuePtr(uri));
|
270
|
+
return (Qtrue);
|
271
|
+
}
|
272
|
+
|
273
|
+
/*
|
274
|
+
* call-seq:
|
275
|
+
* node.content -> "string"
|
276
|
+
*
|
277
|
+
* Obtain this node's content as a string.
|
278
|
+
*/
|
279
|
+
static VALUE rxml_node_content_get(VALUE self)
|
280
|
+
{
|
281
|
+
xmlNodePtr xnode;
|
282
|
+
xmlChar *content;
|
283
|
+
VALUE result = Qnil;
|
284
|
+
|
285
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
286
|
+
content = xmlNodeGetContent(xnode);
|
287
|
+
if (content)
|
288
|
+
{
|
289
|
+
result = rb_str_new2((const char *) content);
|
290
|
+
xmlFree(content);
|
291
|
+
}
|
292
|
+
|
293
|
+
return result;
|
294
|
+
}
|
295
|
+
|
296
|
+
/*
|
297
|
+
* call-seq:
|
298
|
+
* node.content = "string"
|
299
|
+
*
|
300
|
+
* Set this node's content to the specified string.
|
301
|
+
*/
|
302
|
+
static VALUE rxml_node_content_set(VALUE self, VALUE content)
|
303
|
+
{
|
304
|
+
xmlNodePtr xnode;
|
305
|
+
|
306
|
+
Check_Type(content, T_STRING);
|
307
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
308
|
+
// XXX docs indicate need for escaping entites, need to be done? danj
|
309
|
+
xmlNodeSetContent(xnode, (xmlChar*) StringValuePtr(content));
|
310
|
+
return (Qtrue);
|
311
|
+
}
|
312
|
+
|
313
|
+
/*
|
314
|
+
* call-seq:
|
315
|
+
* node.content_stripped -> "string"
|
316
|
+
*
|
317
|
+
* Obtain this node's stripped content.
|
318
|
+
*
|
319
|
+
* *Deprecated*: Stripped content can be obtained via the
|
320
|
+
* +content+ method.
|
321
|
+
*/
|
322
|
+
static VALUE rxml_node_content_stripped_get(VALUE self)
|
323
|
+
{
|
324
|
+
xmlNodePtr xnode;
|
325
|
+
xmlChar* content;
|
326
|
+
VALUE result = Qnil;
|
327
|
+
|
328
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
329
|
+
|
330
|
+
if (!xnode->content)
|
331
|
+
return result;
|
332
|
+
|
333
|
+
content = xmlNodeGetContent(xnode);
|
334
|
+
if (content)
|
335
|
+
{
|
336
|
+
result = rb_str_new2((const char*) content);
|
337
|
+
xmlFree(content);
|
338
|
+
}
|
339
|
+
return (result);
|
340
|
+
}
|
341
|
+
|
342
|
+
/*
|
343
|
+
* call-seq:
|
344
|
+
* node.debug -> true|false
|
345
|
+
*
|
346
|
+
* Print libxml debugging information to stdout.
|
347
|
+
* Requires that libxml was compiled with debugging enabled.
|
348
|
+
*/
|
349
|
+
static VALUE rxml_node_debug(VALUE self)
|
350
|
+
{
|
351
|
+
#ifdef LIBXML_DEBUG_ENABLED
|
352
|
+
xmlNodePtr xnode;
|
353
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
354
|
+
xmlDebugDumpNode(NULL, xnode, 2);
|
355
|
+
return Qtrue;
|
356
|
+
#else
|
357
|
+
rb_warn("libxml was compiled without debugging support.")
|
358
|
+
return Qfalse;
|
359
|
+
#endif
|
360
|
+
}
|
361
|
+
|
362
|
+
/*
|
363
|
+
* call-seq:
|
364
|
+
* node.first -> XML::Node
|
365
|
+
*
|
366
|
+
* Returns this node's first child node if any.
|
367
|
+
*/
|
368
|
+
static VALUE rxml_node_first_get(VALUE self)
|
369
|
+
{
|
370
|
+
xmlNodePtr xnode;
|
371
|
+
|
372
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
373
|
+
|
374
|
+
if (xnode->children)
|
375
|
+
return (rxml_node_wrap(xnode->children));
|
376
|
+
else
|
377
|
+
return (Qnil);
|
378
|
+
}
|
379
|
+
|
380
|
+
/*
|
381
|
+
* underlying for child_set and child_add, difference being
|
382
|
+
* former raises on implicit copy, latter does not.
|
383
|
+
*/
|
384
|
+
static VALUE rxml_node_child_set_aux(VALUE self, VALUE rnode)
|
385
|
+
{
|
386
|
+
xmlNodePtr pnode, chld, ret;
|
387
|
+
|
388
|
+
if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
|
389
|
+
rb_raise(rb_eTypeError, "Must pass an XML::Node object");
|
390
|
+
|
391
|
+
Data_Get_Struct(self, xmlNode, pnode);
|
392
|
+
Data_Get_Struct(rnode, xmlNode, chld);
|
393
|
+
|
394
|
+
if (chld->parent != NULL || chld->doc != NULL)
|
395
|
+
rb_raise(
|
396
|
+
rb_eRuntimeError,
|
397
|
+
"Cannot move a node from one document to another with child= or <<. First copy the node before moving it.");
|
398
|
+
|
399
|
+
ret = xmlAddChild(pnode, chld);
|
400
|
+
if (ret == NULL)
|
401
|
+
{
|
402
|
+
rxml_raise(&xmlLastError);
|
403
|
+
}
|
404
|
+
else if (ret == chld)
|
405
|
+
{
|
406
|
+
/* child was added whole to parent and we need to return it as a new object */
|
407
|
+
return rxml_node_wrap(chld);
|
408
|
+
}
|
409
|
+
/* else */
|
410
|
+
/* If it was a text node, then ret should be parent->last, so we will just return ret. */
|
411
|
+
return rxml_node_wrap(ret);
|
412
|
+
}
|
413
|
+
|
414
|
+
/*
|
415
|
+
* call-seq:
|
416
|
+
* node.child = node
|
417
|
+
*
|
418
|
+
* Set a child node for this node. Also called for <<
|
419
|
+
*/
|
420
|
+
static VALUE rxml_node_child_set(VALUE self, VALUE rnode)
|
421
|
+
{
|
422
|
+
return rxml_node_child_set_aux(self, rnode);
|
423
|
+
}
|
424
|
+
|
425
|
+
/*
|
426
|
+
* call-seq:
|
427
|
+
* node << ("string" | node) -> XML::Node
|
428
|
+
*
|
429
|
+
* Add the specified string or XML::Node to this node's
|
430
|
+
* content. The returned node is the node that was
|
431
|
+
* added and not self, thereby allowing << calls to
|
432
|
+
* be chained.
|
433
|
+
*/
|
434
|
+
static VALUE rxml_node_content_add(VALUE self, VALUE obj)
|
435
|
+
{
|
436
|
+
xmlNodePtr xnode;
|
437
|
+
VALUE str;
|
438
|
+
|
439
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
440
|
+
/* XXX This should only be legal for a CDATA type node, I think,
|
441
|
+
* resulting in a merge of content, as if a string were passed
|
442
|
+
* danj 070827
|
443
|
+
*/
|
444
|
+
if (rb_obj_is_kind_of(obj, cXMLNode))
|
445
|
+
{
|
446
|
+
rxml_node_child_set(self, obj);
|
447
|
+
}
|
448
|
+
else
|
449
|
+
{
|
450
|
+
str = rb_obj_as_string(obj);
|
451
|
+
if (NIL_P(str) || TYPE(str) != T_STRING)
|
452
|
+
rb_raise(rb_eTypeError, "invalid argument: must be string or XML::Node");
|
453
|
+
|
454
|
+
xmlNodeAddContent(xnode, (xmlChar*) StringValuePtr(str));
|
455
|
+
}
|
456
|
+
return (self);
|
457
|
+
}
|
458
|
+
|
459
|
+
/*
|
460
|
+
* call-seq:
|
461
|
+
* node.child_add(node)
|
462
|
+
*
|
463
|
+
* Set a child node for this node.
|
464
|
+
*/
|
465
|
+
static VALUE rxml_node_child_add(VALUE self, VALUE rnode)
|
466
|
+
{
|
467
|
+
return rxml_node_child_set_aux(self, rnode);
|
468
|
+
}
|
469
|
+
|
470
|
+
/*
|
471
|
+
* call-seq:
|
472
|
+
* node.doc -> document
|
473
|
+
*
|
474
|
+
* Obtain the XML::Document this node belongs to.
|
475
|
+
*/
|
476
|
+
static VALUE rxml_node_doc(VALUE self)
|
477
|
+
{
|
478
|
+
xmlNodePtr xnode;
|
479
|
+
xmlDocPtr doc = NULL;
|
480
|
+
|
481
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
482
|
+
|
483
|
+
switch (xnode->type)
|
484
|
+
{
|
485
|
+
case XML_DOCUMENT_NODE:
|
486
|
+
#ifdef LIBXML_DOCB_ENABLED
|
487
|
+
case XML_DOCB_DOCUMENT_NODE:
|
488
|
+
#endif
|
489
|
+
case XML_HTML_DOCUMENT_NODE:
|
490
|
+
doc = NULL;
|
491
|
+
break;
|
492
|
+
case XML_ATTRIBUTE_NODE:
|
493
|
+
{
|
494
|
+
xmlAttrPtr attr = (xmlAttrPtr) xnode;
|
495
|
+
doc = attr->doc;
|
496
|
+
break;
|
497
|
+
}
|
498
|
+
case XML_NAMESPACE_DECL:
|
499
|
+
doc = NULL;
|
500
|
+
break;
|
501
|
+
default:
|
502
|
+
doc = xnode->doc;
|
503
|
+
break;
|
504
|
+
}
|
505
|
+
|
506
|
+
if (doc == NULL)
|
507
|
+
return (Qnil);
|
508
|
+
|
509
|
+
if (doc->_private == NULL)
|
510
|
+
rb_raise(rb_eRuntimeError, "existing document object has no ruby-instance");
|
511
|
+
|
512
|
+
return (VALUE) doc->_private;
|
513
|
+
}
|
514
|
+
|
515
|
+
/*
|
516
|
+
* call-seq:
|
517
|
+
* node.to_s -> "string"
|
518
|
+
* node.to_s(:indent => true, :encoding => 'UTF-8', :level => 0) -> "string"
|
519
|
+
*
|
520
|
+
* Converts a node, and all of its children, to a string representation.
|
521
|
+
* You may provide an optional hash table to control how the string is
|
522
|
+
* generated. Valid options are:
|
523
|
+
*
|
524
|
+
* :indent - Specifies if the string should be indented. The default value
|
525
|
+
* is true. Note that indentation is only added if both :indent is
|
526
|
+
* true and XML.indent_tree_output is true. If :indent is set to false,
|
527
|
+
* then both indentation and line feeds are removed from the result.
|
528
|
+
*
|
529
|
+
* :level - Specifies the indentation level. The amount of indentation
|
530
|
+
* is equal to the (level * number_spaces) + number_spaces, where libxml
|
531
|
+
* defaults the number of spaces to 2. Thus a level of 0 results in
|
532
|
+
* 2 spaces, level 1 results in 4 spaces, level 2 results in 6 spaces, etc.
|
533
|
+
*
|
534
|
+
* :encoding - Specifies the output encoding of the string. It
|
535
|
+
* defaults to XML::Encoding::UTF8. To change it, use one of the
|
536
|
+
* XML::Encoding encoding constants. */
|
537
|
+
|
538
|
+
static VALUE rxml_node_to_s(int argc, VALUE *argv, VALUE self)
|
539
|
+
{
|
540
|
+
VALUE result = Qnil;
|
541
|
+
VALUE options = Qnil;
|
542
|
+
xmlNodePtr xnode;
|
543
|
+
xmlCharEncodingHandlerPtr encodingHandler;
|
544
|
+
xmlOutputBufferPtr output;
|
545
|
+
|
546
|
+
int level = 0;
|
547
|
+
int indent = 1;
|
548
|
+
const char *xencoding = NULL;
|
549
|
+
|
550
|
+
rb_scan_args(argc, argv, "01", &options);
|
551
|
+
|
552
|
+
if (!NIL_P(options))
|
553
|
+
{
|
554
|
+
VALUE rencoding, rindent, rlevel;
|
555
|
+
Check_Type(options, T_HASH);
|
556
|
+
rencoding = rb_hash_aref(options, ID2SYM(rb_intern("encoding")));
|
557
|
+
rindent = rb_hash_aref(options, ID2SYM(rb_intern("indent")));
|
558
|
+
rlevel = rb_hash_aref(options, ID2SYM(rb_intern("level")));
|
559
|
+
|
560
|
+
if (rindent == Qfalse)
|
561
|
+
indent = 0;
|
562
|
+
|
563
|
+
if (rlevel != Qnil)
|
564
|
+
level = NUM2INT(rlevel);
|
565
|
+
|
566
|
+
if (rencoding != Qnil)
|
567
|
+
{
|
568
|
+
xencoding = xmlGetCharEncodingName((xmlCharEncoding)NUM2INT(rencoding));
|
569
|
+
if (!xencoding)
|
570
|
+
rb_raise(rb_eArgError, "Unknown encoding value: %d", NUM2INT(rencoding));
|
571
|
+
}
|
572
|
+
}
|
573
|
+
|
574
|
+
encodingHandler = xmlFindCharEncodingHandler(xencoding);
|
575
|
+
output = xmlAllocOutputBuffer(encodingHandler);
|
576
|
+
|
577
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
578
|
+
xmlNodeDumpOutput(output, xnode->doc, xnode, level, indent, xencoding);
|
579
|
+
xmlOutputBufferFlush(output);
|
580
|
+
|
581
|
+
if (output->conv)
|
582
|
+
result = rb_str_new2((const char*) output->conv->content);
|
583
|
+
else
|
584
|
+
result = rb_str_new2((const char*) output->buffer->content);
|
585
|
+
|
586
|
+
xmlOutputBufferClose(output);
|
587
|
+
|
588
|
+
return result;
|
589
|
+
}
|
590
|
+
|
591
|
+
|
592
|
+
/*
|
593
|
+
* call-seq:
|
594
|
+
* node.each -> XML::Node
|
595
|
+
*
|
596
|
+
* Iterates over this node's children, including text
|
597
|
+
* nodes, element nodes, etc. If you wish to iterate
|
598
|
+
* only over child elements, use XML::Node#each_element.
|
599
|
+
*
|
600
|
+
* doc = XML::Document.new('model/books.xml')
|
601
|
+
* doc.root.each {|node| puts node}
|
602
|
+
*/
|
603
|
+
static VALUE rxml_node_each(VALUE self)
|
604
|
+
{
|
605
|
+
xmlNodePtr xnode;
|
606
|
+
xmlNodePtr xchild;
|
607
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
608
|
+
|
609
|
+
xchild = xnode->children;
|
610
|
+
|
611
|
+
while (xchild)
|
612
|
+
{
|
613
|
+
rb_yield(rxml_node_wrap(xchild));
|
614
|
+
xchild = xchild->next;
|
615
|
+
}
|
616
|
+
return Qnil;
|
617
|
+
}
|
618
|
+
|
619
|
+
/*
|
620
|
+
* call-seq:
|
621
|
+
* node.empty? -> (true|false)
|
622
|
+
*
|
623
|
+
* Determine whether this node is empty.
|
624
|
+
*/
|
625
|
+
static VALUE rxml_node_empty_q(VALUE self)
|
626
|
+
{
|
627
|
+
xmlNodePtr xnode;
|
628
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
629
|
+
if (xnode == NULL)
|
630
|
+
return (Qnil);
|
631
|
+
|
632
|
+
return ((xmlIsBlankNode(xnode) == 1) ? Qtrue : Qfalse);
|
633
|
+
}
|
634
|
+
|
635
|
+
|
636
|
+
/*
|
637
|
+
* call-seq:
|
638
|
+
* node.eql?(other_node) => (true|false)
|
639
|
+
*
|
640
|
+
* Test equality between the two nodes. Two nodes are equal
|
641
|
+
* if they are the same node or have the same XML representation.*/
|
642
|
+
static VALUE rxml_node_eql_q(VALUE self, VALUE other)
|
643
|
+
{
|
644
|
+
if(self == other)
|
645
|
+
{
|
646
|
+
return Qtrue;
|
647
|
+
}
|
648
|
+
else if (NIL_P(other))
|
649
|
+
{
|
650
|
+
return Qfalse;
|
651
|
+
}
|
652
|
+
else
|
653
|
+
{
|
654
|
+
VALUE self_xml;
|
655
|
+
VALUE other_xml;
|
656
|
+
|
657
|
+
if (rb_obj_is_kind_of(other, cXMLNode) == Qfalse)
|
658
|
+
rb_raise(rb_eTypeError, "Nodes can only be compared against other nodes");
|
659
|
+
|
660
|
+
self_xml = rxml_node_to_s(0, NULL, self);
|
661
|
+
other_xml = rxml_node_to_s(0, NULL, other);
|
662
|
+
return(rb_funcall(self_xml, rb_intern("=="), 1, other_xml));
|
663
|
+
}
|
664
|
+
}
|
665
|
+
|
666
|
+
/*
|
667
|
+
* call-seq:
|
668
|
+
* node.lang -> "string"
|
669
|
+
*
|
670
|
+
* Obtain the language set for this node, if any.
|
671
|
+
* This is set in XML via the xml:lang attribute.
|
672
|
+
*/
|
673
|
+
static VALUE rxml_node_lang_get(VALUE self)
|
674
|
+
{
|
675
|
+
xmlNodePtr xnode;
|
676
|
+
xmlChar *lang;
|
677
|
+
VALUE result = Qnil;
|
678
|
+
|
679
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
680
|
+
lang = xmlNodeGetLang(xnode);
|
681
|
+
|
682
|
+
if (lang)
|
683
|
+
{
|
684
|
+
result = rb_str_new2((const char*) lang);
|
685
|
+
xmlFree(lang);
|
686
|
+
}
|
687
|
+
|
688
|
+
return (result);
|
689
|
+
}
|
690
|
+
|
691
|
+
// TODO node_lang_set should support setting back to nil
|
692
|
+
|
693
|
+
/*
|
694
|
+
* call-seq:
|
695
|
+
* node.lang = "string"
|
696
|
+
*
|
697
|
+
* Set the language for this node. This affects the value
|
698
|
+
* of the xml:lang attribute.
|
699
|
+
*/
|
700
|
+
static VALUE rxml_node_lang_set(VALUE self, VALUE lang)
|
701
|
+
{
|
702
|
+
xmlNodePtr xnode;
|
703
|
+
|
704
|
+
Check_Type(lang, T_STRING);
|
705
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
706
|
+
xmlNodeSetLang(xnode, (xmlChar*) StringValuePtr(lang));
|
707
|
+
|
708
|
+
return (Qtrue);
|
709
|
+
}
|
710
|
+
|
711
|
+
/*
|
712
|
+
* call-seq:
|
713
|
+
* node.last -> XML::Node
|
714
|
+
*
|
715
|
+
* Obtain the last child node of this node, if any.
|
716
|
+
*/
|
717
|
+
static VALUE rxml_node_last_get(VALUE self)
|
718
|
+
{
|
719
|
+
xmlNodePtr xnode;
|
720
|
+
|
721
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
722
|
+
|
723
|
+
if (xnode->last)
|
724
|
+
return (rxml_node_wrap(xnode->last));
|
725
|
+
else
|
726
|
+
return (Qnil);
|
727
|
+
}
|
728
|
+
|
729
|
+
/*
|
730
|
+
* call-seq:
|
731
|
+
* node.line_num -> num
|
732
|
+
*
|
733
|
+
* Obtain the line number (in the XML document) that this
|
734
|
+
* node was read from. If +default_line_numbers+ is set
|
735
|
+
* false (the default), this method returns zero.
|
736
|
+
*/
|
737
|
+
static VALUE rxml_node_line_num(VALUE self)
|
738
|
+
{
|
739
|
+
xmlNodePtr xnode;
|
740
|
+
long line_num;
|
741
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
742
|
+
|
743
|
+
if (!xmlLineNumbersDefaultValue)
|
744
|
+
rb_warn(
|
745
|
+
"Line numbers were not retained: use XML::Parser::default_line_numbers=true");
|
746
|
+
|
747
|
+
line_num = xmlGetLineNo(xnode);
|
748
|
+
if (line_num == -1)
|
749
|
+
return (Qnil);
|
750
|
+
else
|
751
|
+
return (INT2NUM((long) line_num));
|
752
|
+
}
|
753
|
+
|
754
|
+
/*
|
755
|
+
* call-seq:
|
756
|
+
* node.xlink? -> (true|false)
|
757
|
+
*
|
758
|
+
* Determine whether this node is an xlink node.
|
759
|
+
*/
|
760
|
+
static VALUE rxml_node_xlink_q(VALUE self)
|
761
|
+
{
|
762
|
+
xmlNodePtr xnode;
|
763
|
+
xlinkType xlt;
|
764
|
+
|
765
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
766
|
+
xlt = xlinkIsLink(xnode->doc, xnode);
|
767
|
+
|
768
|
+
if (xlt == XLINK_TYPE_NONE)
|
769
|
+
return (Qfalse);
|
770
|
+
else
|
771
|
+
return (Qtrue);
|
772
|
+
}
|
773
|
+
|
774
|
+
/*
|
775
|
+
* call-seq:
|
776
|
+
* node.xlink_type -> num
|
777
|
+
*
|
778
|
+
* Obtain the type identifier for this xlink, if applicable.
|
779
|
+
* If this is not an xlink node (see +xlink?+), will return
|
780
|
+
* nil.
|
781
|
+
*/
|
782
|
+
static VALUE rxml_node_xlink_type(VALUE self)
|
783
|
+
{
|
784
|
+
xmlNodePtr xnode;
|
785
|
+
xlinkType xlt;
|
786
|
+
|
787
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
788
|
+
xlt = xlinkIsLink(xnode->doc, xnode);
|
789
|
+
|
790
|
+
if (xlt == XLINK_TYPE_NONE)
|
791
|
+
return (Qnil);
|
792
|
+
else
|
793
|
+
return (INT2NUM(xlt));
|
794
|
+
}
|
795
|
+
|
796
|
+
/*
|
797
|
+
* call-seq:
|
798
|
+
* node.xlink_type_name -> "string"
|
799
|
+
*
|
800
|
+
* Obtain the type name for this xlink, if applicable.
|
801
|
+
* If this is not an xlink node (see +xlink?+), will return
|
802
|
+
* nil.
|
803
|
+
*/
|
804
|
+
static VALUE rxml_node_xlink_type_name(VALUE self)
|
805
|
+
{
|
806
|
+
xmlNodePtr xnode;
|
807
|
+
xlinkType xlt;
|
808
|
+
|
809
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
810
|
+
xlt = xlinkIsLink(xnode->doc, xnode);
|
811
|
+
|
812
|
+
switch (xlt)
|
813
|
+
{
|
814
|
+
case XLINK_TYPE_NONE:
|
815
|
+
return (Qnil);
|
816
|
+
case XLINK_TYPE_SIMPLE:
|
817
|
+
return (rb_str_new2("simple"));
|
818
|
+
case XLINK_TYPE_EXTENDED:
|
819
|
+
return (rb_str_new2("extended"));
|
820
|
+
case XLINK_TYPE_EXTENDED_SET:
|
821
|
+
return (rb_str_new2("extended_set"));
|
822
|
+
default:
|
823
|
+
rb_fatal("Unknowng xlink type, %d", xlt);
|
824
|
+
}
|
825
|
+
}
|
826
|
+
|
827
|
+
/*
|
828
|
+
* call-seq:
|
829
|
+
* node.name -> "string"
|
830
|
+
*
|
831
|
+
* Obtain this node's name.
|
832
|
+
*/
|
833
|
+
static VALUE rxml_node_name_get(VALUE self)
|
834
|
+
{
|
835
|
+
xmlNodePtr xnode;
|
836
|
+
const xmlChar *name;
|
837
|
+
|
838
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
839
|
+
|
840
|
+
switch (xnode->type)
|
841
|
+
{
|
842
|
+
case XML_DOCUMENT_NODE:
|
843
|
+
#ifdef LIBXML_DOCB_ENABLED
|
844
|
+
case XML_DOCB_DOCUMENT_NODE:
|
845
|
+
#endif
|
846
|
+
case XML_HTML_DOCUMENT_NODE:
|
847
|
+
{
|
848
|
+
xmlDocPtr doc = (xmlDocPtr) xnode;
|
849
|
+
name = doc->URL;
|
850
|
+
break;
|
851
|
+
}
|
852
|
+
case XML_ATTRIBUTE_NODE:
|
853
|
+
{
|
854
|
+
xmlAttrPtr attr = (xmlAttrPtr) xnode;
|
855
|
+
name = attr->name;
|
856
|
+
break;
|
857
|
+
}
|
858
|
+
case XML_NAMESPACE_DECL:
|
859
|
+
{
|
860
|
+
xmlNsPtr ns = (xmlNsPtr) xnode;
|
861
|
+
name = ns->prefix;
|
862
|
+
break;
|
863
|
+
}
|
864
|
+
default:
|
865
|
+
name = xnode->name;
|
866
|
+
break;
|
867
|
+
}
|
868
|
+
|
869
|
+
if (xnode->name == NULL)
|
870
|
+
return (Qnil);
|
871
|
+
else if (name == xmlStringText)
|
872
|
+
return (kXMLStringText);
|
873
|
+
else if (name == xmlStringTextNoenc)
|
874
|
+
return (kXMLStringTextNoenc);
|
875
|
+
else
|
876
|
+
return (rb_str_new2((const char*) name));
|
877
|
+
}
|
878
|
+
|
879
|
+
/*
|
880
|
+
* call-seq:
|
881
|
+
* node.name = "string"
|
882
|
+
*
|
883
|
+
* Set this node's name.
|
884
|
+
*/
|
885
|
+
static VALUE rxml_node_name_set(VALUE self, VALUE name)
|
886
|
+
{
|
887
|
+
xmlNodePtr xnode;
|
888
|
+
const xmlChar *xname;
|
889
|
+
|
890
|
+
Check_Type(name, T_STRING);
|
891
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
892
|
+
xname = (const xmlChar*)StringValuePtr(name);
|
893
|
+
|
894
|
+
if (xnode->type != XML_TEXT_NODE)
|
895
|
+
xmlNodeSetName(xnode, xname);
|
896
|
+
else if (xname == xmlStringText) /* compare addresses instead of string contents. */
|
897
|
+
xnode->name = xmlStringText;
|
898
|
+
else if (xname == xmlStringTextNoenc) /* compare addresses instead of string contents. */
|
899
|
+
xnode->name = xmlStringTextNoenc;
|
900
|
+
|
901
|
+
/* Note: calling xmlNodeSetName() for a text node is ignored by libXML. */
|
902
|
+
return (Qtrue);
|
903
|
+
}
|
904
|
+
|
905
|
+
/*
|
906
|
+
* call-seq:
|
907
|
+
* node.next -> XML::Node
|
908
|
+
*
|
909
|
+
* Obtain the next sibling node, if any.
|
910
|
+
*/
|
911
|
+
static VALUE rxml_node_next_get(VALUE self)
|
912
|
+
{
|
913
|
+
xmlNodePtr xnode;
|
914
|
+
|
915
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
916
|
+
|
917
|
+
if (xnode->next)
|
918
|
+
return (rxml_node_wrap(xnode->next));
|
919
|
+
else
|
920
|
+
return (Qnil);
|
921
|
+
}
|
922
|
+
|
923
|
+
/*
|
924
|
+
* call-seq:
|
925
|
+
* node.next = node
|
926
|
+
*
|
927
|
+
* Insert the specified node as this node's next sibling.
|
928
|
+
*/
|
929
|
+
static VALUE rxml_node_next_set(VALUE self, VALUE rnode)
|
930
|
+
{
|
931
|
+
xmlNodePtr cnode, pnode, ret;
|
932
|
+
|
933
|
+
if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
|
934
|
+
rb_raise(rb_eTypeError, "Must pass an XML::Node object");
|
935
|
+
|
936
|
+
Data_Get_Struct(self, xmlNode, pnode);
|
937
|
+
Data_Get_Struct(rnode, xmlNode, cnode);
|
938
|
+
|
939
|
+
ret = xmlAddNextSibling(pnode, cnode);
|
940
|
+
if (ret == NULL)
|
941
|
+
rxml_raise(&xmlLastError);
|
942
|
+
|
943
|
+
return (rxml_node_wrap(ret));
|
944
|
+
}
|
945
|
+
|
946
|
+
/*
|
947
|
+
* call-seq:
|
948
|
+
* node.parent -> XML::Node
|
949
|
+
*
|
950
|
+
* Obtain this node's parent node, if any.
|
951
|
+
*/
|
952
|
+
static VALUE rxml_node_parent_get(VALUE self)
|
953
|
+
{
|
954
|
+
xmlNodePtr xnode;
|
955
|
+
|
956
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
957
|
+
|
958
|
+
if (xnode->parent)
|
959
|
+
return (rxml_node_wrap(xnode->parent));
|
960
|
+
else
|
961
|
+
return (Qnil);
|
962
|
+
}
|
963
|
+
|
964
|
+
/*
|
965
|
+
* call-seq:
|
966
|
+
* node.path -> path
|
967
|
+
*
|
968
|
+
* Obtain this node's path.
|
969
|
+
*/
|
970
|
+
static VALUE rxml_node_path(VALUE self)
|
971
|
+
{
|
972
|
+
xmlNodePtr xnode;
|
973
|
+
xmlChar *path;
|
974
|
+
|
975
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
976
|
+
path = xmlGetNodePath(xnode);
|
977
|
+
|
978
|
+
if (path == NULL)
|
979
|
+
return (Qnil);
|
980
|
+
else
|
981
|
+
return (rb_str_new2((const char*) path));
|
982
|
+
}
|
983
|
+
|
984
|
+
/*
|
985
|
+
* call-seq:
|
986
|
+
* node.pointer -> XML::NodeSet
|
987
|
+
*
|
988
|
+
* Evaluates an XPointer expression relative to this node.
|
989
|
+
*/
|
990
|
+
static VALUE rxml_node_pointer(VALUE self, VALUE xptr_str)
|
991
|
+
{
|
992
|
+
return (rxml_xpointer_point2(self, xptr_str));
|
993
|
+
}
|
994
|
+
|
995
|
+
/*
|
996
|
+
* call-seq:
|
997
|
+
* node.prev -> XML::Node
|
998
|
+
*
|
999
|
+
* Obtain the previous sibling, if any.
|
1000
|
+
*/
|
1001
|
+
static VALUE rxml_node_prev_get(VALUE self)
|
1002
|
+
{
|
1003
|
+
xmlNodePtr xnode;
|
1004
|
+
xmlNodePtr node;
|
1005
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
1006
|
+
|
1007
|
+
switch (xnode->type)
|
1008
|
+
{
|
1009
|
+
case XML_DOCUMENT_NODE:
|
1010
|
+
#ifdef LIBXML_DOCB_ENABLED
|
1011
|
+
case XML_DOCB_DOCUMENT_NODE:
|
1012
|
+
#endif
|
1013
|
+
case XML_HTML_DOCUMENT_NODE:
|
1014
|
+
case XML_NAMESPACE_DECL:
|
1015
|
+
node = NULL;
|
1016
|
+
break;
|
1017
|
+
case XML_ATTRIBUTE_NODE:
|
1018
|
+
{
|
1019
|
+
xmlAttrPtr attr = (xmlAttrPtr) xnode;
|
1020
|
+
node = (xmlNodePtr) attr->prev;
|
1021
|
+
}
|
1022
|
+
break;
|
1023
|
+
default:
|
1024
|
+
node = xnode->prev;
|
1025
|
+
break;
|
1026
|
+
}
|
1027
|
+
|
1028
|
+
if (node == NULL)
|
1029
|
+
return (Qnil);
|
1030
|
+
else
|
1031
|
+
return (rxml_node_wrap(node));
|
1032
|
+
}
|
1033
|
+
|
1034
|
+
/*
|
1035
|
+
* call-seq:
|
1036
|
+
* node.prev = node
|
1037
|
+
*
|
1038
|
+
* Insert the specified node as this node's previous sibling.
|
1039
|
+
*/
|
1040
|
+
static VALUE rxml_node_prev_set(VALUE self, VALUE rnode)
|
1041
|
+
{
|
1042
|
+
xmlNodePtr cnode, pnode, ret;
|
1043
|
+
|
1044
|
+
if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
|
1045
|
+
rb_raise(rb_eTypeError, "Must pass an XML::Node object");
|
1046
|
+
|
1047
|
+
Data_Get_Struct(self, xmlNode, pnode);
|
1048
|
+
Data_Get_Struct(rnode, xmlNode, cnode);
|
1049
|
+
|
1050
|
+
ret = xmlAddPrevSibling(pnode, cnode);
|
1051
|
+
if (ret == NULL)
|
1052
|
+
rxml_raise(&xmlLastError);
|
1053
|
+
|
1054
|
+
return (rxml_node_wrap(ret));
|
1055
|
+
}
|
1056
|
+
|
1057
|
+
/*
|
1058
|
+
* call-seq:
|
1059
|
+
* node.attributes -> attributes
|
1060
|
+
*
|
1061
|
+
* Returns the XML::Attributes for this node.
|
1062
|
+
*/
|
1063
|
+
static VALUE rxml_node_attributes_get(VALUE self)
|
1064
|
+
{
|
1065
|
+
xmlNodePtr xnode;
|
1066
|
+
|
1067
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
1068
|
+
return rxml_attributes_new(xnode);
|
1069
|
+
}
|
1070
|
+
|
1071
|
+
/*
|
1072
|
+
* call-seq:
|
1073
|
+
* node.property("name") -> "string"
|
1074
|
+
* node["name"] -> "string"
|
1075
|
+
*
|
1076
|
+
* Obtain the named pyroperty.
|
1077
|
+
*/
|
1078
|
+
static VALUE rxml_node_attribute_get(VALUE self, VALUE name)
|
1079
|
+
{
|
1080
|
+
VALUE attributes = rxml_node_attributes_get(self);
|
1081
|
+
return rxml_attributes_attribute_get(attributes, name);
|
1082
|
+
}
|
1083
|
+
|
1084
|
+
/*
|
1085
|
+
* call-seq:
|
1086
|
+
* node["name"] = "string"
|
1087
|
+
*
|
1088
|
+
* Set the named property.
|
1089
|
+
*/
|
1090
|
+
static VALUE rxml_node_property_set(VALUE self, VALUE name, VALUE value)
|
1091
|
+
{
|
1092
|
+
VALUE attributes = rxml_node_attributes_get(self);
|
1093
|
+
return rxml_attributes_attribute_set(attributes, name, value);
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
/*
|
1097
|
+
* call-seq:
|
1098
|
+
* node.remove! -> node
|
1099
|
+
*
|
1100
|
+
* Removes this node and its children from its
|
1101
|
+
* document tree by setting its document,
|
1102
|
+
* parent and siblings to nil. You can add
|
1103
|
+
* the returned node back into a document.
|
1104
|
+
* Otherwise, the node will be freed once
|
1105
|
+
* any references to it go out of scope. */
|
1106
|
+
|
1107
|
+
static VALUE rxml_node_remove_ex(VALUE self)
|
1108
|
+
{
|
1109
|
+
xmlNodePtr xnode;
|
1110
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
1111
|
+
/* Unlink the node from its parent. */
|
1112
|
+
xmlUnlinkNode(xnode);
|
1113
|
+
/* Now set the nodes parent to nil so it can
|
1114
|
+
be freed if the reference to it goes out of scope*/
|
1115
|
+
xmlSetTreeDoc(xnode, NULL);
|
1116
|
+
|
1117
|
+
/* Now return the removed node so the user can
|
1118
|
+
do something wiht it.*/
|
1119
|
+
return self;
|
1120
|
+
}
|
1121
|
+
|
1122
|
+
/*
|
1123
|
+
* call-seq:
|
1124
|
+
* node.sibling(node) -> XML::Node
|
1125
|
+
*
|
1126
|
+
* Add the specified node as a sibling of this node.
|
1127
|
+
*/
|
1128
|
+
static VALUE rxml_node_sibling_set(VALUE self, VALUE rnode)
|
1129
|
+
{
|
1130
|
+
xmlNodePtr cnode, pnode, ret;
|
1131
|
+
VALUE obj;
|
1132
|
+
|
1133
|
+
if (rb_obj_is_kind_of(rnode, cXMLNode) == Qfalse)
|
1134
|
+
rb_raise(rb_eTypeError, "Must pass an XML::Node object");
|
1135
|
+
|
1136
|
+
Data_Get_Struct(self, xmlNode, pnode);
|
1137
|
+
Data_Get_Struct(rnode, xmlNode, cnode);
|
1138
|
+
|
1139
|
+
ret = xmlAddSibling(pnode, cnode);
|
1140
|
+
if (ret == NULL)
|
1141
|
+
rxml_raise(&xmlLastError);
|
1142
|
+
|
1143
|
+
if (ret->_private == NULL)
|
1144
|
+
obj = rxml_node_wrap(ret);
|
1145
|
+
else
|
1146
|
+
obj = (VALUE) ret->_private;
|
1147
|
+
|
1148
|
+
return obj;
|
1149
|
+
}
|
1150
|
+
|
1151
|
+
/*
|
1152
|
+
* call-seq:
|
1153
|
+
* node.space_preserve -> (true|false)
|
1154
|
+
*
|
1155
|
+
* Determine whether this node preserves whitespace.
|
1156
|
+
*/
|
1157
|
+
static VALUE rxml_node_space_preserve_get(VALUE self)
|
1158
|
+
{
|
1159
|
+
xmlNodePtr xnode;
|
1160
|
+
|
1161
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
1162
|
+
return (INT2NUM(xmlNodeGetSpacePreserve(xnode)));
|
1163
|
+
}
|
1164
|
+
|
1165
|
+
/*
|
1166
|
+
* call-seq:
|
1167
|
+
* node.space_preserve = true|false
|
1168
|
+
*
|
1169
|
+
* Control whether this node preserves whitespace.
|
1170
|
+
*/
|
1171
|
+
static VALUE rxml_node_space_preserve_set(VALUE self, VALUE bool)
|
1172
|
+
{
|
1173
|
+
xmlNodePtr xnode;
|
1174
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
1175
|
+
|
1176
|
+
if (TYPE(bool) == T_FALSE)
|
1177
|
+
xmlNodeSetSpacePreserve(xnode, 1);
|
1178
|
+
else
|
1179
|
+
xmlNodeSetSpacePreserve(xnode, 0);
|
1180
|
+
|
1181
|
+
return (Qnil);
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
/*
|
1185
|
+
* call-seq:
|
1186
|
+
* node.type -> num
|
1187
|
+
*
|
1188
|
+
* Obtain this node's type identifier.
|
1189
|
+
*/
|
1190
|
+
static VALUE rxml_node_type(VALUE self)
|
1191
|
+
{
|
1192
|
+
xmlNodePtr xnode;
|
1193
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
1194
|
+
return (INT2NUM(xnode->type));
|
1195
|
+
}
|
1196
|
+
|
1197
|
+
/*
|
1198
|
+
* call-seq:
|
1199
|
+
* node.copy -> XML::Node
|
1200
|
+
*
|
1201
|
+
* Creates a copy of this node. To create a
|
1202
|
+
* shallow copy set the deep parameter to false.
|
1203
|
+
* To create a deep copy set the deep parameter
|
1204
|
+
* to true.
|
1205
|
+
*
|
1206
|
+
*/
|
1207
|
+
static VALUE rxml_node_copy(VALUE self, VALUE deep)
|
1208
|
+
{
|
1209
|
+
xmlNodePtr xnode;
|
1210
|
+
xmlNodePtr xcopy;
|
1211
|
+
int recursive = (deep == Qnil || deep == Qfalse) ? 0 : 1;
|
1212
|
+
Data_Get_Struct(self, xmlNode, xnode);
|
1213
|
+
|
1214
|
+
xcopy = xmlCopyNode(xnode, recursive);
|
1215
|
+
|
1216
|
+
if (xcopy)
|
1217
|
+
return rxml_node_wrap(xcopy);
|
1218
|
+
else
|
1219
|
+
return Qnil;
|
1220
|
+
}
|
1221
|
+
|
1222
|
+
void rxml_node_registerNode(xmlNodePtr node)
|
1223
|
+
{
|
1224
|
+
node->_private = NULL;
|
1225
|
+
}
|
1226
|
+
|
1227
|
+
void rxml_node_deregisterNode(xmlNodePtr xnode)
|
1228
|
+
{
|
1229
|
+
VALUE node;
|
1230
|
+
|
1231
|
+
if (xnode->_private == NULL)
|
1232
|
+
return;
|
1233
|
+
node = (VALUE) xnode->_private;
|
1234
|
+
DATA_PTR( node) = NULL;
|
1235
|
+
}
|
1236
|
+
|
1237
|
+
// Rdoc needs to know
|
1238
|
+
#ifdef RDOC_NEVER_DEFINED
|
1239
|
+
mLibXML = rb_define_module("LibXML");
|
1240
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
1241
|
+
#endif
|
1242
|
+
|
1243
|
+
static VALUE rxml_constant_stringref(const xmlChar *ptr)
|
1244
|
+
{
|
1245
|
+
VALUE str = rb_str_new("", 0);
|
1246
|
+
FL_SET(str, ELTS_SHARED | FL_USER3);
|
1247
|
+
xfree(RSTRING_PTR(str));
|
1248
|
+
RSTRING_PTR(str) = (void*)ptr;
|
1249
|
+
RSTRING_LEN(str) = strlen(ptr);
|
1250
|
+
RSTRING(str)->aux.capa = 0;
|
1251
|
+
OBJ_FREEZE(str);
|
1252
|
+
return str;
|
1253
|
+
}
|
1254
|
+
|
1255
|
+
void ruby_init_xml_node(void)
|
1256
|
+
{
|
1257
|
+
xmlRegisterNodeDefault(rxml_node_registerNode);
|
1258
|
+
xmlDeregisterNodeDefault(rxml_node_deregisterNode);
|
1259
|
+
|
1260
|
+
kXMLStringText = rxml_constant_stringref(xmlStringText);
|
1261
|
+
kXMLStringTextNoenc = rxml_constant_stringref(xmlStringTextNoenc);
|
1262
|
+
|
1263
|
+
cXMLNode = rb_define_class_under(mXML, "Node", rb_cObject);
|
1264
|
+
|
1265
|
+
rb_define_const(cXMLNode, "SPACE_DEFAULT", INT2NUM(0));
|
1266
|
+
rb_define_const(cXMLNode, "SPACE_PRESERVE", INT2NUM(1));
|
1267
|
+
rb_define_const(cXMLNode, "SPACE_NOT_INHERIT", INT2NUM(-1));
|
1268
|
+
rb_define_const(cXMLNode, "XLINK_ACTUATE_AUTO", INT2NUM(1));
|
1269
|
+
rb_define_const(cXMLNode, "XLINK_ACTUATE_NONE", INT2NUM(0));
|
1270
|
+
rb_define_const(cXMLNode, "XLINK_ACTUATE_ONREQUEST", INT2NUM(2));
|
1271
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_EMBED", INT2NUM(2));
|
1272
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_NEW", INT2NUM(1));
|
1273
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_NONE", INT2NUM(0));
|
1274
|
+
rb_define_const(cXMLNode, "XLINK_SHOW_REPLACE", INT2NUM(3));
|
1275
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_EXTENDED", INT2NUM(2));
|
1276
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_EXTENDED_SET", INT2NUM(3));
|
1277
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_NONE", INT2NUM(0));
|
1278
|
+
rb_define_const(cXMLNode, "XLINK_TYPE_SIMPLE", INT2NUM(1));
|
1279
|
+
|
1280
|
+
rb_define_const(cXMLNode, "ELEMENT_NODE", INT2FIX(XML_ELEMENT_NODE));
|
1281
|
+
rb_define_const(cXMLNode, "ATTRIBUTE_NODE", INT2FIX(XML_ATTRIBUTE_NODE));
|
1282
|
+
rb_define_const(cXMLNode, "TEXT_NODE", INT2FIX(XML_TEXT_NODE));
|
1283
|
+
rb_define_const(cXMLNode, "CDATA_SECTION_NODE", INT2FIX(XML_CDATA_SECTION_NODE));
|
1284
|
+
rb_define_const(cXMLNode, "ENTITY_REF_NODE", INT2FIX(XML_ENTITY_REF_NODE));
|
1285
|
+
rb_define_const(cXMLNode, "ENTITY_NODE", INT2FIX(XML_ENTITY_NODE));
|
1286
|
+
rb_define_const(cXMLNode, "PI_NODE", INT2FIX(XML_PI_NODE));
|
1287
|
+
rb_define_const(cXMLNode, "COMMENT_NODE", INT2FIX(XML_COMMENT_NODE));
|
1288
|
+
rb_define_const(cXMLNode, "DOCUMENT_NODE", INT2FIX(XML_DOCUMENT_NODE));
|
1289
|
+
rb_define_const(cXMLNode, "DOCUMENT_TYPE_NODE", INT2FIX(XML_DOCUMENT_TYPE_NODE));
|
1290
|
+
rb_define_const(cXMLNode, "DOCUMENT_FRAG_NODE", INT2FIX(XML_DOCUMENT_FRAG_NODE));
|
1291
|
+
rb_define_const(cXMLNode, "NOTATION_NODE", INT2FIX(XML_NOTATION_NODE));
|
1292
|
+
rb_define_const(cXMLNode, "HTML_DOCUMENT_NODE", INT2FIX(XML_HTML_DOCUMENT_NODE));
|
1293
|
+
rb_define_const(cXMLNode, "DTD_NODE", INT2FIX(XML_DTD_NODE));
|
1294
|
+
rb_define_const(cXMLNode, "ELEMENT_DECL", INT2FIX(XML_ELEMENT_DECL));
|
1295
|
+
rb_define_const(cXMLNode, "ATTRIBUTE_DECL", INT2FIX(XML_ATTRIBUTE_DECL));
|
1296
|
+
rb_define_const(cXMLNode, "ENTITY_DECL", INT2FIX(XML_ENTITY_DECL));
|
1297
|
+
rb_define_const(cXMLNode, "NAMESPACE_DECL", INT2FIX(XML_NAMESPACE_DECL));
|
1298
|
+
rb_define_const(cXMLNode, "XINCLUDE_START", INT2FIX(XML_XINCLUDE_START));
|
1299
|
+
rb_define_const(cXMLNode, "XINCLUDE_END", INT2FIX(XML_XINCLUDE_END));
|
1300
|
+
|
1301
|
+
#ifdef LIBXML_DOCB_ENABLED
|
1302
|
+
rb_define_const(cXMLNode, "DOCB_DOCUMENT_NODE", INT2FIX(XML_DOCB_DOCUMENT_NODE));
|
1303
|
+
#else
|
1304
|
+
rb_define_const(cXMLNode, "DOCB_DOCUMENT_NODE", Qnil);
|
1305
|
+
#endif
|
1306
|
+
|
1307
|
+
rb_define_const(cXMLNode, "XML_STRING_TEXT", kXMLStringText);
|
1308
|
+
rb_define_const(cXMLNode, "XML_STRING_TEXT_NOENC", kXMLStringTextNoenc);
|
1309
|
+
|
1310
|
+
rb_define_singleton_method(cXMLNode, "new_cdata", rxml_node_new_cdata, -1);
|
1311
|
+
rb_define_singleton_method(cXMLNode, "new_comment", rxml_node_new_comment, -1);
|
1312
|
+
rb_define_singleton_method(cXMLNode, "new_text", rxml_node_new_text, 1);
|
1313
|
+
|
1314
|
+
/* Initialization */
|
1315
|
+
rb_define_alloc_func(cXMLNode, rxml_node_alloc);
|
1316
|
+
rb_define_method(cXMLNode, "initialize", rxml_node_initialize, -1);
|
1317
|
+
|
1318
|
+
/* Traversal */
|
1319
|
+
rb_include_module(cXMLNode, rb_mEnumerable);
|
1320
|
+
rb_define_method(cXMLNode, "[]", rxml_node_attribute_get, 1);
|
1321
|
+
rb_define_method(cXMLNode, "each", rxml_node_each, 0);
|
1322
|
+
rb_define_method(cXMLNode, "first", rxml_node_first_get, 0);
|
1323
|
+
rb_define_method(cXMLNode, "last", rxml_node_last_get, 0);
|
1324
|
+
rb_define_method(cXMLNode, "next", rxml_node_next_get, 0);
|
1325
|
+
rb_define_method(cXMLNode, "parent", rxml_node_parent_get, 0);
|
1326
|
+
rb_define_method(cXMLNode, "prev", rxml_node_prev_get, 0);
|
1327
|
+
|
1328
|
+
/* Modification */
|
1329
|
+
rb_define_method(cXMLNode, "<<", rxml_node_content_add, 1);
|
1330
|
+
rb_define_method(cXMLNode, "[]=", rxml_node_property_set, 2);
|
1331
|
+
rb_define_method(cXMLNode, "child_add", rxml_node_child_add, 1);
|
1332
|
+
rb_define_method(cXMLNode, "child=", rxml_node_child_set, 1);
|
1333
|
+
rb_define_method(cXMLNode, "sibling=", rxml_node_sibling_set, 1);
|
1334
|
+
rb_define_method(cXMLNode, "next=", rxml_node_next_set, 1);
|
1335
|
+
rb_define_method(cXMLNode, "prev=", rxml_node_prev_set, 1);
|
1336
|
+
|
1337
|
+
/* Rest of the node api */
|
1338
|
+
rb_define_method(cXMLNode, "attributes", rxml_node_attributes_get, 0);
|
1339
|
+
rb_define_method(cXMLNode, "base_uri", rxml_node_base_uri_get, 0);
|
1340
|
+
rb_define_method(cXMLNode, "base_uri=", rxml_node_base_uri_set, 1);
|
1341
|
+
rb_define_method(cXMLNode, "blank?", rxml_node_empty_q, 0);
|
1342
|
+
rb_define_method(cXMLNode, "copy", rxml_node_copy, 1);
|
1343
|
+
rb_define_method(cXMLNode, "content", rxml_node_content_get, 0);
|
1344
|
+
rb_define_method(cXMLNode, "content=", rxml_node_content_set, 1);
|
1345
|
+
rb_define_method(cXMLNode, "content_stripped", rxml_node_content_stripped_get, 0);
|
1346
|
+
rb_define_method(cXMLNode, "debug", rxml_node_debug, 0);
|
1347
|
+
rb_define_method(cXMLNode, "doc", rxml_node_doc, 0);
|
1348
|
+
rb_define_method(cXMLNode, "empty?", rxml_node_empty_q, 0);
|
1349
|
+
rb_define_method(cXMLNode, "eql?", rxml_node_eql_q, 1);
|
1350
|
+
rb_define_method(cXMLNode, "lang", rxml_node_lang_get, 0);
|
1351
|
+
rb_define_method(cXMLNode, "lang=", rxml_node_lang_set, 1);
|
1352
|
+
rb_define_method(cXMLNode, "line_num", rxml_node_line_num, 0);
|
1353
|
+
rb_define_method(cXMLNode, "name", rxml_node_name_get, 0);
|
1354
|
+
rb_define_method(cXMLNode, "name=", rxml_node_name_set, 1);
|
1355
|
+
rb_define_method(cXMLNode, "node_type", rxml_node_type, 0);
|
1356
|
+
rb_define_method(cXMLNode, "path", rxml_node_path, 0);
|
1357
|
+
rb_define_method(cXMLNode, "pointer", rxml_node_pointer, 1);
|
1358
|
+
rb_define_method(cXMLNode, "remove!", rxml_node_remove_ex, 0);
|
1359
|
+
rb_define_method(cXMLNode, "space_preserve", rxml_node_space_preserve_get, 0);
|
1360
|
+
rb_define_method(cXMLNode, "space_preserve=", rxml_node_space_preserve_set, 1);
|
1361
|
+
rb_define_method(cXMLNode, "to_s", rxml_node_to_s, -1);
|
1362
|
+
rb_define_method(cXMLNode, "xlink?", rxml_node_xlink_q, 0);
|
1363
|
+
rb_define_method(cXMLNode, "xlink_type", rxml_node_xlink_type, 0);
|
1364
|
+
rb_define_method(cXMLNode, "xlink_type_name", rxml_node_xlink_type_name, 0);
|
1365
|
+
|
1366
|
+
rb_define_alias(cXMLNode, "==", "eql?");
|
1367
|
+
}
|