libxml-ruby 2.9.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY +811 -790
  3. data/LICENSE +20 -20
  4. data/MANIFEST +166 -166
  5. data/README.rdoc +188 -184
  6. data/Rakefile +1 -1
  7. data/ext/libxml/libxml.c +80 -80
  8. data/ext/libxml/ruby_libxml.h +75 -75
  9. data/ext/libxml/ruby_xml.c +0 -84
  10. data/ext/libxml/ruby_xml.h +0 -10
  11. data/ext/libxml/ruby_xml_attr.h +12 -12
  12. data/ext/libxml/ruby_xml_attr_decl.c +153 -153
  13. data/ext/libxml/ruby_xml_attr_decl.h +11 -11
  14. data/ext/libxml/ruby_xml_attributes.c +275 -275
  15. data/ext/libxml/ruby_xml_attributes.h +15 -15
  16. data/ext/libxml/ruby_xml_document.c +21 -27
  17. data/ext/libxml/ruby_xml_document.h +11 -11
  18. data/ext/libxml/ruby_xml_dtd.c +2 -13
  19. data/ext/libxml/ruby_xml_dtd.h +9 -9
  20. data/ext/libxml/ruby_xml_error.c +996 -996
  21. data/ext/libxml/ruby_xml_error.h +12 -12
  22. data/ext/libxml/ruby_xml_html_parser.c +89 -92
  23. data/ext/libxml/ruby_xml_html_parser.h +10 -10
  24. data/ext/libxml/ruby_xml_html_parser_context.h +10 -10
  25. data/ext/libxml/ruby_xml_html_parser_options.c +46 -46
  26. data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
  27. data/ext/libxml/ruby_xml_input_cbg.h +20 -20
  28. data/ext/libxml/ruby_xml_io.c +0 -1
  29. data/ext/libxml/ruby_xml_io.h +10 -10
  30. data/ext/libxml/ruby_xml_namespace.c +153 -153
  31. data/ext/libxml/ruby_xml_namespace.h +10 -10
  32. data/ext/libxml/ruby_xml_namespaces.c +293 -293
  33. data/ext/libxml/ruby_xml_namespaces.h +9 -9
  34. data/ext/libxml/ruby_xml_node.c +100 -143
  35. data/ext/libxml/ruby_xml_node.h +13 -11
  36. data/ext/libxml/ruby_xml_parser.c +91 -94
  37. data/ext/libxml/ruby_xml_parser.h +12 -12
  38. data/ext/libxml/ruby_xml_parser_context.h +10 -10
  39. data/ext/libxml/ruby_xml_parser_options.c +66 -66
  40. data/ext/libxml/ruby_xml_parser_options.h +12 -12
  41. data/ext/libxml/ruby_xml_reader.c +45 -37
  42. data/ext/libxml/ruby_xml_reader.h +17 -17
  43. data/ext/libxml/ruby_xml_relaxng.h +10 -10
  44. data/ext/libxml/ruby_xml_sax2_handler.c +3 -3
  45. data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
  46. data/ext/libxml/ruby_xml_sax_parser.c +116 -120
  47. data/ext/libxml/ruby_xml_sax_parser.h +10 -10
  48. data/ext/libxml/ruby_xml_schema.h +809 -809
  49. data/ext/libxml/ruby_xml_schema_attribute.c +109 -109
  50. data/ext/libxml/ruby_xml_schema_attribute.h +15 -15
  51. data/ext/libxml/ruby_xml_schema_element.c +94 -94
  52. data/ext/libxml/ruby_xml_schema_element.h +14 -14
  53. data/ext/libxml/ruby_xml_schema_facet.c +52 -52
  54. data/ext/libxml/ruby_xml_schema_facet.h +13 -13
  55. data/ext/libxml/ruby_xml_schema_type.c +259 -259
  56. data/ext/libxml/ruby_xml_schema_type.h +9 -9
  57. data/ext/libxml/ruby_xml_version.h +9 -9
  58. data/ext/libxml/ruby_xml_writer.c +1136 -1136
  59. data/ext/libxml/ruby_xml_writer.h +10 -10
  60. data/ext/libxml/ruby_xml_xinclude.c +16 -16
  61. data/ext/libxml/ruby_xml_xinclude.h +11 -11
  62. data/ext/libxml/ruby_xml_xpath.c +42 -36
  63. data/ext/libxml/ruby_xml_xpath.h +13 -13
  64. data/ext/libxml/ruby_xml_xpath_context.c +1 -1
  65. data/ext/libxml/ruby_xml_xpath_context.h +9 -9
  66. data/ext/libxml/ruby_xml_xpath_expression.c +81 -81
  67. data/ext/libxml/ruby_xml_xpath_expression.h +10 -10
  68. data/ext/libxml/ruby_xml_xpath_object.c +5 -2
  69. data/ext/libxml/ruby_xml_xpath_object.h +17 -17
  70. data/ext/libxml/ruby_xml_xpointer.c +99 -99
  71. data/ext/libxml/ruby_xml_xpointer.h +11 -11
  72. data/ext/vc/libxml_ruby.sln +17 -15
  73. data/lib/libxml.rb +1 -6
  74. data/lib/libxml/node.rb +2 -78
  75. data/lib/libxml/parser.rb +0 -266
  76. data/lib/libxml/sax_parser.rb +0 -17
  77. data/lib/libxml/schema.rb +66 -66
  78. data/lib/libxml/schema/attribute.rb +19 -19
  79. data/lib/libxml/schema/element.rb +27 -27
  80. data/lib/libxml/schema/type.rb +29 -29
  81. data/script/benchmark/depixelate +634 -634
  82. data/script/benchmark/hamlet.xml +9054 -9054
  83. data/script/benchmark/parsecount +170 -170
  84. data/script/benchmark/throughput +41 -41
  85. data/script/test +6 -6
  86. data/test/c14n/given/example-1.xml +14 -14
  87. data/test/c14n/given/example-2.xml +11 -11
  88. data/test/c14n/given/example-3.xml +18 -18
  89. data/test/c14n/given/example-4.xml +9 -9
  90. data/test/c14n/given/example-5.xml +12 -12
  91. data/test/c14n/given/example-6.xml +2 -2
  92. data/test/c14n/given/example-7.xml +11 -11
  93. data/test/c14n/given/example-8.xml +11 -11
  94. data/test/c14n/given/example-8.xpath +9 -9
  95. data/test/c14n/result/1-1-without-comments/example-1 +3 -3
  96. data/test/c14n/result/1-1-without-comments/example-2 +10 -10
  97. data/test/c14n/result/1-1-without-comments/example-3 +13 -13
  98. data/test/c14n/result/1-1-without-comments/example-4 +8 -8
  99. data/test/c14n/result/1-1-without-comments/example-5 +2 -2
  100. data/test/c14n/result/with-comments/example-1 +5 -5
  101. data/test/c14n/result/with-comments/example-2 +10 -10
  102. data/test/c14n/result/with-comments/example-3 +13 -13
  103. data/test/c14n/result/with-comments/example-4 +8 -8
  104. data/test/c14n/result/with-comments/example-5 +3 -3
  105. data/test/c14n/result/without-comments/example-1 +3 -3
  106. data/test/c14n/result/without-comments/example-2 +10 -10
  107. data/test/c14n/result/without-comments/example-3 +13 -13
  108. data/test/c14n/result/without-comments/example-4 +8 -8
  109. data/test/c14n/result/without-comments/example-5 +2 -2
  110. data/test/model/atom.xml +12 -12
  111. data/test/model/bands.iso-8859-1.xml +4 -4
  112. data/test/model/bands.utf-8.xml +4 -4
  113. data/test/model/bands.xml +4 -4
  114. data/test/model/books.xml +153 -153
  115. data/test/model/merge_bug_data.xml +58 -58
  116. data/test/model/ruby-lang.html +238 -238
  117. data/test/model/rubynet.xml +79 -79
  118. data/test/model/shiporder.rnc +28 -28
  119. data/test/model/shiporder.rng +86 -86
  120. data/test/model/shiporder.xml +22 -22
  121. data/test/model/shiporder.xsd +39 -39
  122. data/test/model/soap.xml +27 -27
  123. data/test/model/xinclude.xml +4 -4
  124. data/test/tc_attributes.rb +0 -6
  125. data/test/tc_error.rb +157 -158
  126. data/test/tc_node.rb +33 -17
  127. data/test/tc_node_edit.rb +0 -15
  128. data/test/tc_node_pi.rb +39 -39
  129. data/test/tc_parser.rb +0 -48
  130. data/test/tc_reader.rb +12 -53
  131. data/test/tc_writer.rb +447 -447
  132. data/test/tc_xpath.rb +1 -1
  133. data/test/test_helper.rb +2 -2
  134. metadata +3 -8
  135. data/ext/libxml/extconf.h +0 -4
  136. data/lib/libxml/ns.rb +0 -22
  137. data/lib/libxml/properties.rb +0 -23
  138. data/lib/libxml/reader.rb +0 -29
  139. data/lib/libxml/xpath_object.rb +0 -16
