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.
Files changed (38) hide show
  1. data/CHANGES +22 -0
  2. data/README +3 -1
  3. data/ext/libxml/cbg.c +86 -76
  4. data/ext/libxml/extconf.rb +2 -1
  5. data/ext/libxml/libxml.c +899 -885
  6. data/ext/libxml/ruby_libxml.h +65 -70
  7. data/ext/libxml/ruby_xml_attr.c +485 -500
  8. data/ext/libxml/ruby_xml_attributes.c +107 -106
  9. data/ext/libxml/ruby_xml_document.c +355 -356
  10. data/ext/libxml/ruby_xml_dtd.c +119 -117
  11. data/ext/libxml/ruby_xml_error.c +1112 -581
  12. data/ext/libxml/ruby_xml_html_parser.c +35 -34
  13. data/ext/libxml/ruby_xml_input.c +182 -187
  14. data/ext/libxml/ruby_xml_input_cbg.c +197 -179
  15. data/ext/libxml/ruby_xml_node.c +1529 -1566
  16. data/ext/libxml/ruby_xml_node.h +2 -2
  17. data/ext/libxml/ruby_xml_ns.c +150 -156
  18. data/ext/libxml/ruby_xml_parser.c +37 -36
  19. data/ext/libxml/ruby_xml_parser_context.c +657 -659
  20. data/ext/libxml/ruby_xml_reader.c +203 -209
  21. data/ext/libxml/ruby_xml_relaxng.c +29 -25
  22. data/ext/libxml/ruby_xml_sax_parser.c +33 -32
  23. data/ext/libxml/ruby_xml_schema.c +165 -161
  24. data/ext/libxml/ruby_xml_state.c +19 -21
  25. data/ext/libxml/ruby_xml_xinclude.c +24 -25
  26. data/ext/libxml/ruby_xml_xpath.c +108 -108
  27. data/ext/libxml/ruby_xml_xpath_context.c +305 -293
  28. data/ext/libxml/ruby_xml_xpath_expression.c +24 -24
  29. data/ext/libxml/ruby_xml_xpath_object.c +89 -96
  30. data/ext/libxml/ruby_xml_xpointer.c +107 -109
  31. data/ext/libxml/ruby_xml_xpointer.h +13 -13
  32. data/ext/libxml/version.h +2 -2
  33. data/ext/mingw/Rakefile +1 -1
  34. data/ext/vc/libxml_ruby.vcproj +1 -1
  35. data/lib/libxml/error.rb +4 -4
  36. data/test/tc_node_edit.rb +14 -2
  37. data/test/tc_node_text.rb +9 -9
  38. metadata +2 -2
@@ -3,160 +3,158 @@
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
5
5
  /*
6
- * Document-class: LibXML::XML::Attributes
7
- *
8
- * Provides access to an element's attributes (XML::Attr).
9
- *
10
- * Basic Usage:
11
- * require 'xml'
12
- *
13
- * doc = XML::Document.new(<some_file>)
14
- * attributes = doc.root.attributes
15
- *
16
- * attributes.each do |attribute|
17
- * ..
18
- * end
19
- *
20
- * attributes['foo'] = 'bar'
21
- * attribute = attributes.get_attribute['foo']
22
- * attribute.value == 'foo'
23
- *
24
- * To access a namespaced attribute:
25
- *
26
- * XLINK_URI = 'http://www.w3.org/1999/xlink'
27
- *
28
- * attribute = attributes.get_attribute_ns(XLINK_URI, 'title')
29
- * attribute.value = 'My title'
30
- */
6
+ * Document-class: LibXML::XML::Attributes
7
+ *
8
+ * Provides access to an element's attributes (XML::Attr).
9
+ *
10
+ * Basic Usage:
11
+ * require 'xml'
12
+ *
13
+ * doc = XML::Document.new(<some_file>)
14
+ * attributes = doc.root.attributes
15
+ *
16
+ * attributes.each do |attribute|
17
+ * ..
18
+ * end
19
+ *
20
+ * attributes['foo'] = 'bar'
21
+ * attribute = attributes.get_attribute['foo']
22
+ * attribute.value == 'foo'
23
+ *
24
+ * To access a namespaced attribute:
25
+ *
26
+ * XLINK_URI = 'http://www.w3.org/1999/xlink'
27
+ *
28
+ * attribute = attributes.get_attribute_ns(XLINK_URI, 'title')
29
+ * attribute.value = 'My title'
30
+ */
31
31
 
32
32
  #include "ruby_libxml.h"
33
33
  #include "ruby_xml_attributes.h"
34
34
 
35
35
  VALUE cXMLAttributes;
36
36
 