@@ -1,9 +1,9 @@
1
- /* Please see the LICENSE file for copyright and distribution information */
2
-
3
- #ifndef __RXML_NAMESPACES__
4
- #define __RXML_NAMESPACES__
5
-
6
- extern VALUE cXMLNamespaces;
7
-
8
- void rxml_init_namespaces(void);
9
- #endif
1
+ /* Please see the LICENSE file for copyright and distribution information */
2
+
3
+ #ifndef __RXML_NAMESPACES__
4
+ #define __RXML_NAMESPACES__
5
+
6
+ extern VALUE cXMLNamespaces;
7
+
8
+ void rxml_init_namespaces(void);
9
+ #endif
@@ -17,89 +17,103 @@ VALUE cXMLNode;
17
17
 
18
18
  /* Memory management:
19
19
  *
20
- * The bindings create a one-to-one mapping between libxml nodes
21
- * and Ruby nodes. If a libxml node is wrapped, the mapping is stored in the
22
- * private_pointers hashtable.
23
- *
24
- * When a libxml document or top level node is freed, it will free
25
- * all its children. Thus Ruby is responsible for:
26
- *
27
- * * Using the mark function to keep alive any documents Ruby is
28
- * referencing via the document or child nodes.
29
- * * Using the mark function to keep alive any top level, free
30
- * standing nodes Ruby is referencing via the node or its children.
31
- *
32
- * In general use, this will cause Ruby nodes to be freed before
33
- * a libxml document. When a Ruby node is freed, the hashtable entry is
34
- * removed.
35
- *
36
- * In the sweep phase in Ruby 1.9.*, the document tends to be
37
- * freed before the nodes. To support this, the bindings register
38
- * a callback function with libxml that is called each time a node
39
- * is freed. In that case, the data_ptr is set to null, so the bindings
40
- * can recognize the situation.
20
+ * The bindings create a one-to-one mapping between ruby objects and
21
+ * libxml documents and libxml parent nodes (ie, nodes that do not
22
+ * have a parent and do not belong to a document). In these cases,
23
+ * the bindings manage the memory. They do this by installing a free
24
+ * function and storing a back pointer to the Ruby object from the xmlnode
25
+ * using the _private member on libxml structures. When the Ruby object
26
+ * goes out of scope, the underlying libxml structure is freed. Libxml
27
+ * itself then frees all child node (recursively).
28
+ *
29
+ * For all other nodes (the vast majority), the bindings create temporary
30
+ * Ruby objects that get freed once they go out of scope. Thus there can be
31
+ * more than one ruby object pointing to the same xml node. To mostly hide
32
+ * this from programmers on the ruby side, the #eql? and #== methods are
33
+ * overriden to check if two ruby objects wrap the same xmlnode. If they do,
34
+ * then the methods return true. During the mark phase, each of these temporary
35
+ * objects marks its owning document, thereby keeping the Ruby document object
36
+ * alive and thus the xmldoc tree.
37
+ *
38
+ * In the sweep phase of the garbage collector, or when a program ends,
39
+ * there is no order to how Ruby objects are freed. In fact, the ruby document
40
+ * object is almost always freed before any ruby objects that wrap child nodes.
41
+ * However, this is ok because those ruby objects do not have a free function
42
+ * and are no longer in scope (since if they were the document would not be freed).
41
43
  */
42
44
 
43
- static void rxml_node_deregisterNode(xmlNodePtr xnode)
44
- {
45
- /* Has the node been wrapped and exposed to Ruby? */
46
- VALUE node = rxml_lookup_node(xnode);
47
- if (node == Qnil)
48
- return;
49
-
50
- /* Node was wrapped. Disassociate the ruby object from the xml node
51
- and turn off the free function so Ruby will not call it when the
52
- wrapping object is itself freed. Note we still MUST include
53
- the mark function. Unsetting it breaks the Ruby GC. */
54
- RDATA(node)->dfree = NULL;
55
- RDATA(node)->data = NULL;
56
-
57
- // Remove the hashtable entry
58
- rxml_unregister_node(xnode);
59
- }
60
-
61
45
  static void rxml_node_free(xmlNodePtr xnode)
62
46
  {
63
- /* The ruby object wrapping the xml object no longer exists. */
64
- rxml_unregister_node(xnode);
65
-
66
- /* Ruby is responsible for freeing this node if it does not
67
- have a parent and is not owned by a document. Note a corner
68
- case here - calling node2 = doc.import(node1) will cause node2
69
- to not have a parent but to have a document. */
47
+ /* The ruby object wrapping the xml object no longer exists and this
48
+ is a standalone node without a document or parent so ruby is
49
+ responsible for freeing the underlying node.*/
70
50
  if (xnode->doc == NULL && xnode->parent == NULL)
71
51
  {
52
+ // Remove the back linkage from libxml to Ruby
53
+ xnode->_private = NULL;
72
54
  xmlFreeNode(xnode);
73
55
  }
74
56
  }