37
- void
38
- rxml_attributes_mark(xmlNodePtr xnode) {
37
+ void rxml_attributes_mark(xmlNodePtr xnode)
38
+ {
39
39
  rxml_node_mark_common(xnode);
40
40
  }
41
41
 
42
42
  /*
43
43
  * Creates a new attributes instance. Not exposed to ruby.
44
44
  */
45
- VALUE
46
- rxml_attributes_new(xmlNodePtr xnode)
45
+ VALUE rxml_attributes_new(xmlNodePtr xnode)
47
46
  {
48
- return Data_Wrap_Struct(cXMLAttributes,
49
- rxml_attributes_mark, NULL,
50
- xnode);
47
+ return Data_Wrap_Struct(cXMLAttributes, rxml_attributes_mark, NULL, xnode);
51
48
  }
52
49
 
53
50
  /*
54
51
  * call-seq:
55
52
  * attributes.node -> XML::Node
56
- *
53
+ *
57
54
  * Return the node that owns this attributes list.
58
55
  *
59
56
  * doc.root.attributes.node == doc.root
60
57
  */
61
- VALUE
62
- rxml_attributes_node_get(VALUE self) {
58
+ VALUE rxml_attributes_node_get(VALUE self)
59
+ {
63
60
  xmlNodePtr xnode;
64
61
  Data_Get_Struct(self, xmlNode, xnode);
65
- return(rxml_node2_wrap(cXMLNode, xnode));
62
+ return (rxml_node_wrap(cXMLNode, xnode));
66
63
  }
67
64
 
68
-
69
65
  /*
70
66
  * call-seq:
71
67
  * attributes.get_attribute("name") -> XML::Attr
72
- *
68
+ *
73
69
  * Returns the specified attribute.
74
- *
70
+ *
75
71
  * name: The name of the attribute, not including a namespace.
76
72
  *
77
73
  * doc.root.attributes.get_attribute("foo")
78
74
  */
79
- static VALUE
80
- rxml_attributes_get_attribute(VALUE self, VALUE name) {
75
+ static VALUE rxml_attributes_get_attribute(VALUE self, VALUE name)
76
+ {
81
77
  xmlNodePtr xnode;
82
78
  xmlAttrPtr xattr;
83
79
 
84
80
  name = check_string_or_symbol(name);
85
-
81
+
86
82
  Data_Get_Struct(self, xmlNode, xnode);
87
-
88
- xattr = xmlHasProp(xnode, (xmlChar*)StringValuePtr(name));
89
-
83
+
84
+ xattr = xmlHasProp(xnode, (xmlChar*) StringValuePtr(name));
85
+
90
86
  if (xattr)
91
- return(rxml_attr_wrap(xattr));
87
+ return (rxml_attr_wrap(xattr));
92
88
  else
93
- return(Qnil);
89
+ return (Qnil);
94
90
  }
95
91
 
96
92
  /*
97
93
  * call-seq:
98
94
  * attributes.get_attribute_ns("namespace", "name") -> XML::Attr
99
- *
95
+ *
100
96
  * Returns the specified attribute.
101
- *
97
+ *
102
98
  * namespace: The URI of the attribute's namespace.
103
99
  * name: The name of the attribute, not including a namespace.
104
100
  *
105
101
  * doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
106
102
  */
107
- static VALUE
108
- rxml_attributes_get_attribute_ns(VALUE self, VALUE namespace, VALUE name) {
103
+ static VALUE rxml_attributes_get_attribute_ns(VALUE self, VALUE namespace,
104
+ VALUE name)
105
+ {
109
106
  xmlNodePtr xnode;
110
107
  xmlAttrPtr xattr;
111
108
 
112
109
  name = check_string_or_symbol(name);
113
-
110
+
114
111
  Data_Get_Struct(self, xmlNode, xnode);
115
-
116
- xattr = xmlHasNsProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(namespace));
117
-
112
+
113
+ xattr = xmlHasNsProp(xnode, (xmlChar*) StringValuePtr(name),
114
+ (xmlChar*) StringValuePtr(namespace));
115
+
118
116
  if (xattr)
119
- return(rxml_attr_wrap(xattr));
117
+ return (rxml_attr_wrap(xattr));
120
118
  else
121
- return(Qnil);
119
+ return (Qnil);
122
120
  }
123
121
 
124
122
  /*
125
123
  * call-seq:
126
124
  * attributes["name"] -> String
127
- *
125
+ *
128
126
  * Fetches an attribute value. If you want to access the underlying
129
- * Attribute itself use get_attribute.
127
+ * Attribute itself use get_attribute.
130
128
  *
131
129
  * name: The name of the attribute, not including any namespaces.
132
- *
130
+ *
133
131
  * doc.root.attributes['att'] -> 'some value'
134
132
  */
135
- VALUE
136
- rxml_attributes_attribute_get(VALUE self, VALUE name) {
133
+ VALUE rxml_attributes_attribute_get(VALUE self, VALUE name)
134
+ {
137
135
  VALUE xattr = rxml_attributes_get_attribute(self, name);
138
- if NIL_P(xattr)
136
+ if (NIL_P(xattr))
139
137
  return(Qnil);
140
138
  else
141
139
  return rxml_attr_value_get(xattr);
142
- }
140
+ }
143
141
 
144
142
  /*
145
143
  * call-seq:
146
144
  * attributes["name"] = "value"
147
- *
145
+ *
148
146
  * Sets an attribute value. If you want to get the Attribute itself,
149
- * use get_attribute.
147
+ * use get_attribute.
150
148
  *
151
149
  * name: The name of the attribute, not including any namespaces.
152
150
  * value: The new value of the namespace.
153
- *
151
+ *
154
152
  * doc.root.attributes['att'] = 'some value'
155
153
  */
156
- VALUE
157
- rxml_attributes_attribute_set(VALUE self, VALUE name, VALUE value) {
154
+ VALUE rxml_attributes_attribute_set(VALUE self, VALUE name, VALUE value)
155
+ {
158
156
  VALUE xattr = rxml_attributes_get_attribute(self, name);
159
- if NIL_P(xattr)
157
+ if (NIL_P(xattr))
160
158
  {
161
159
  VALUE args[3];
162
160
 
@@ -170,19 +168,18 @@ rxml_attributes_attribute_set(VALUE self, VALUE name, VALUE value) {
170
168
  {
171
169
  return rxml_attr_value_set(xattr, value);
172
170
  }
173
- }
174
-
171
+ }
175
172
 
176
173
  /*
177
174
  * call-seq:
178
175
  * attributes.each {block} -> XML::Attr
179
- *
176
+ *
180
177
  * Iterates over each attribute.
181
- *
178
+ *
182
179
  * doc.root.attributes.each {|attribute| puts attribute.name}
183
180
  */
184
- static VALUE
185
- rxml_attributes_each(VALUE self) {
181
+ static VALUE rxml_attributes_each(VALUE self)
182
+ {
186
183
  xmlNodePtr xnode;
187
184
  xmlAttrPtr xattr;
188
185
  Data_Get_Struct(self, xmlNode, xnode);
@@ -191,24 +188,24 @@ rxml_attributes_each(VALUE self) {
191
188
 
192
189
  while (xattr)
193
190
  {
194
- VALUE attr = rxml_attr_wrap(xattr);
195
- rb_yield(attr);
196
- xattr = xattr->next;
191
+ VALUE attr = rxml_attr_wrap(xattr);
192
+ rb_yield(attr);
193
+ xattr = xattr->next;
197
194
  }
198
-
195
+
199
196
  return self;
200
- }
201
-
197
+ }
198
+
202
199
  /*
203
200
  * call-seq:
204
201
  * attributes.length -> Integer
205
- *
202
+ *
206
203
  * Returns the number of attributes.
207
204
  *
208
205
  * doc.root.attributes.length
209
206
  */
210
- static VALUE
211
- rxml_attributes_length(VALUE self) {
207
+ static VALUE rxml_attributes_length(VALUE self)
208
+ {
212
209
  int length = 0;
213
210
  xmlNodePtr xnode;
214
211
  xmlAttrPtr xattr;
@@ -218,49 +215,53 @@ rxml_attributes_length(VALUE self) {
218
215
 
219
216
  while (xattr)
220
217
  {
221
- length++;
222
- xattr = xattr->next;
218
+ length++;
219
+ xattr = xattr->next;
223
220
  }
224
-
221
+
225
222
  return INT2NUM(length);
226
- }
223
+ }
227
224
 
228
225
  /*
229
226
  * call-seq:
230
227
  * attributes.first -> XML::Attr
231
- *
228
+ *
232
229
  * Returns the first attribute.
233
230
  *
234
231
  * doc.root.attributes.first
235
232
  */
236
- static VALUE
237
- rxml_attributes_first(VALUE self) {
233
+ static VALUE rxml_attributes_first(VALUE self)
234
+ {
238
235
  xmlNodePtr xnode;
239
236
  Data_Get_Struct(self, xmlNode, xnode);
240
237
 
241
- if (xnode->type == XML_ELEMENT_NODE) {
238
+ if (xnode->type == XML_ELEMENT_NODE)
239
+ {
242
240
  xmlAttrPtr xattr = xnode->properties;
243
-
244
- if (xattr) {
245
- return(rxml_attr_wrap(xattr));
241
+
242
+ if (xattr)
243
+ {
244
+ return (rxml_attr_wrap(xattr));
246
245
  }
247
- }
248
- return(Qnil);
246
+ }
247
+ return (Qnil);
249
248
  }
250
249
 
251
- // Rdoc needs to know
250
+ // Rdoc needs to know
252
251
  #ifdef RDOC_NEVER_DEFINED
253
- mLibXML = rb_define_module("LibXML");
254
- mXML = rb_define_module_under(mLibXML, "XML");
252
+ mLibXML = rb_define_module("LibXML");
253
+ mXML = rb_define_module_under(mLibXML, "XML");
255
254
  #endif
256
-
257
- void
258
- ruby_init_xml_attributes(void) {
255
+
256
+ void ruby_init_xml_attributes(void)
257
+ {
259
258
  cXMLAttributes = rb_define_class_under(mXML, "Attributes", rb_cObject);
260
259
  rb_include_module(cXMLAttributes, rb_mEnumerable);
261
260
  rb_define_method(cXMLAttributes, "node", rxml_attributes_node_get, 0);
262
- rb_define_method(cXMLAttributes, "get_attribute", rxml_attributes_get_attribute, 1);
263
- rb_define_method(cXMLAttributes, "get_attribute_ns", rxml_attributes_get_attribute_ns, 2);
261
+ rb_define_method(cXMLAttributes, "get_attribute",
262
+ rxml_attributes_get_attribute, 1);
263
+ rb_define_method(cXMLAttributes, "get_attribute_ns",
264
+ rxml_attributes_get_attribute_ns, 2);
264
265
  rb_define_method(cXMLAttributes, "[]", rxml_attributes_attribute_get, 1);
265
266
  rb_define_method(cXMLAttributes, "[]=", rxml_attributes_attribute_set, 2);
266
267
  rb_define_method(cXMLAttributes, "each", rxml_attributes_each, 0);
@@ -1,148 +1,147 @@
1
- /* $Id: ruby_xml_document.c 626 2008-11-22 20:47:07Z cfis $ */
1
+ /* $Id: ruby_xml_document.c 650 2008-11-30 03:40:22Z cfis $ */
2
2
 
3
3
  /*
4
- * Document-class: LibXML::XML::Document
5
- *
6
- * The XML::Document class provides a tree based API for working
7
- * with xml documents. You may directly create a document and
8
- * manipulate it, or create a document from a data source by
9
- * using an XML::Parser object.
10
- *
11
- * To create a document from scratch:
12
- *
13
- * doc = XML::Document.new()
14
- * doc.root = XML::Node.new('root_node')
15
- * doc.root << XML::Node.new('elem1')
16
- * doc.save('output.xml', format)
17
- *
18
- * To read a document from a file:
19
- *
20
- * doc = XML::Document.file('my_file')
21
- *
22
- * To use a parser to read a document:
23
- *
24
- * parser = XML::Parser.new
25
- * parser.file = 'my_file'
26
- * doc = parser.parse
27
- *
28
- * To write a file:
29
- *
30
- *
31
- * doc = XML::Document.new()
32
- * doc.root = XML::Node.new('root_node')
33
- * root = doc.root
34
- *
35
- * root << elem1 = XML::Node.new('elem1')
36
- * elem1['attr1'] = 'val1'
37
- * elem1['attr2'] = 'val2'
38
- *
39
- * root << elem2 = XML::Node.new('elem2')
40
- * elem2['attr1'] = 'val1'
41
- * elem2['attr2'] = 'val2'
42
- *
43
- * root << elem3 = XML::Node.new('elem3')
44
- * elem3 << elem4 = XML::Node.new('elem4')
45
- * elem3 << elem5 = XML::Node.new('elem5')
46
- *
47
- * elem5 << elem6 = XML::Node.new('elem6')
48
- * elem6 << 'Content for element 6'
49
- *
50
- * elem3['attr'] = 'baz'
51
- *
52
- * format = true
53
- * doc.save('output.xml', format)
54
- */
4
+ * Document-class: LibXML::XML::Document
5
+ *
6
+ * The XML::Document class provides a tree based API for working
7
+ * with xml documents. You may directly create a document and
8
+ * manipulate it, or create a document from a data source by
9
+ * using an XML::Parser object.
10
+ *
11
+ * To create a document from scratch:
12
+ *
13
+ * doc = XML::Document.new()
14
+ * doc.root = XML::Node.new('root_node')
15
+ * doc.root << XML::Node.new('elem1')
16
+ * doc.save('output.xml', format)
17
+ *
18
+ * To read a document from a file:
19
+ *
20
+ * doc = XML::Document.file('my_file')
21
+ *
22
+ * To use a parser to read a document:
23
+ *
24
+ * parser = XML::Parser.new
25
+ * parser.file = 'my_file'
26
+ * doc = parser.parse
27
+ *
28
+ * To write a file:
29
+ *
30
+ *
31
+ * doc = XML::Document.new()
32
+ * doc.root = XML::Node.new('root_node')
33
+ * root = doc.root
34
+ *
35
+ * root << elem1 = XML::Node.new('elem1')
36
+ * elem1['attr1'] = 'val1'
37
+ * elem1['attr2'] = 'val2'
38
+ *
39
+ * root << elem2 = XML::Node.new('elem2')
40
+ * elem2['attr1'] = 'val1'
41
+ * elem2['attr2'] = 'val2'
42
+ *
43
+ * root << elem3 = XML::Node.new('elem3')
44
+ * elem3 << elem4 = XML::Node.new('elem4')
45
+ * elem3 << elem5 = XML::Node.new('elem5')
46
+ *
47
+ * elem5 << elem6 = XML::Node.new('elem6')
48
+ * elem6 << 'Content for element 6'
49
+ *
50
+ * elem3['attr'] = 'baz'
51
+ *
52
+ * format = true
53
+ * doc.save('output.xml', format)
54
+ */
55
55
 
56
56
  #include <stdarg.h>
57
57
  #include <st.h>
58
58
  #include "ruby_libxml.h"
59
59
  #include "ruby_xml_document.h"
60
60
 
61
-
62
61
  VALUE cXMLDocument;
63
62
 
64
- void
65
- rxml_document_free(xmlDocPtr xdoc) {
63
+ void rxml_document_free(xmlDocPtr xdoc)
64
+ {
66
65
  xdoc->_private = NULL;
67
66
  xmlFreeDoc(xdoc);
68
- }
69
-
70
- void
71
- rxml_document_mark(xmlDocPtr xdoc) {
67
+ }
68
+
69
+ void rxml_document_mark(xmlDocPtr xdoc)
70
+ {
72
71
  rb_gc_mark(LIBXML_STATE);
73
72
  }
74
73
 
75
- VALUE
76
- rxml_document_wrap(xmlDocPtr xdoc) {
74
+ VALUE rxml_document_wrap(xmlDocPtr xdoc)
75
+ {
77
76
  VALUE result;
78
77
 
79
78
  // This node is already wrapped
80
79
  if (xdoc->_private != NULL)
81
80
  {
82
- result = (VALUE)xdoc->_private;
81
+ result = (VALUE) xdoc->_private;
83
82
  }
84
- else
83
+ else
85
84
  {
86
- result = Data_Wrap_Struct(cXMLDocument, rxml_document_mark, rxml_document_free, xdoc);
87
- xdoc->_private = (void*)result;
85
+ result = Data_Wrap_Struct(cXMLDocument, rxml_document_mark,
86
+ rxml_document_free, xdoc);
87
+ xdoc->_private = (void*) result;
88
88
  }
89
-
89
+
90
90
  return result;
91
91
  }
92
92
 
93
-
94
93
  /*
95
94
  * call-seq:
96
95
  * XML::Document.alloc(xml_version = 1.0) -> document
97
- *
96
+ *
98
97
  * Alocates a new XML::Document, optionally specifying the
99
98
  * XML version.
100
99
  */
101
- static VALUE
102
- rxml_document_alloc(VALUE klass) {
100
+ static VALUE rxml_document_alloc(VALUE klass)
101
+ {
103
102
  return Data_Wrap_Struct(klass, rxml_document_mark, rxml_document_free, NULL);
104
103
  }
105
104
 
106
105
  /*
107
106
  * call-seq:
108
107
  * XML::Document.initialize(xml_version = 1.0) -> document
109
- *
108
+ *
110
109
  * Initializes a new XML::Document, optionally specifying the
111
110
  * XML version.
112
111
  */
113
- static VALUE
114
- rxml_document_initialize(int argc, VALUE *argv, VALUE self) {
112
+ static VALUE rxml_document_initialize(int argc, VALUE *argv, VALUE self)
113
+ {
115
114
  xmlDocPtr xdoc;
116
115
  VALUE xmlver;
117
116
 
118
- switch (argc) {
119
- case 0:
120
- xmlver = rb_str_new2("1.0");
121
- break;
122
- case 1:
123
- rb_scan_args(argc, argv, "01", &xmlver);
124
- break;
125
- default:
126
- rb_raise(rb_eArgError, "wrong number of arguments (need 0 or 1)");
117
+ switch (argc)
118
+ {
119
+ case 0:
120
+ xmlver = rb_str_new2("1.0");
121
+ break;
122
+ case 1:
123
+ rb_scan_args(argc, argv, "01", &xmlver);
124
+ break;
125
+ default:
126
+ rb_raise(rb_eArgError, "wrong number of arguments (need 0 or 1)");
127
127
  }
128
128
 
129
129
  Check_Type(xmlver, T_STRING);
130
- xdoc = xmlNewDoc((xmlChar*)StringValuePtr(xmlver));
131
- xdoc->_private = (void*)self;
132
- DATA_PTR(self) = xdoc;
133
-
130
+ xdoc = xmlNewDoc((xmlChar*) StringValuePtr(xmlver));
131
+ xdoc->_private = (void*) self;
132
+ DATA_PTR( self) = xdoc;
133
+
134
134
  return self;
135
135
  }
136
136
 
137
-
138
137
  /*
139
138
  * call-seq:
140
139
  * document.compression -> num
141
- *
140
+ *
142
141
  * Obtain this document's compression mode identifier.
143
142
  */
144
- static VALUE
145
- rxml_document_compression_get(VALUE self) {
143
+ static VALUE rxml_document_compression_get(VALUE self)
144
+ {
146
145
  #ifdef HAVE_ZLIB_H
147
146
  xmlDocPtr xdoc;
148
147
 
@@ -151,24 +150,23 @@ rxml_document_compression_get(VALUE self) {
151
150
 
152
151
  compmode = xmlGetDocCompressMode(xdoc);
153
152
  if (compmode == -1)
154
- return(Qnil);
153
+ return(Qnil);
155
154
  else
156
- return(INT2NUM(compmode));
155
+ return(INT2NUM(compmode));
157
156
  #else
158
157
  rb_warn("libxml not compiled with zlib support");
159
- return(Qfalse);
158
+ return (Qfalse);
160
159
  #endif
161
160
  }
162
161
 
163
-
164
162
  /*
165
163
  * call-seq:
166
164
  * document.compression = num
167
- *
165
+ *
168
166
  * Set this document's compression mode.
169
167
  */
170
- static VALUE
171
- rxml_document_compression_set(VALUE self, VALUE num) {
168
+ static VALUE rxml_document_compression_set(VALUE self, VALUE num)
169
+ {
172
170
  #ifdef HAVE_ZLIB_H
173
171
  xmlDocPtr xdoc;
174
172
 
@@ -176,93 +174,92 @@ rxml_document_compression_set(VALUE self, VALUE num) {
176
174
  Check_Type(num, T_FIXNUM);
177
175
  Data_Get_Struct(self, xmlDoc, xdoc);
178
176
 
179
- if (xdoc == NULL) {
177
+ if (xdoc == NULL)
178
+ {
180
179
  return(Qnil);
181
- } else {
180
+ }
181
+ else
182
+ {
182
183
  xmlSetDocCompressMode(xdoc, NUM2INT(num));
183
184
 
184
185
  compmode = xmlGetDocCompressMode(xdoc);
185
186
  if (compmode == -1)
186
- return(Qnil);
187
+ return(Qnil);
187
188
  else
188
- return(INT2NUM(compmode));
189
+ return(INT2NUM(compmode));
189
190
  }
190
191
  #else
191
192
  rb_warn("libxml compiled without zlib support");
192
- return(Qfalse);
193
+ return (Qfalse);
193
194
  #endif
194
195
  }
195
196
 
196
-
197
197
  /*
198
198
  * call-seq:
199
199
  * document.compression? -> (true|false)
200
- *
200
+ *
201
201
  * Determine whether this document is compressed.
202
202
  */
203
- static VALUE
204
- rxml_document_compression_q(VALUE self) {
203
+ static VALUE rxml_document_compression_q(VALUE self)
204
+ {
205
205
  #ifdef HAVE_ZLIB_H
206
206
  xmlDocPtr xdoc;
207
207
 
208
208
  Data_Get_Struct(self, xmlDoc, xdoc);
209
209
 
210
210
  if (xdoc->compression != -1)
211
- return(Qtrue);
211
+ return(Qtrue);
212
212
  else
213
- return(Qfalse);
213
+ return(Qfalse);
214
214
  #else
215
215
  rb_warn("libxml compiled without zlib support");
216
- return(Qfalse);
216
+ return (Qfalse);
217
217
  #endif
218
218
  }
219
219
 
220
-
221
220
  /*
222
221
  * call-seq:
223
222
  * document.child -> node
224
- *
223
+ *
225
224
  * Get this document's child node.
226
225
  */
227
- static VALUE
228
- rxml_document_child_get(VALUE self) {
226
+ static VALUE rxml_document_child_get(VALUE self)
227
+ {
229
228
  xmlDocPtr xdoc;
230
229
  Data_Get_Struct(self, xmlDoc, xdoc);
231
230
 
232
231
  if (xdoc->children == NULL)
233
- return(Qnil);
232
+ return (Qnil);
234
233
 
235
- return rxml_node2_wrap(cXMLNode, xdoc->children);
234
+ return rxml_node_wrap(cXMLNode, xdoc->children);
236
235
  }
237
236
 
238
-
239
237
  /*
240
238
  * call-seq:
241
239
  * document.child? -> (true|false)
242
- *
240
+ *
243
241
  * Determine whether this document has a child node.
244
242
  */
245
- static VALUE
246
- rxml_document_child_q(VALUE self) {
243
+ static VALUE rxml_document_child_q(VALUE self)
244
+ {
247
245
  xmlDocPtr xdoc;
248
246
  Data_Get_Struct(self, xmlDoc, xdoc);
249
247
 
250
248
  if (xdoc->children == NULL)
251
- return(Qfalse);
249
+ return (Qfalse);
252
250
  else
253
- return(Qtrue);
251
+ return (Qtrue);
254
252
  }
255
253
 
256
-
257
254
  /*
258
255
  * call-seq:
259
256
  * document.dump([stream]) -> true
260
- *
257
+ *
261
258
  * Dump this document's XML to the specified IO stream.
262
259
  * If no stream is specified, stdout is used.
263
260
  */
264
- static VALUE
265
- rxml_document_dump(int argc, VALUE *argv, VALUE self) {
261
+ static VALUE rxml_document_dump(int argc, VALUE *argv, VALUE self)
262
+ {
266
263
  OpenFile *fptr;
267
264
  VALUE io;
268
265
  FILE *out;
@@ -270,9 +267,10 @@ rxml_document_dump(int argc, VALUE *argv, VALUE self) {
270
267
 
271
268
  Data_Get_Struct(self, xmlDoc, xdoc);
272
269
  if (xdoc == NULL)
273
- return(Qnil);
270
+ return (Qnil);
274
271
 
275
- switch (argc) {
272
+ switch (argc)
273
+ {
276
274
  case 0:
277
275
  io = rb_stdout;
278
276
  break;
@@ -289,18 +287,17 @@ rxml_document_dump(int argc, VALUE *argv, VALUE self) {
289
287
  rb_io_check_writable(fptr);
290
288
  out = GetWriteFile(fptr);
291
289
  xmlDocDump(out, xdoc);
292
- return(Qtrue);
290
+ return (Qtrue);
293
291
  }
294
292
 
295
-
296
293
  /*
297
294
  * call-seq:
298
295
  * document.debug_dump([stream]) -> true
299
- *
296
+ *
300
297
  * Debug version of dump.
301
298
  */
302
- static VALUE
303
- rxml_document_debug_dump(int argc, VALUE *argv, VALUE self) {
299
+ static VALUE rxml_document_debug_dump(int argc, VALUE *argv, VALUE self)
300
+ {
304
301
  #ifdef LIBXML_DEBUG_ENABLED
305
302
  OpenFile *fptr;
306
303
  VALUE io;
@@ -309,18 +306,19 @@ rxml_document_debug_dump(int argc, VALUE *argv, VALUE self) {
309
306
 
310
307
  Data_Get_Struct(self, xmlDoc, xdoc);
311
308
  if (xdoc == NULL)
312
- return(Qnil);
309
+ return(Qnil);
313
310
 
314
- switch (argc) {
315
- case 0:
311
+ switch (argc)
312
+ {
313
+ case 0:
316
314
  io = rb_stderr;
317
315
  break;
318
- case 1:
316
+ case 1:
319
317
  io = argv[0];
320
318
  if (!rb_obj_is_kind_of(io, rb_cIO))
321
- rb_raise(rb_eTypeError, "need an IO object");
319
+ rb_raise(rb_eTypeError, "need an IO object");
322
320
  break;
323
- default:
321
+ default:
324
322
  rb_raise(rb_eArgError, "wrong number of arguments (0 or 1)");
325
323
  }
326
324
 
@@ -330,42 +328,42 @@ rxml_document_debug_dump(int argc, VALUE *argv, VALUE self) {
330
328
  xmlDebugDumpDocument(out, xdoc);
331
329
  return(Qtrue);
332
330
  #else
333
- rb_warn("libxml was compiled without debugging support. Please recompile libxml and ruby-libxml");
334
- return(Qfalse);
331
+ rb_warn(
332
+ "libxml was compiled without debugging support. Please recompile libxml and ruby-libxml");
333
+ return (Qfalse);
335
334
  #endif
336
335
  }
337
336
 
338
-
339
337
  /*
340
338
  * call-seq:
341
339
  * document.debug_dump_head([stream]) -> true
342
- *
340
+ *
343
341
  * Debug-dump this document's header to the specified IO stream.
344
342
  * If no stream is specified, stdout is used.
345
343
  */
346
- static VALUE
347
- rxml_document_debug_dump_head(int argc, VALUE *argv, VALUE self) {
344
+ static VALUE rxml_document_debug_dump_head(int argc, VALUE *argv, VALUE self)
345
+ {
348
346
  #ifdef LIBXML_DEBUG_ENABLED
349
347
  OpenFile *fptr;
350
348
  VALUE io;
351
349
  FILE *out;
352
350
  xmlDocPtr xdoc;
353
351
 
354
-
355
352
  Data_Get_Struct(self, xmlDoc, xdoc);
356
353
  if (xdoc == NULL)
357
- return(Qnil);
354
+ return(Qnil);
358
355
 
359
- switch (argc) {
360
- case 0:
356
+ switch (argc)
357
+ {
358
+ case 0:
361
359
  io = rb_stdout;
362
360
  break;
363
- case 1:
361
+ case 1:
364
362
  io = argv[0];
365
363
  if (!rb_obj_is_kind_of(io, rb_cIO))
366
- rb_raise(rb_eTypeError, "need an IO object");
364
+ rb_raise(rb_eTypeError, "need an IO object");
367
365
  break;
368
- default:
366
+ default:
369
367
  rb_raise(rb_eArgError, "wrong number of arguments (0 or 1)");
370
368
  }
371
369
 
@@ -375,23 +373,23 @@ rxml_document_debug_dump_head(int argc, VALUE *argv, VALUE self) {
375
373
  xmlDebugDumpDocumentHead(out, xdoc);
376
374
  return(Qtrue);
377
375
  #else
378
- rb_warn("libxml was compiled without debugging support. Please recompile libxml and ruby-libxml");
379
- return(Qfalse);
376
+ rb_warn(
377
+ "libxml was compiled without debugging support. Please recompile libxml and ruby-libxml");
378
+ return (Qfalse);
380
379
  #endif
381
380
  }
382
381
 
383
-
384
382
  /*
385
383
  * call-seq:
386
384
  * document.format_dump([stream], [spacing]) -> true
387
- *
385
+ *
388
386
  * Dump this document's formatted XML to the specified IO stream.
389
- * If no stream is specified, stdout is used. If spacing is
390
- * specified, it must be a boolean that determines whether
387
+ * If no stream is specified, stdout is used. If spacing is
388
+ * specified, it must be a boolean that determines whether
391
389
  * spacing is used.
392
390
  */
393
- static VALUE
394
- rxml_document_format_dump(int argc, VALUE *argv, VALUE self) {
391
+ static VALUE rxml_document_format_dump(int argc, VALUE *argv, VALUE self)
392
+ {
395
393
  OpenFile *fptr;
396
394
  VALUE bool, io;
397
395
  FILE *out;
@@ -401,9 +399,10 @@ rxml_document_format_dump(int argc, VALUE *argv, VALUE self) {
401
399
 
402
400
  Data_Get_Struct(self, xmlDoc, xdoc);
403
401
  if (xdoc == NULL)
404
- return(Qnil);
402
+ return (Qnil);
405
403
 
406
- switch (argc) {
404
+ switch (argc)
405
+ {
407
406
  case 0:
408
407
  io = rb_stdout;
409
408
  spacing = 1;
@@ -424,7 +423,8 @@ rxml_document_format_dump(int argc, VALUE *argv, VALUE self) {
424
423
  else if (TYPE(bool) == T_FALSE)
425
424
  spacing = 0;
426
425
  else
427
- rb_raise(rb_eTypeError, "incorect argument type, second argument must be bool");
426
+ rb_raise(rb_eTypeError,
427
+ "incorect argument type, second argument must be bool");
428
428
 
429
429
  break;
430
430
  default:
@@ -435,222 +435,206 @@ rxml_document_format_dump(int argc, VALUE *argv, VALUE self) {
435
435
  rb_io_check_writable(fptr);
436
436
  out = GetWriteFile(fptr);
437
437
  size = xmlDocFormatDump(out, xdoc, spacing);
438
- return(INT2NUM(size));
438
+ return (INT2NUM(size));
439
439
  }
440
440
 
441
-
442
441
  /*
443
442
  * call-seq:
444
443
  * document.debug_format_dump([stream]) -> true
445
- *
444
+ *
446
445
  * *Deprecated* in favour of format_dump.
447
446
  */
448
- static VALUE
449
- rxml_document_debug_format_dump(int argc, VALUE *argv, VALUE self) {
447
+ static VALUE rxml_document_debug_format_dump(int argc, VALUE *argv, VALUE self)
448
+ {
450
449
  rb_warn("debug_format_dump has been deprecaited, use format_dump instead");
451
- return(rxml_document_format_dump(argc, argv, self));
450
+ return (rxml_document_format_dump(argc, argv, self));
452
451
  }
453
452
 
454
-
455
453
  /*
456
454
  * call-seq:
457
455
  * document.encoding -> "encoding"
458
- *
456
+ *
459
457
  * Obtain the encoding specified by this document.
460
458
  */
461
- static VALUE
462
- rxml_document_encoding_get(VALUE self) {
459
+ static VALUE rxml_document_encoding_get(VALUE self)
460
+ {
463
461
  xmlDocPtr xdoc;
464
462
 
465
463
  Data_Get_Struct(self, xmlDoc, xdoc);
466
464
  if (xdoc->encoding == NULL)
467
- return(Qnil);
465
+ return (Qnil);
468
466
  else
469
- return(rb_str_new2((const char*)xdoc->encoding));
467
+ return (rb_str_new2((const char*) xdoc->encoding));
470
468
  }
471
469
 
472
-
473
470
  /*
474
471
  * call-seq:
475
472
  * document.encoding = "encoding"
476
- *
473
+ *
477
474
  * Set the encoding for this document.
478
475
  */
479
- static VALUE
480
- rxml_document_encoding_set(VALUE self, VALUE encoding) {
476
+ static VALUE rxml_document_encoding_set(VALUE self, VALUE encoding)
477
+ {
481
478
  xmlDocPtr xdoc;
482
479
 
483
-
484
480
  Check_Type(encoding, T_STRING);
485
481
  Data_Get_Struct(self, xmlDoc, xdoc);
486
482
  xdoc->encoding = xmlStrdup(StringValuePtr(encoding));
487
- return(rxml_document_encoding_get(self));
483
+ return (rxml_document_encoding_get(self));
488
484
  }
489
485
 
490
486
  /*
491
487
  * call-seq:
492
488
  * document.last -> node
493
- *
489
+ *
494
490
  * Obtain the last node.
495
491
  */
496
- static VALUE
497
- rxml_document_last_get(VALUE self) {
492
+ static VALUE rxml_document_last_get(VALUE self)
493
+ {
498
494
  xmlDocPtr xdoc;
499
495
 
500
-
501
496
  Data_Get_Struct(self, xmlDoc, xdoc);
502
497
 
503
498
  if (xdoc->last == NULL)
504
- return(Qnil);
499
+ return (Qnil);
505
500
 
506
- return rxml_node2_wrap(cXMLNode, xdoc->last);
501
+ return rxml_node_wrap(cXMLNode, xdoc->last);
507
502
  }
508
503
 
509
-
510
504
  /*
511
505
  * call-seq:
512
506
  * document.last? -> (true|false)
513
- *
507
+ *
514
508
  * Determine whether there is a last node.
515
509
  */
516
- static VALUE
517
- rxml_document_last_q(VALUE self) {
510
+ static VALUE rxml_document_last_q(VALUE self)
511
+ {
518
512
  xmlDocPtr xdoc;
519
513
 
520
514
  Data_Get_Struct(self, xmlDoc, xdoc);
521
515
 
522
516
  if (xdoc->last == NULL)
523
- return(Qfalse);
517
+ return (Qfalse);
524
518
  else
525
- return(Qtrue);
519
+ return (Qtrue);
526
520
  }
527
521
 
528
-
529
522
  /*
530
523
  * call-seq:
531
524
  * document.next -> node
532
- *
525
+ *
533
526
  * Obtain the next node.
534
527
  */
535
- static VALUE
536
- rxml_document_next_get(VALUE self) {
528
+ static VALUE rxml_document_next_get(VALUE self)
529
+ {
537
530
  xmlDocPtr xdoc;
538
531
 
539
-
540
532
  Data_Get_Struct(self, xmlDoc, xdoc);
541
533
 
542
534
  if (xdoc->next == NULL)
543
- return(Qnil);
535
+ return (Qnil);
544
536
 
545
- return rxml_node2_wrap(cXMLNode, xdoc->next);
537
+ return rxml_node_wrap(cXMLNode, xdoc->next);
546
538
  }
547
539
 
548
-
549
540
  /*
550
541
  * call-seq:
551
542
  * document.next? -> (true|false)
552
- *
543
+ *
553
544
  * Determine whether there is a next node.
554
545
  */
555
- static VALUE
556
- rxml_document_next_q(VALUE self) {
546
+ static VALUE rxml_document_next_q(VALUE self)
547
+ {
557
548
  xmlDocPtr xdoc;
558
549
 
559
550
  Data_Get_Struct(self, xmlDoc, xdoc);
560
551
 
561
552
  if (xdoc->next == NULL)
562
- return(Qfalse);
553
+ return (Qfalse);
563
554
  else
564
- return(Qtrue);
555
+ return (Qtrue);
565
556
  }
566
557
 
567
-
568
558
  /*
569
559
  * call-seq:
570
560
  * document.parent -> node
571
- *
561
+ *
572
562
  * Obtain the parent node.
573
563
  */
574
- static VALUE
575
- rxml_document_parent_get(VALUE self) {
564
+ static VALUE rxml_document_parent_get(VALUE self)
565
+ {
576
566
  xmlDocPtr xdoc;
577
567
 
578
-
579
568
  Data_Get_Struct(self, xmlDoc, xdoc);
580
569
 
581
570
  if (xdoc->parent == NULL)
582
- return(Qnil);
571
+ return (Qnil);
583
572
 
584
- return rxml_node2_wrap(cXMLNode, xdoc->parent);
573
+ return rxml_node_wrap(cXMLNode, xdoc->parent);
585
574
  }
586
575
 
587
-
588
576
  /*
589
577
  * call-seq:
590
578
  * document.parent? -> (true|false)
591
- *
579
+ *
592
580
  * Determine whether there is a parent node.
593
581
  */
594
- static VALUE
595
- rxml_document_parent_q(VALUE self) {
582
+ static VALUE rxml_document_parent_q(VALUE self)
583
+ {
596
584
  xmlDocPtr xdoc;
597
585
 
598
586
  Data_Get_Struct(self, xmlDoc, xdoc);
599
587
 
600
588
  if (xdoc->parent == NULL)
601
- return(Qfalse);
589
+ return (Qfalse);
602
590
  else
603
- return(Qtrue);
591
+ return (Qtrue);
604
592
  }
605
593
 
606
-
607
594
  /*
608
595
  * call-seq:
609
596
  * document.prev -> node
610
- *
597
+ *
611
598
  * Obtain the previous node.
612
599
  */
613
- static VALUE
614
- rxml_document_prev_get(VALUE self) {
600
+ static VALUE rxml_document_prev_get(VALUE self)
601
+ {
615
602
  xmlDocPtr xdoc;
616
603
 
617
-
618
604
  Data_Get_Struct(self, xmlDoc, xdoc);
619
605
 
620
606
  if (xdoc->prev == NULL)
621
- return(Qnil);
607
+ return (Qnil);
622
608
 
623
- return rxml_node2_wrap(cXMLNode, xdoc->prev);
609
+ return rxml_node_wrap(cXMLNode, xdoc->prev);
624
610
  }
625
611
 
626
-
627
612
  /*
628
613
  * call-seq:
629
614
  * document.prev? -> (true|false)
630
- *
615
+ *
631
616
  * Determine whether there is a previous node.
632
617
  */
633
- static VALUE
634
- rxml_document_prev_q(VALUE self) {
618
+ static VALUE rxml_document_prev_q(VALUE self)
619
+ {
635
620
  xmlDocPtr xdoc;
636
621
 
637
622
  Data_Get_Struct(self, xmlDoc, xdoc);
638
623
 
639
624
  if (xdoc->prev == NULL)
640
- return(Qfalse);
625
+ return (Qfalse);
641
626
  else
642
- return(Qtrue);
627
+ return (Qtrue);
643
628
  }
644
629
 
645
-
646
630
  /*
647
631
  * call-seq:
648
632
  * document.root -> node
649
- *
633
+ *
650
634
  * Obtain the root node.
651
635
  */
652
- static VALUE
653
- rxml_document_root_get(VALUE self) {
636
+ static VALUE rxml_document_root_get(VALUE self)
637
+ {
654
638
  xmlDocPtr xdoc;
655
639
 
656
640
  xmlNodePtr root;
@@ -659,20 +643,19 @@ rxml_document_root_get(VALUE self) {
659
643
  root = xmlDocGetRootElement(xdoc);
660
644
 
661
645
  if (root == NULL)
662
- return(Qnil);
646
+ return (Qnil);
663
647
 
664
- return rxml_node2_wrap(cXMLNode, root);
648
+ return rxml_node_wrap(cXMLNode, root);
665
649
  }
666
650
 
667
-
668
651
  /*
669
652
  * call-seq:
670
653
  * document.root = node
671
- *
654
+ *
672
655
  * Set the root node.
673
656
  */
674
- static VALUE
675
- rxml_document_root_set(VALUE self, VALUE node) {
657
+ static VALUE rxml_document_root_set(VALUE self, VALUE node)
658
+ {
676
659
  xmlDocPtr xdoc;
677
660
  xmlNodePtr xroot, xnode;
678
661
 
@@ -683,84 +666,84 @@ rxml_document_root_set(VALUE self, VALUE node) {
683
666
  Data_Get_Struct(node, xmlNode, xnode);
684
667
  xroot = xmlDocSetRootElement(xdoc, xnode);
685
668
  if (xroot == NULL)
686
- return(Qnil);
669
+ return (Qnil);
687
670
 
688
- return rxml_node2_wrap(cXMLNode, xroot);
671
+ return rxml_node_wrap(cXMLNode, xroot);
689
672
  }
690
673
 
691
-
692
674
  /*
693
675
  * call-seq:
694
676
  * document.save(filename, format = false) -> int
695
- *
696
- * Save this document to the file given by filename,
677
+ *
678
+ * Save this document to the file given by filename,
697
679
  * optionally formatting the output.
698
-
680
+
699
681
  * Parameters:
700
682
  * filename: The filename or URL of the new document
701
683
  * format: Specifies whether formatting spaces should be added.
702
- * returns: The number of bytes written or -1 in case of error.
684
+ * returns: The number of bytes written or -1 in case of error.
703
685
  */
704
- static VALUE
705
- rxml_document_save(int argc, VALUE *argv, VALUE self) {
686
+ static VALUE rxml_document_save(int argc, VALUE *argv, VALUE self)
687
+ {
706
688
  xmlDocPtr xdoc;
707
689
 
708
690
  const char *filename;
709
691
  int format = 0;
710
692
  int len;
711
693
 
712
- if (argc <1 || argc > 2)
694
+ if (argc < 1 || argc > 2)
713
695
  rb_raise(rb_eArgError, "wrong number of arguments (need 1 or 2)");
714
696
 
715
697
  Check_Type(argv[0], T_STRING);
716
698
  filename = StringValuePtr(argv[0]);
717
-
699
+
718
700
  if (argc == 2)
719
701
  {
720
- switch (TYPE(argv[1])) {
721
- case T_TRUE:
722
- format = 1;
723
- break;
724
- case T_FALSE:
725
- format = 0;
726
- break;
727
- default:
728
- rb_raise(rb_eArgError, "The second parameter (format) must be true or false");
702
+ switch (TYPE(argv[1]))
703
+ {
704
+ case T_TRUE:
705
+ format = 1;
706
+ break;
707
+ case T_FALSE:
708
+ format = 0;
709
+ break;
710
+ default:
711
+ rb_raise(rb_eArgError,
712
+ "The second parameter (format) must be true or false");
729
713
  }
730
714
  }
731
715
 
732
716
  Data_Get_Struct(self, xmlDoc, xdoc);
733
- len = xmlSaveFormatFileEnc(filename, xdoc, (const char*)xdoc->encoding, format);
734
-
717
+ len = xmlSaveFormatFileEnc(filename, xdoc, (const char*) xdoc->encoding,
718
+ format);
719
+
735
720
  if (len == -1)
736
721
  rb_raise(rb_eIOError, "Could not write document");
737
722
  else
738
- return(INT2NUM(len));
723
+ return (INT2NUM(len));
739
724
  }
740
725
 
741
-
742
726
  /*
743
727
  * call-seq:
744
728
  * document.standalone? -> (true|false)
745
- *
729
+ *
746
730
  * Determine whether this is a standalone document.
747
731
  */
748
- static VALUE
749
- rxml_document_standalone_q(VALUE self) {
732
+ static VALUE rxml_document_standalone_q(VALUE self)
733
+ {
750
734
  xmlDocPtr xdoc;
751
735
 
752
736
  Data_Get_Struct(self, xmlDoc, xdoc);
753
737
  if (xdoc->standalone)
754
- return(Qtrue);
738
+ return (Qtrue);
755
739
  else
756
- return(Qfalse);
740
+ return (Qfalse);
757
741
  }
758
742
 
759
-
760
743
  /*
761
744
  * call-seq:
762
745
  * document.to_s({format=true,encoding) -> "xml"
763
- *
746
+ *
764
747
  * Coerce this document to a string representation
765
748
  * of it's XML. The default is to pretty format, but this
766
749
  * depends Parser#indent_tree_output==true or
@@ -769,21 +752,22 @@ rxml_document_standalone_q(VALUE self) {
769
752
  * The encoding is not applied to the document, but is
770
753
  * encoding target of the resulting string.
771
754
  */
772
- static VALUE
773
- rxml_document_to_s(int argc, VALUE *argv, VALUE self) {
755
+ static VALUE rxml_document_to_s(int argc, VALUE *argv, VALUE self)
756
+ {
774
757
  xmlDocPtr xdoc;
775
758
 
776
- xmlChar *result, *encoding=NULL;
759
+ xmlChar *result, *encoding = NULL;
777
760
  int format, len;
778
761
  VALUE rresult;
779
762
 
780
- switch (argc) {
763
+ switch (argc)
764
+ {
781
765
  case 0:
782
766
  format = 1;
783
767
  break;
784
768
  case 2:
785
769
  if (TYPE(argv[1]) == T_STRING)
786
- encoding=(xmlChar *)StringValuePtr(argv[1]);
770
+ encoding = (xmlChar *) StringValuePtr(argv[1]);
787
771
  case 1:
788
772
  if (TYPE(argv[0]) == T_TRUE)
789
773
  format = 1;
@@ -797,72 +781,76 @@ rxml_document_to_s(int argc, VALUE *argv, VALUE self) {
797
781
  }
798
782
 
799
783
  Data_Get_Struct(self, xmlDoc, xdoc);
800
- if (xdoc == NULL) {
801
- return(Qnil);
802
- } else if (encoding != NULL) {
803
- if (format) {
804
- xmlDocDumpFormatMemoryEnc(xdoc, &result, &len,
805
- (const char*)encoding, format);
806
- } else {
807
- xmlDocDumpMemoryEnc(xdoc, &result, &len,
808
- (const char *)encoding);
784
+ if (xdoc == NULL)
785
+ {
786
+ return (Qnil);
787
+ }
788
+ else if (encoding != NULL)
789
+ {
790
+ if (format)
791
+ {
792
+ xmlDocDumpFormatMemoryEnc(xdoc, &result, &len, (const char*) encoding,
793
+ format);
794
+ }
795
+ else
796
+ {
797
+ xmlDocDumpMemoryEnc(xdoc, &result, &len, (const char *) encoding);
809
798
  }
810
- } else {
799
+ }
800
+ else
801
+ {
811
802
  if (format)
812
803
  xmlDocDumpFormatMemory(xdoc, &result, &len, format);
813
804
  else
814
805
  xmlDocDumpMemory(xdoc, &result, &len);
815
806
  }
816
- rresult=rb_str_new((const char*)result,len);
807
+ rresult = rb_str_new((const char*) result, len);
817
808
  xmlFree(result);
818
809
  return rresult;
819
810
  }
820
811
 
821
-
822
812
  /*
823
813
  * call-seq:
824
814
  * document.url -> "url"
825
- *
815
+ *
826
816
  * Obtain this document's source URL, if any.
827
817
  */
828
- static VALUE
829
- rxml_document_url_get(VALUE self) {
818
+ static VALUE rxml_document_url_get(VALUE self)
819
+ {
830
820
  xmlDocPtr xdoc;
831
821
 
832
822
  Data_Get_Struct(self, xmlDoc, xdoc);
833
823
  if (xdoc->URL == NULL)
834
- return(Qnil);
824
+ return (Qnil);
835
825
  else
836
- return(rb_str_new2((const char*)xdoc->URL));
826
+ return (rb_str_new2((const char*) xdoc->URL));
837
827
  }
838
828
 
839
-
840
829
  /*
841
830
  * call-seq:
842
831
  * document.version -> "version"
843
- *
832
+ *
844
833
  * Obtain the XML version specified by this document.
845
834
  */
846
- static VALUE
847
- rxml_document_version_get(VALUE self) {
835
+ static VALUE rxml_document_version_get(VALUE self)
836
+ {
848
837
  xmlDocPtr xdoc;
849
838
 
850
839
  Data_Get_Struct(self, xmlDoc, xdoc);
851
840
  if (xdoc->version == NULL)
852
- return(Qnil);
841
+ return (Qnil);
853
842
  else
854
- return(rb_str_new2((const char*)xdoc->version));
843
+ return (rb_str_new2((const char*) xdoc->version));
855
844
  }
856
845
 
857
-
858
846
  /*
859
847
  * call-seq:
860
848
  * document.xinclude -> num
861
- *
862
- * Process xinclude directives in this document.
849
+ *
850
+ * Process xinclude directives in this document.
863
851
  */
864
- static VALUE
865
- rxml_document_xinclude(VALUE self) {
852
+ static VALUE rxml_document_xinclude(VALUE self)
853
+ {
866
854
  #ifdef LIBXML_XINCLUDE_ENABLED
867
855
  xmlDocPtr xdoc;
868
856
 
@@ -880,32 +868,37 @@ rxml_document_xinclude(VALUE self) {
880
868
  return Qnil;
881
869
  }
882
870
  #else
883
- rb_warn("libxml was compiled without XInclude support. Please recompile libxml and ruby-libxml");
884
- return(Qfalse);
871
+ rb_warn(
872
+ "libxml was compiled without XInclude support. Please recompile libxml and ruby-libxml");
873
+ return (Qfalse);
885
874
  #endif
886
875
  }
887
876
 
888
- void
889
- LibXML_validity_error(void * ctxt, const char * msg, va_list ap)
877
+ void LibXML_validity_error(void * ctxt, const char * msg, va_list ap)
890
878
  {
891
- if (rb_block_given_p()) {
879
+ if (rb_block_given_p())
880
+ {
892
881
  char buff[1024];
893
882
  snprintf(buff, 1024, msg, ap);
894
883
  rb_yield(rb_ary_new3(2, rb_str_new2(buff), Qtrue));
895
- } else {
884
+ }
885
+ else
886
+ {
896
887
  fprintf(stderr, "error -- found validity error: ");
897
888
  fprintf(stderr, msg, ap);
898
889
  }
899
890
  }
900
891
 
901
- void
902
- LibXML_validity_warning(void * ctxt, const char * msg, va_list ap)
892
+ void LibXML_validity_warning(void * ctxt, const char * msg, va_list ap)
903
893
  {
904
- if (rb_block_given_p()) {
894
+ if (rb_block_given_p())
895
+ {
905
896
  char buff[1024];
906
897
  snprintf(buff, 1024, msg, ap);
907
898
  rb_yield(rb_ary_new3(2, rb_str_new2(buff), Qfalse));
908
- } else {
899
+ }
900
+ else
901
+ {
909
902
  fprintf(stderr, "warning -- found validity error: ");
910
903
  fprintf(stderr, msg, ap);
911
904
  }
@@ -914,15 +907,15 @@ LibXML_validity_warning(void * ctxt, const char * msg, va_list ap)
914
907
  /*
915
908
  * call-seq:
916
909
  * document.validate_schema(schema) -> (true|false)
917
- *
910
+ *
918
911
  * Validate this document against the specified XML::Schema.
919
- *
912
+ *
920
913
  * If a block is provided it is used as an error handler for validaten errors.
921
914
  * The block is called with two argument, the message and a flag indication
922
915
  * if the message is an error (true) or a warning (false).
923
916
  */
924
- static VALUE
925
- rxml_document_validate_schema(VALUE self, VALUE schema) {
917
+ static VALUE rxml_document_validate_schema(VALUE self, VALUE schema)
918
+ {
926
919
  xmlSchemaValidCtxtPtr vptr;
927
920
  xmlDocPtr xdoc;
928
921
  xmlSchemaPtr xschema;
@@ -933,34 +926,35 @@ rxml_document_validate_schema(VALUE self, VALUE schema) {
933
926
 
934
927
  vptr = xmlSchemaNewValidCtxt(xschema);
935
928
 
936
- xmlSchemaSetValidErrors(vptr, (xmlSchemaValidityErrorFunc)LibXML_validity_error,
937
- (xmlSchemaValidityWarningFunc)LibXML_validity_warning, NULL);
938
-
929
+ xmlSchemaSetValidErrors(vptr,
930
+ (xmlSchemaValidityErrorFunc) LibXML_validity_error,
931
+ (xmlSchemaValidityWarningFunc) LibXML_validity_warning, NULL);
932
+
939
933
  is_invalid = xmlSchemaValidateDoc(vptr, xdoc);
940
934
  xmlSchemaFreeValidCtxt(vptr);
941
- if (is_invalid)
935
+ if (is_invalid)
942
936
  {
943
937
  rxml_raise(&xmlLastError);
944
938
  return Qfalse;
945
- }
939
+ }
946
940
  else
947
941
  {
948
- return Qtrue;
942
+ return Qtrue;
949
943
  }
950
944
  }
951
945
 
952
946
  /*
953
947
  * call-seq:
954
948
  * document.validate_schema(relaxng) -> (true|false)
955
- *
949
+ *
956
950
  * Validate this document against the specified XML::RelaxNG.
957
951
  *
958
952
  * If a block is provided it is used as an error handler for validaten errors.
959
953
  * The block is called with two argument, the message and a flag indication
960
954
  * if the message is an error (true) or a warning (false).
961
955
  */
962
- static VALUE
963
- rxml_document_validate_relaxng(VALUE self, VALUE relaxng) {
956
+ static VALUE rxml_document_validate_relaxng(VALUE self, VALUE relaxng)
957
+ {
964
958
  xmlRelaxNGValidCtxtPtr vptr;
965
959
  xmlDocPtr xdoc;
966
960
  xmlRelaxNGPtr xrelaxng;
@@ -971,30 +965,31 @@ rxml_document_validate_relaxng(VALUE self, VALUE relaxng) {
971
965
 
972
966
  vptr = xmlRelaxNGNewValidCtxt(xrelaxng);
973
967
 
974
- xmlRelaxNGSetValidErrors(vptr, (xmlRelaxNGValidityErrorFunc)LibXML_validity_error,
975
- (xmlRelaxNGValidityWarningFunc)LibXML_validity_warning, NULL);
976
-
968
+ xmlRelaxNGSetValidErrors(vptr,
969
+ (xmlRelaxNGValidityErrorFunc) LibXML_validity_error,
970
+ (xmlRelaxNGValidityWarningFunc) LibXML_validity_warning, NULL);
971
+
977
972
  is_invalid = xmlRelaxNGValidateDoc(vptr, xdoc);
978
973
  xmlRelaxNGFreeValidCtxt(vptr);
979
- if (is_invalid)
974
+ if (is_invalid)
980
975
  {
981
976
  rxml_raise(&xmlLastError);
982
977
  return Qfalse;
983
- } else
978
+ }
979
+ else
984
980
  {
985
- return Qtrue;
981
+ return Qtrue;
986
982
  }
987
983
  }
988
984
 
989
-
990
985
  /*
991
986
  * call-seq:
992
987
  * document.validate(dtd) -> (true|false)
993
- *
988
+ *
994
989
  * Validate this document against the specified XML::DTD.
995
990
  */
996
- static VALUE
997
- rxml_document_validate_dtd(VALUE self, VALUE dtd) {
991
+ static VALUE rxml_document_validate_dtd(VALUE self, VALUE dtd)
992
+ {
998
993
  VALUE error = Qnil;
999
994
  xmlValidCtxt ctxt;
1000
995
  xmlDocPtr xdoc;
@@ -1004,8 +999,8 @@ rxml_document_validate_dtd(VALUE self, VALUE dtd) {
1004
999
  Data_Get_Struct(dtd, xmlDtd, xdtd);
1005
1000
 
1006
1001
  ctxt.userData = &error;
1007
- ctxt.error = (xmlValidityErrorFunc)LibXML_validity_error;
1008
- ctxt.warning = (xmlValidityWarningFunc)LibXML_validity_warning;
1002
+ ctxt.error = (xmlValidityErrorFunc) LibXML_validity_error;
1003
+ ctxt.warning = (xmlValidityWarningFunc) LibXML_validity_warning;
1009
1004
 
1010
1005
  ctxt.nodeNr = 0;
1011
1006
  ctxt.nodeTab = NULL;
@@ -1014,7 +1009,7 @@ rxml_document_validate_dtd(VALUE self, VALUE dtd) {
1014
1009
 
1015
1010
  if (xmlValidateDtd(&ctxt, xdoc, xdtd))
1016
1011
  {
1017
- return(Qtrue);
1012
+ return (Qtrue);
1018
1013
  }
1019
1014
  else
1020
1015
  {
@@ -1023,41 +1018,43 @@ rxml_document_validate_dtd(VALUE self, VALUE dtd) {
1023
1018
  }
1024
1019
  }
1025
1020
 
1026
-
1027
1021
  /*
1028
1022
  * call-seq:
1029
1023
  * document.reader -> reader
1030
- *
1024
+ *
1031
1025
  * Create a XML::Reader from the document. This is a shortcut to
1032
1026
  * XML::Reader.walker().
1033
1027
  */
1034
- static VALUE
1035
- rxml_document_reader(VALUE self)
1028
+ static VALUE rxml_document_reader(VALUE self)
1036
1029
  {
1037
1030
  return rxml_reader_new_walker(cXMLReader, self);
1038
1031
  }
1039
1032
 
1040
- // Rdoc needs to know
1033
+ // Rdoc needs to know
1041
1034
  #ifdef RDOC_NEVER_DEFINED
1042
- mLibXML = rb_define_module("LibXML");
1043
- mXML = rb_define_module_under(mLibXML, "XML");
1035
+ mLibXML = rb_define_module("LibXML");
1036
+ mXML = rb_define_module_under(mLibXML, "XML");
1044
1037
  #endif
1045
1038
 
1046
- void
1047
- ruby_init_xml_document(void) {
1039
+ void ruby_init_xml_document(void)
1040
+ {
1048
1041
  cXMLDocument = rb_define_class_under(mXML, "Document", rb_cObject);
1049
1042
  rb_define_alloc_func(cXMLDocument, rxml_document_alloc);
1050
1043
 
1051
1044
  rb_define_method(cXMLDocument, "initialize", rxml_document_initialize, -1);
1052
1045
  rb_define_method(cXMLDocument, "child", rxml_document_child_get, 0);
1053
1046
  rb_define_method(cXMLDocument, "child?", rxml_document_child_q, 0);
1054
- rb_define_method(cXMLDocument, "compression", rxml_document_compression_get, 0);
1055
- rb_define_method(cXMLDocument, "compression=", rxml_document_compression_set, 1);
1047
+ rb_define_method(cXMLDocument, "compression", rxml_document_compression_get,
1048
+ 0);
1049
+ rb_define_method(cXMLDocument, "compression=", rxml_document_compression_set,
1050
+ 1);
1056
1051
  rb_define_method(cXMLDocument, "compression?", rxml_document_compression_q, 0);
1057
1052
  rb_define_method(cXMLDocument, "dump", rxml_document_dump, -1);
1058
1053
  rb_define_method(cXMLDocument, "debug_dump", rxml_document_debug_dump, -1);
1059
- rb_define_method(cXMLDocument, "debug_dump_head", rxml_document_debug_dump_head, -1);
1060
- rb_define_method(cXMLDocument, "debug_format_dump", rxml_document_debug_format_dump, -1);
1054
+ rb_define_method(cXMLDocument, "debug_dump_head",
1055
+ rxml_document_debug_dump_head, -1);
1056
+ rb_define_method(cXMLDocument, "debug_format_dump",
1057
+ rxml_document_debug_format_dump, -1);
1061
1058
  rb_define_method(cXMLDocument, "encoding", rxml_document_encoding_get, 0);
1062
1059
  rb_define_method(cXMLDocument, "encoding=", rxml_document_encoding_set, 1);
1063
1060
  rb_define_method(cXMLDocument, "format_dump", rxml_document_format_dump, -1);
@@ -1078,7 +1075,9 @@ ruby_init_xml_document(void) {
1078
1075
  rb_define_method(cXMLDocument, "version", rxml_document_version_get, 0);
1079
1076
  rb_define_method(cXMLDocument, "xinclude", rxml_document_xinclude, 0);
1080
1077
  rb_define_method(cXMLDocument, "validate", rxml_document_validate_dtd, 1);
1081
- rb_define_method(cXMLDocument, "validate_schema", rxml_document_validate_schema, 1);
1082
- rb_define_method(cXMLDocument, "validate_relaxng", rxml_document_validate_relaxng, 1);
1078
+ rb_define_method(cXMLDocument, "validate_schema",
1079
+ rxml_document_validate_schema, 1);
1080
+ rb_define_method(cXMLDocument, "validate_relaxng",
1081
+ rxml_document_validate_relaxng, 1);
1083
1082
  rb_define_method(cXMLDocument, "reader", rxml_document_reader, 0);
1084
1083
  }