75
57
 
76
- void rxml_node_mark(xmlNodePtr xnode)
58
+ void rxml_node_manage(xmlNodePtr xnode, VALUE node)
77
59
  {
78
- VALUE doc = Qnil;
79
- VALUE parent = Qnil;
60
+ RDATA(node)->dfree = rxml_node_free;
61
+ xnode->_private = (void*)node;
62
+ }
80
63
 
81
- /* Either the node has not been created yet in initialize
82
- or it has been freed by libxml already in Ruby's
83
- mark phase. */
84
- if (xnode == NULL)
85
- return;
64
+ void rxml_node_unmanage(xmlNodePtr xnode, VALUE node)
65
+ {
66
+ RDATA(node)->dfree = NULL;
67
+ xnode->_private = NULL;
68
+ }
86
69
 
87
- doc = rxml_lookup_doc(xnode->doc);
88
- if (doc != Qnil)
89
- rb_gc_mark(doc);
70
+ xmlNodePtr rxml_node_root(xmlNodePtr xnode)
71
+ {
72
+ xmlNodePtr current = xnode;
90
73
 
91
- parent = rxml_lookup_node(xnode->parent);
92
- if (parent != Qnil)
93
- rb_gc_mark(parent);
74
+ while (current->parent)
75
+ {
76
+ current = current->parent;
77
+ }
78
+
79
+ return current;
80
+ }
81
+
82
+ void rxml_node_mark(xmlNodePtr xnode)
83
+ {
84
+ if (xnode->doc)
85
+ {
86
+ VALUE doc = (VALUE)xnode->doc->_private;
87
+ rb_gc_mark(doc);
88
+ }
89
+ else if (xnode->parent)
90
+ {
91
+ xmlNodePtr root = rxml_node_root(xnode);
92
+ if (root->_private)
93
+ {
94
+ VALUE node = (VALUE)root->_private;
95
+ rb_gc_mark(node);
96
+ }
97
+ }
94
98
  }
95
99
 
96
100
  VALUE rxml_node_wrap(xmlNodePtr xnode)
97
101
  {
98
- VALUE result = rxml_lookup_node(xnode);
102
+ VALUE result = Qnil;
103
+
104
+ // Is this node already wrapped?
105
+ if (xnode->_private)
106
+ {
107
+ result = (VALUE)xnode->_private;
108
+ }
109
+ else
110
+ {
111
+ result = Data_Wrap_Struct(cXMLNode, rxml_node_mark, NULL, xnode);
112
+ }
99
113
 
100
- if (result == Qnil) {
101
- result = Data_Wrap_Struct(cXMLNode, rxml_node_mark, rxml_node_free, xnode);
102
- rxml_register_node(xnode, result);
114
+ if (!xnode->doc && !xnode->parent)
115
+ {
116
+ rxml_node_manage(xnode, result);
103
117
  }
104
118
  return result;
105
119
  }
@@ -270,9 +284,11 @@ static VALUE rxml_node_initialize(int argc, VALUE *argv, VALUE self)
270
284
  if (xnode == NULL)
271
285
  rxml_raise(&xmlLastError);
272
286
 
273
- /* Link the Ruby object to the libxml object and vice-versa. */
274
- rxml_register_node(xnode, self);
275
- DATA_PTR(self) = xnode;
287
+ // Link the ruby wrapper to the underlying libxml node
288
+ RDATA(self)->data = xnode;
289
+
290
+ // Ruby is in charge of managing this node's memory
291
+ rxml_node_manage(xnode, self);
276
292
 
277
293
  if (!NIL_P(content))
278
294
  rxml_node_content_set(self, content);
@@ -306,9 +322,12 @@ static VALUE rxml_node_modify_dom(VALUE self, VALUE target,
306
322
  if (xresult != xtarget)
307
323
  {
308
324
  RDATA(target)->data = xresult;
309
- rxml_register_node(xresult, target);
310
325
  }
311
326
 
327
+ // Target now has a parent so ruby should no longer manage its memory
328
+ rxml_node_unmanage(xresult, target);
329
+ xtarget->_private = NULL;
330
+
312
331
  return target;
313
332
  }
314
333
 
@@ -402,35 +421,6 @@ static VALUE rxml_node_content_set(VALUE self, VALUE content)
402
421
  return (Qtrue);
403
422
  }
404
423
 
405
- /*
406
- * call-seq:
407
- * node.content_stripped -> "string"
408
- *
409
- * Obtain this node's stripped content.
410
- *
411
- * *Deprecated*: Stripped content can be obtained via the
412
- * +content+ method.
413
- */
414
- static VALUE rxml_node_content_stripped_get(VALUE self)
415
- {
416
- xmlNodePtr xnode;
417
- xmlChar* content;
418
- VALUE result = Qnil;
419
-
420
- xnode = rxml_get_xnode(self);
421
-
422
- if (!xnode->content)
423
- return result;
424
-
425
- content = xmlNodeGetContent(xnode);
426
- if (content)
427
- {
428
- result = rxml_new_cstr( content, NULL);
429
- xmlFree(content);
430
- }
431
- return (result);
432
- }
433
-
434
424
  /*
435
425
  * call-seq:
436
426
  * node.debug -> true|false
@@ -540,7 +530,7 @@ static VALUE rxml_node_doc(VALUE self)
540
530
  if (xdoc == NULL)
541
531
  return (Qnil);
542
532
 
543
- return rxml_lookup_doc(xdoc);
533
+ return (VALUE)xdoc->_private;
544
534
  }
545
535
 
546
536
  /*
@@ -684,10 +674,10 @@ static VALUE rxml_node_empty_q(VALUE self)
684
674
  * node.eql?(other_node) => (true|false)
685
675
  *
686
676
  * Test equality between the two nodes. Two nodes are equal
687
- * if they are the same node or have the same XML representation.*/
677
+ * if they are the same node.*/
688
678
  static VALUE rxml_node_eql_q(VALUE self, VALUE other)
689
679
  {
690
- if(self == other)
680
+ if (self == other)
691
681
  {
692
682
  return Qtrue;
693
683
  }
@@ -697,15 +687,9 @@ static VALUE rxml_node_eql_q(VALUE self, VALUE other)
697
687
  }
698
688
  else
699
689
  {
700
- VALUE self_xml;
701
- VALUE other_xml;
702
-
703
- if (rb_obj_is_kind_of(other, cXMLNode) == Qfalse)
704
- rb_raise(rb_eTypeError, "Nodes can only be compared against other nodes");
705
-
706
- self_xml = rxml_node_to_s(0, NULL, self);
707
- other_xml = rxml_node_to_s(0, NULL, other);
708
- return(rb_funcall(self_xml, rb_intern("=="), 1, other_xml));
690
+ xmlNodePtr xnode = rxml_get_xnode(self);
691
+ xmlNodePtr xnode_other = rxml_get_xnode(other);
692
+ return xnode == xnode_other ? Qtrue : Qfalse;
709
693
  }
710
694
  }
711
695
 
@@ -1125,35 +1109,15 @@ static VALUE rxml_node_property_set(VALUE self, VALUE name, VALUE value)
1125
1109
 
1126
1110
  static VALUE rxml_node_remove_ex(VALUE self)
1127
1111
  {
1128
- xmlNodePtr xnode, xresult;
1129
- xnode = rxml_get_xnode(self);
1130
-
1131
- /* First unlink the node from its parent. */
1112
+ xmlNodePtr xnode = rxml_get_xnode(self);
1113
+
1114
+ // Now unlink the node from its parent
1132
1115
  xmlUnlinkNode(xnode);
1133
1116
 
1134
- /* Now copy the node we want to remove and make the
1135
- current Ruby object point to it. We do this because
1136
- a node has a number of dependencies on its parent
1137
- document - its name (if using a dictionary), entities,
1138
- namespaces, etc. For a node to live on its own, it
1139
- needs to get its own copies of this information.*/
1140
- xresult = xmlDocCopyNode(xnode, NULL, 1);
1141
-
1142
- /* This ruby node object no longer points at the node.*/
1143
- rxml_unregister_node(xnode);
1144
- RDATA(self)->data = NULL;
1145
-
1146
- /* Now free the original node. This will call the deregister node
1147
- callback which would reset the mark and free function except for
1148
- the fact we already removed it from the private hashtable above */
1149
- xmlFreeNode(xnode);
1150
-
1151
- /* Now wrap the new node */
1152
- RDATA(self)->data = xresult;
1153
- rxml_register_node(xresult, self);
1154
-
1155
- /* Now return the removed node so the user can
1156
- do something with it.*/
1117
+ // Ruby now manages this node
1118
+ rxml_node_manage(xnode, self);
1119
+
1120
+ // Now return the removed node so the user can do something with it
1157
1121
  return self;
1158
1122
  }
1159
1123
 
@@ -1335,12 +1299,6 @@ static VALUE rxml_node_copy(VALUE self, VALUE deep)
1335
1299
 
1336
1300
  void rxml_init_node(void)
1337
1301
  {
1338
- /* Register callback for main thread */
1339
- xmlDeregisterNodeDefault(rxml_node_deregisterNode);
1340
-
1341
- /* Register callback for all other threads */
1342
- xmlThrDefDeregisterNodeDefault(rxml_node_deregisterNode);
1343
-
1344
1302
  cXMLNode = rb_define_class_under(mXML, "Node", rb_cObject);
1345
1303
 
1346
1304
  rb_define_const(cXMLNode, "SPACE_DEFAULT", INT2NUM(0));
@@ -1419,7 +1377,6 @@ void rxml_init_node(void)
1419
1377
  rb_define_method(cXMLNode, "copy", rxml_node_copy, 1);
1420
1378
  rb_define_method(cXMLNode, "content", rxml_node_content_get, 0);
1421
1379
  rb_define_method(cXMLNode, "content=", rxml_node_content_set, 1);
1422
- rb_define_method(cXMLNode, "content_stripped", rxml_node_content_stripped_get, 0);
1423
1380
  rb_define_method(cXMLNode, "debug", rxml_node_debug, 0);
1424
1381
  rb_define_method(cXMLNode, "doc", rxml_node_doc, 0);
1425
1382
  rb_define_method(cXMLNode, "empty?", rxml_node_empty_q, 0);
@@ -1,11 +1,13 @@
1
- /* Please see the LICENSE file for copyright and distribution information */
2
-
3
- #ifndef __RXML_NODE__
4
- #define __RXML_NODE__
5
-
6
- extern VALUE cXMLNode;
7
-
8
- void rxml_init_node(void);
9
- void rxml_node_mark(xmlNodePtr xnode);
10
- VALUE rxml_node_wrap(xmlNodePtr xnode);
11
- #endif
1
+ /* Please see the LICENSE file for copyright and distribution information */
2
+
3
+ #ifndef __RXML_NODE__
4
+ #define __RXML_NODE__
5
+
6
+ extern VALUE cXMLNode;
7
+
8
+ void rxml_init_node(void);
9
+ void rxml_node_mark(xmlNodePtr xnode);
10
+ VALUE rxml_node_wrap(xmlNodePtr xnode);
11
+ void rxml_node_manage(xmlNodePtr xnode, VALUE node);
12
+ void rxml_node_unmanage(xmlNodePtr xnode, VALUE node);
13
+ #endif
@@ -1,94 +1,91 @@
1
- /* Please see the LICENSE file for copyright and distribution information */
2
-
3
- #include <stdarg.h>
4
- #include "ruby_libxml.h"
5
-
6
- /*
7
- * Document-class: LibXML::XML::Parser
8
- *
9
- * The XML::Parser provides a tree based API for processing
10
- * xml documents, in contract to XML::Reader's stream
11
- * based api and XML::SaxParser callback based API.
12
- *
13
- * As a result, parsing a document creates an in-memory document object
14
- * that consist of any number of XML::Node instances. This is simple
15
- * and powerful model, but has the major limitation that the size of
16
- * the document that can be processed is limited by the amount of
17
- * memory available. In such cases, it is better to use the XML::Reader.
18
- *
19
- * Using the parser is simple:
20
- *
21
- * parser = XML::Parser.file('my_file')
22
- * doc = parser.parse
23
- *
24
- * You can also parse documents (see XML::Parser.document),
25
- * strings (see XML::Parser.string) and io objects (see
26
- * XML::Parser.io).
27
- */
28
-
29
- VALUE cXMLParser;
30
- static ID CONTEXT_ATTR;
31
-
32
- /*
33
- * call-seq:
34
- * parser.initialize(context) -> XML::Parser
35
- *
36
- * Creates a new XML::Parser from the specified
37
- * XML::Parser::Context.
38
- */
39
- static VALUE rxml_parser_initialize(int argc, VALUE *argv, VALUE self)
40
- {
41
- VALUE context = Qnil;
42
-
43
- rb_scan_args(argc, argv, "01", &context);
44
-
45
- if (context == Qnil)
46
- {
47
- rb_warn("Passing no parameters to XML::Parser.new is deprecated. Pass an instance of XML::Parser::Context instead.");
48
- context = rb_class_new_instance(0, NULL, cXMLParserContext);
49
- }
50
-
51
- rb_ivar_set(self, CONTEXT_ATTR, context);
52
- return self;
53
- }
54
-
55
- /*
56
- * call-seq:
57
- * parser.parse -> XML::Document
58
- *
59
- * Parse the input XML and create an XML::Document with
60
- * it's content. If an error occurs, XML::Parser::ParseError
61
- * is thrown.
62
- */
63
- static VALUE rxml_parser_parse(VALUE self)
64
- {
65
- xmlParserCtxtPtr ctxt;
66
- VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
67
-
68
- Data_Get_Struct(context, xmlParserCtxt, ctxt);
69
-
70
- if ((xmlParseDocument(ctxt) == -1 || !ctxt->wellFormed) && ! ctxt->recovery)
71
- {
72
- if (ctxt->myDoc)
73
- xmlFreeDoc(ctxt->myDoc);
74
- rxml_raise(&ctxt->lastError);
75
- }
76
-
77
- rb_funcall(context, rb_intern("close"), 0);
78
-
79
- return rxml_document_wrap(ctxt->myDoc);
80
- }
81
-
82
- void rxml_init_parser(void)
83
- {
84
- cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
85
-
86
- /* Atributes */
87
- CONTEXT_ATTR = rb_intern("@context");
88
- rb_define_attr(cXMLParser, "input", 1, 0);
89
- rb_define_attr(cXMLParser, "context", 1, 0);
90
-
91
- /* Instance Methods */
92
- rb_define_method(cXMLParser, "initialize", rxml_parser_initialize, -1);
93
- rb_define_method(cXMLParser, "parse", rxml_parser_parse, 0);
94
- }
1
+ /* Please see the LICENSE file for copyright and distribution information */
2
+
3
+ #include <stdarg.h>
4
+ #include "ruby_libxml.h"
5
+
6
+ /*
7
+ * Document-class: LibXML::XML::Parser
8
+ *
9
+ * The XML::Parser provides a tree based API for processing
10
+ * xml documents, in contract to XML::Reader's stream
11
+ * based api and XML::SaxParser callback based API.
12
+ *
13
+ * As a result, parsing a document creates an in-memory document object
14
+ * that consist of any number of XML::Node instances. This is simple
15
+ * and powerful model, but has the major limitation that the size of
16
+ * the document that can be processed is limited by the amount of
17
+ * memory available. In such cases, it is better to use the XML::Reader.
18
+ *
19
+ * Using the parser is simple:
20
+ *
21
+ * parser = XML::Parser.file('my_file')
22
+ * doc = parser.parse
23
+ *
24
+ * You can also parse documents (see XML::Parser.document),
25
+ * strings (see XML::Parser.string) and io objects (see
26
+ * XML::Parser.io).
27
+ */
28
+
29
+ VALUE cXMLParser;
30
+ static ID CONTEXT_ATTR;
31
+
32
+ /*
33
+ * call-seq:
34
+ * parser.initialize(context) -> XML::Parser
35
+ *
36
+ * Creates a new XML::Parser from the specified
37
+ * XML::Parser::Context.
38
+ */
39
+ static VALUE rxml_parser_initialize(int argc, VALUE *argv, VALUE self)
40
+ {
41
+ VALUE context = Qnil;
42
+
43
+ rb_scan_args(argc, argv, "01", &context);
44
+
45
+ if (context == Qnil)
46
+ {
47
+ rb_raise(rb_eArgError, "An instance of a XML::Parser::Context must be passed to XML::Parser.new");
48
+ }
49
+
50
+ rb_ivar_set(self, CONTEXT_ATTR, context);
51
+ return self;
52
+ }
53
+
54
+ /*
55
+ * call-seq:
56
+ * parser.parse -> XML::Document
57
+ *
58
+ * Parse the input XML and create an XML::Document with
59
+ * it's content. If an error occurs, XML::Parser::ParseError
60
+ * is thrown.
61
+ */
62
+ static VALUE rxml_parser_parse(VALUE self)
63
+ {
64
+ xmlParserCtxtPtr ctxt;
65
+ VALUE context = rb_ivar_get(self, CONTEXT_ATTR);
66
+
67
+ Data_Get_Struct(context, xmlParserCtxt, ctxt);
68
+
69
+ if ((xmlParseDocument(ctxt) == -1 || !ctxt->wellFormed) && ! ctxt->recovery)
70
+ {
71
+ rxml_raise(&ctxt->lastError);
72
+ }
73
+
74
+ rb_funcall(context, rb_intern("close"), 0);
75
+
76
+ return rxml_document_wrap(ctxt->myDoc);
77
+ }
78
+
79
+ void rxml_init_parser(void)
80
+ {
81
+ cXMLParser = rb_define_class_under(mXML, "Parser", rb_cObject);
82
+
83
+ /* Atributes */
84
+ CONTEXT_ATTR = rb_intern("@context");
85
+ rb_define_attr(cXMLParser, "input", 1, 0);
86
+ rb_define_attr(cXMLParser, "context", 1, 0);
87
+
88
+ /* Instance Methods */
89
+ rb_define_method(cXMLParser, "initialize", rxml_parser_initialize, -1);
90
+ rb_define_method(cXMLParser, "parse", rxml_parser_parse, 0);
91
+ }