libxml-ruby 0.7.0-x86-mswin32-60 → 0.8.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/CHANGES +24 -1
  2. data/README +48 -3
  3. data/benchmark/depixelate.rb +632 -0
  4. data/benchmark/hamlet.xml +9055 -0
  5. data/benchmark/sock_entries.xml +507 -0
  6. data/benchmark/throughput.rb +39 -0
  7. data/benchmark/xml_benchmarks.rb +222 -0
  8. data/doc/classes/LibXML.html +237 -0
  9. data/doc/classes/LibXML/XML.html +178 -0
  10. data/doc/classes/{XML → LibXML/XML}/Attr.html +213 -182
  11. data/doc/classes/{XML → LibXML/XML}/Attributes.html +126 -54
  12. data/doc/classes/{XML → LibXML/XML}/Document.html +299 -297
  13. data/doc/classes/{XML → LibXML/XML}/Dtd.html +10 -10
  14. data/doc/classes/{XML/XInclude → LibXML/XML}/Error.html +4 -4
  15. data/doc/classes/{XML → LibXML/XML}/HTMLParser.html +40 -40
  16. data/doc/classes/{XML → LibXML/XML}/InputCallbacks.html +10 -10
  17. data/doc/classes/{XML → LibXML/XML}/NS.html +46 -46
  18. data/doc/classes/{XML → LibXML/XML}/Node.html +935 -788
  19. data/doc/classes/LibXML/XML/Node/FailedModify.html +111 -0
  20. data/doc/classes/{XML → LibXML/XML}/Node/Set.html +69 -68
  21. data/doc/classes/{XML → LibXML/XML}/Node/SetNamespace.html +4 -4
  22. data/doc/classes/{XML/Node/FailedModify.html → LibXML/XML/Node/UnknownType.html} +4 -4
  23. data/doc/classes/{XML → LibXML/XML}/Parser.html +426 -389
  24. data/doc/classes/{XML → LibXML/XML}/Parser/Context.html +208 -208
  25. data/doc/classes/{XML → LibXML/XML}/Parser/ParseError.html +4 -4
  26. data/doc/classes/{XML → LibXML/XML}/Reader.html +288 -287
  27. data/doc/classes/{XML → LibXML/XML}/SaxParser.html +52 -52
  28. data/doc/classes/{XML/XPath/Context.html → LibXML/XML/Schema.html} +60 -32
  29. data/doc/classes/{XML → LibXML/XML}/State.html +4 -4
  30. data/doc/classes/{XML/Node/UnknownType.html → LibXML/XML/Tree.html} +5 -5
  31. data/doc/classes/{XML → LibXML/XML}/XInclude.html +5 -5
  32. data/doc/classes/{XML → LibXML/XML/XInclude}/Error.html +5 -5
  33. data/doc/classes/{XML → LibXML/XML}/XMLParserOptions.html +5 -5
  34. data/doc/classes/{XML → LibXML/XML}/XPath.html +23 -64
  35. data/doc/classes/LibXML/XML/XPath/Context.html +403 -0
  36. data/doc/classes/{XML/XPointer/Context → LibXML/XML/XPath}/InvalidPath.html +4 -4
  37. data/doc/classes/LibXML/XML/XPath/Object.html +623 -0
  38. data/doc/classes/{XML → LibXML/XML}/XPointer.html +12 -12
  39. data/doc/classes/{XML → LibXML/XML}/XPointer/Context.html +5 -5
  40. data/doc/classes/{XML/XPath → LibXML/XML/XPointer/Context}/InvalidPath.html +5 -5
  41. data/doc/classes/{XML → LibXML/XML}/XPointer/InvalidExpression.html +4 -4
  42. data/doc/classes/XML.html +17 -123
  43. data/doc/created.rid +1 -1
  44. data/doc/files/CHANGES.html +49 -25
  45. data/doc/files/LICENSE.html +1 -1
  46. data/doc/files/README.html +79 -4
  47. data/doc/files/VERSION.html +2 -2
  48. data/doc/files/ext/libxml/cbg_c.html +1 -1
  49. data/doc/files/ext/libxml/libxml_c.html +1 -1
  50. data/doc/files/ext/libxml/ruby_xml_attr_c.html +1 -1
  51. data/doc/files/ext/libxml/ruby_xml_attributes_c.html +1 -1
  52. data/doc/files/ext/libxml/ruby_xml_document_c.html +1 -1
  53. data/doc/files/ext/libxml/ruby_xml_dtd_c.html +1 -1
  54. data/doc/files/ext/libxml/ruby_xml_html_parser_c.html +1 -1
  55. data/doc/files/ext/libxml/ruby_xml_input_cbg_c.html +1 -1
  56. data/doc/files/ext/libxml/ruby_xml_node_c.html +1 -1
  57. data/doc/files/ext/libxml/ruby_xml_node_set_c.html +1 -1
  58. data/doc/files/ext/libxml/ruby_xml_ns_c.html +1 -1
  59. data/doc/files/ext/libxml/ruby_xml_parser_c.html +1 -1
  60. data/doc/files/ext/libxml/ruby_xml_parser_context_c.html +1 -1
  61. data/doc/files/ext/libxml/ruby_xml_reader_c.html +1 -1
  62. data/doc/files/ext/libxml/ruby_xml_sax_parser_c.html +1 -1
  63. data/doc/files/ext/libxml/ruby_xml_schema_c.html +1 -1
  64. data/doc/files/ext/libxml/ruby_xml_state_c.html +1 -1
  65. data/doc/files/ext/libxml/ruby_xml_xinclude_c.html +1 -1
  66. data/doc/files/ext/libxml/ruby_xml_xpath_c.html +1 -1
  67. data/doc/files/ext/libxml/ruby_xml_xpath_context_c.html +1 -1
  68. data/doc/files/ext/libxml/ruby_xml_xpath_object_c.html +1 -1
  69. data/doc/files/ext/libxml/ruby_xml_xpointer_c.html +1 -1
  70. data/doc/files/ext/libxml/ruby_xml_xpointer_context_c.html +1 -1
  71. data/doc/files/lib/libxml/attr_rb.html +108 -0
  72. data/doc/files/lib/libxml/attributes_rb.html +108 -0
  73. data/doc/files/lib/libxml/document_rb.html +108 -0
  74. data/doc/files/lib/libxml/node_rb.html +108 -0
  75. data/doc/files/lib/libxml/node_set_rb.html +108 -0
  76. data/doc/files/lib/libxml/parser_options_rb.html +107 -0
  77. data/doc/files/{ext/libxml/ruby_xml_tree_c.html → lib/libxml/parser_rb.html} +4 -4
  78. data/doc/files/lib/libxml/properties_rb.html +108 -0
  79. data/doc/files/lib/libxml/tree_rb.html +107 -0
  80. data/doc/files/lib/libxml_rb.html +12 -3
  81. data/doc/fr_class_index.html +34 -32
  82. data/doc/fr_file_index.html +9 -1
  83. data/doc/fr_method_index.html +362 -347
  84. data/ext/libxml/cbg.c +76 -76
  85. data/ext/libxml/libxml.c +4 -3
  86. data/ext/libxml/ruby_libxml.h +1 -1
  87. data/ext/libxml/ruby_xml_attr.c +4 -3
  88. data/ext/libxml/ruby_xml_attr.h +16 -16
  89. data/ext/libxml/ruby_xml_attributes.c +267 -266
  90. data/ext/libxml/ruby_xml_attributes.h +17 -17
  91. data/ext/libxml/ruby_xml_document.c +30 -59
  92. data/ext/libxml/ruby_xml_document.h +27 -27
  93. data/ext/libxml/ruby_xml_dtd.c +2 -1
  94. data/ext/libxml/ruby_xml_dtd.h +17 -17
  95. data/ext/libxml/ruby_xml_html_parser.c +3 -2
  96. data/ext/libxml/ruby_xml_html_parser.h +29 -29
  97. data/ext/libxml/ruby_xml_input_cbg.c +2 -1
  98. data/ext/libxml/ruby_xml_input_cbg.h +20 -20
  99. data/ext/libxml/ruby_xml_node.c +127 -470
  100. data/ext/libxml/ruby_xml_node.h +17 -17
  101. data/ext/libxml/ruby_xml_node_set.c +5 -4
  102. data/ext/libxml/ruby_xml_node_set.h +20 -20
  103. data/ext/libxml/ruby_xml_ns.c +3 -2
  104. data/ext/libxml/ruby_xml_ns.h +12 -12
  105. data/ext/libxml/ruby_xml_parser.c +20 -48
  106. data/ext/libxml/ruby_xml_parser.h +31 -31
  107. data/ext/libxml/ruby_xml_parser_context.c +3 -2
  108. data/ext/libxml/ruby_xml_parser_context.h +20 -20
  109. data/ext/libxml/ruby_xml_reader.c +2 -1
  110. data/ext/libxml/ruby_xml_sax_parser.c +3 -2
  111. data/ext/libxml/ruby_xml_sax_parser.h +56 -56
  112. data/ext/libxml/ruby_xml_schema.c +6 -0
  113. data/ext/libxml/ruby_xml_schema.h +16 -16
  114. data/ext/libxml/ruby_xml_state.c +13 -12
  115. data/ext/libxml/ruby_xml_state.h +1 -1
  116. data/ext/libxml/ruby_xml_xinclude.c +3 -2
  117. data/ext/libxml/ruby_xml_xinclude.h +13 -13
  118. data/ext/libxml/ruby_xml_xpath.c +35 -228
  119. data/ext/libxml/ruby_xml_xpath.h +22 -23
  120. data/ext/libxml/ruby_xml_xpath_context.c +223 -62
  121. data/ext/libxml/ruby_xml_xpath_context.h +15 -20
  122. data/ext/libxml/ruby_xml_xpath_object.c +63 -19
  123. data/ext/libxml/ruby_xml_xpointer.c +19 -15
  124. data/ext/libxml/ruby_xml_xpointer.h +27 -27
  125. data/ext/libxml/ruby_xml_xpointer_context.c +3 -2
  126. data/ext/libxml/ruby_xml_xpointer_context.h +18 -18
  127. data/ext/libxml/version.h +9 -9
  128. data/lib/libxml.rb +16 -128
  129. data/lib/libxml/attr.rb +45 -0
  130. data/lib/libxml/attributes.rb +15 -0
  131. data/lib/libxml/document.rb +54 -0
  132. data/lib/libxml/node.rb +132 -0
  133. data/lib/libxml/node_set.rb +27 -0
  134. data/lib/libxml/parser.rb +42 -0
  135. data/lib/libxml/parser_options.rb +25 -0
  136. data/lib/libxml/properties.rb +19 -0
  137. data/lib/libxml/tree.rb +29 -0
  138. data/lib/libxml_ruby.so +0 -0
  139. data/mingw/libxml_ruby.so +0 -0
  140. data/{work/task/setup → setup.rb} +1585 -1616
  141. data/test/gc.log +0 -0
  142. data/test/model/books.xml +147 -0
  143. data/{work/test/runner.rb → test/model/default_validation_bug.rb} +0 -0
  144. data/test/model/merge_bug_data.xml +58 -0
  145. data/test/model/rubynet.xml +78 -0
  146. data/test/model/rubynet_project +1 -0
  147. data/test/model/saxtest.xml +5 -0
  148. data/test/model/shiporder.xml +23 -0
  149. data/test/model/shiporder.xsd +31 -0
  150. data/test/model/simple.xml +7 -0
  151. data/test/model/soap.xml +27 -0
  152. data/test/model/xinclude.xml +5 -0
  153. data/test/tc_deprecated_require.rb +13 -0
  154. data/test/tc_xml_document.rb +57 -16
  155. data/test/tc_xml_document_write.rb +125 -10
  156. data/test/tc_xml_dtd.rb +22 -1
  157. data/test/tc_xml_node.rb +13 -0
  158. data/test/tc_xml_node_edit.rb +1 -1
  159. data/test/tc_xml_node_xlink.rb +1 -1
  160. data/test/tc_xml_parser.rb +64 -7
  161. data/test/tc_xml_properties.rb +42 -0
  162. data/test/tc_xml_reader.rb +4 -4
  163. data/test/tc_xml_sax_parser.rb +50 -50
  164. data/test/tc_xml_schema.rb +2 -2
  165. data/test/tc_xml_traversal.rb +220 -0
  166. data/test/tc_xml_xinclude.rb +12 -15
  167. data/test/tc_xml_xpath.rb +74 -6
  168. data/test/tc_xml_xpath_context.rb +72 -0
  169. data/test/test_suite.rb +6 -4
  170. data/vc/libxml_ruby.vcproj +1 -9
  171. metadata +92 -65
  172. data/doc/classes/XML/SiblingEnum.html +0 -142
  173. data/doc/classes/XML/Tree.html +0 -224
  174. data/doc/classes/XML/XPath/Object.html +0 -439
  175. data/ext/libxml/ruby_xml_tree.c +0 -43
  176. data/ext/libxml/ruby_xml_tree.h +0 -12
  177. data/test/ets_copy_bug2.rb +0 -21
  178. data/test/tc_xml_document_write2.rb +0 -54
  179. data/test/tc_xml_document_write3.rb +0 -96
  180. data/test/tc_xml_sax_parser2.rb +0 -51
  181. data/work/Rakefile +0 -247
  182. data/work/task/make +0 -26
  183. data/work/task/memory +0 -37
  184. data/work/task/rdoc +0 -39
  185. data/work/task/test +0 -29
  186. data/work/test/ets_runner.rb +0 -33
  187. data/work/test/libxml_test.rb +0 -3
  188. data/work/test/runner_ets.rb +0 -33
@@ -1,76 +1,76 @@
1
- #include <string.h>
2
- #include <libxml/xmlIO.h>
3
- #include "ruby.h"
4
-
5
- /*
6
- int xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc,
7
- xmlInputOpenCallback openFunc,
8
- xmlInputReadCallback readFunc,
9
- xmlInputCloseCallback closeFunc);
10
-
11
-
12
- int (*xmlInputMatchCallback) (char const *filename);
13
- void* (*xmlInputOpenCallback) (char const *filename);
14
- int (*xmlInputReadCallback) (void *context,
15
- char *buffer,
16
- int len);
17
- int (*xmlInputCloseCallback) (void *context);
18
- */
19
-
20
- typedef struct deb_doc_context {
21
- char *buffer;
22
- char *bpos;
23
- int remaining;
24
- } deb_doc_context;
25
-
26
- int deb_Match (char const *filename) {
27
- fprintf( stderr, "deb_Match: %s\n", filename );
28
- if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "deb://", 6)) {
29
- return(1);
30
- }
31
- return(0);
32
- }
33
-
34
- void* deb_Open (char const *filename) {
35
- deb_doc_context *deb_doc;
36
- VALUE res;
37
-
38
- deb_doc = (deb_doc_context*)malloc( sizeof(deb_doc_context) );
39
-
40
- res = rb_funcall( rb_funcall( rb_mKernel, rb_intern("const_get"), 1, rb_str_new2("DEBSystem") ),
41
- rb_intern("document_query"), 1, rb_str_new2(filename));
42
- deb_doc->buffer = strdup( StringValuePtr(res) );
43
- //deb_doc->buffer = strdup("<serepes>serepes</serepes>");
44
-
45
- deb_doc->bpos = deb_doc->buffer;
46
- deb_doc->remaining = strlen(deb_doc->buffer);
47
- return deb_doc;
48
- }
49
-
50
- int deb_Read (void *context, char *buffer, int len) {
51
- deb_doc_context *deb_doc;
52
- int ret_len;
53
- deb_doc = (deb_doc_context*)context;
54
-
55
- if (len >= deb_doc->remaining) {
56
- ret_len = deb_doc->remaining;
57
- } else {
58
- ret_len = len;
59
- }
60
- deb_doc->remaining -= ret_len;
61
- strncpy( buffer, deb_doc->bpos, ret_len );
62
- deb_doc->bpos += ret_len;
63
-
64
- return ret_len;
65
- }
66
-
67
- int deb_Close (void *context) {
68
- free( ((deb_doc_context*)context)->buffer );
69
- free( context );
70
- return 1;
71
- }
72
-
73
-
74
- void deb_register_cbg() {
75
- xmlRegisterInputCallbacks( deb_Match, deb_Open, deb_Read, deb_Close );
76
- }
1
+ #include <string.h>
2
+ #include <libxml/xmlIO.h>
3
+ #include "ruby.h"
4
+
5
+ /*
6
+ int xmlRegisterInputCallbacks (xmlInputMatchCallback matchFunc,
7
+ xmlInputOpenCallback openFunc,
8
+ xmlInputReadCallback readFunc,
9
+ xmlInputCloseCallback closeFunc);
10
+
11
+
12
+ int (*xmlInputMatchCallback) (char const *filename);
13
+ void* (*xmlInputOpenCallback) (char const *filename);
14
+ int (*xmlInputReadCallback) (void *context,
15
+ char *buffer,
16
+ int len);
17
+ int (*xmlInputCloseCallback) (void *context);
18
+ */
19
+
20
+ typedef struct deb_doc_context {
21
+ char *buffer;
22
+ char *bpos;
23
+ int remaining;
24
+ } deb_doc_context;
25
+
26
+ int deb_Match (char const *filename) {
27
+ fprintf( stderr, "deb_Match: %s\n", filename );
28
+ if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "deb://", 6)) {
29
+ return(1);
30
+ }
31
+ return(0);
32
+ }
33
+
34
+ void* deb_Open (char const *filename) {
35
+ deb_doc_context *deb_doc;
36
+ VALUE res;
37
+
38
+ deb_doc = (deb_doc_context*)malloc( sizeof(deb_doc_context) );
39
+
40
+ res = rb_funcall( rb_funcall( rb_mKernel, rb_intern("const_get"), 1, rb_str_new2("DEBSystem") ),
41
+ rb_intern("document_query"), 1, rb_str_new2(filename));
42
+ deb_doc->buffer = strdup( StringValuePtr(res) );
43
+ //deb_doc->buffer = strdup("<serepes>serepes</serepes>");
44
+
45
+ deb_doc->bpos = deb_doc->buffer;
46
+ deb_doc->remaining = strlen(deb_doc->buffer);
47
+ return deb_doc;
48
+ }
49
+
50
+ int deb_Read (void *context, char *buffer, int len) {
51
+ deb_doc_context *deb_doc;
52
+ int ret_len;
53
+ deb_doc = (deb_doc_context*)context;
54
+
55
+ if (len >= deb_doc->remaining) {
56
+ ret_len = deb_doc->remaining;
57
+ } else {
58
+ ret_len = len;
59
+ }
60
+ deb_doc->remaining -= ret_len;
61
+ strncpy( buffer, deb_doc->bpos, ret_len );
62
+ deb_doc->bpos += ret_len;
63
+
64
+ return ret_len;
65
+ }
66
+
67
+ int deb_Close (void *context) {
68
+ free( ((deb_doc_context*)context)->buffer );
69
+ free( context );
70
+ return 1;
71
+ }
72
+
73
+
74
+ void deb_register_cbg() {
75
+ xmlRegisterInputCallbacks( deb_Match, deb_Open, deb_Read, deb_Close );
76
+ }
@@ -1,9 +1,10 @@
1
- /* $Id: libxml.c 323 2008-07-08 22:59:23Z cfis $ */
1
+ /* $Id: libxml.c 462 2008-07-15 21:52:47Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
5
5
  #include "ruby_libxml.h"
6
6
 
7
+ VALUE mLibXML;
7
8
  VALUE mXML;
8
9
  VALUE eXMLError;
9
10
 
@@ -26,7 +27,8 @@ Init_libxml_ruby(void) {
26
27
  rb_fatal("could not install the memory handlers for libxml");
27
28
  #endif
28
29
 
29
- mXML = rb_define_module("XML");
30
+ mLibXML = rb_define_module("LibXML");
31
+ mXML = rb_define_module_under(mLibXML, "XML");
30
32
  eXMLError = rb_define_class_under(mXML, "Error", rb_eRuntimeError);
31
33
 
32
34
  rb_define_const(mXML, "XML_NAMESPACE", rb_str_new2((const char*)XML_XML_NAMESPACE));
@@ -41,7 +43,6 @@ Init_libxml_ruby(void) {
41
43
  ruby_init_xml_node_set();
42
44
  ruby_init_xml_ns();
43
45
  ruby_init_xml_sax_parser();
44
- ruby_init_xml_tree();
45
46
  ruby_init_xml_xinclude();
46
47
  ruby_init_xml_xpath();
47
48
  ruby_init_xml_xpath_context();
@@ -72,7 +72,6 @@ typedef struct rx_xpath_data {
72
72
  #include "ruby_xml_parser.h"
73
73
  #include "ruby_xml_parser_context.h"
74
74
  #include "ruby_xml_sax_parser.h"
75
- #include "ruby_xml_tree.h"
76
75
  #include "ruby_xml_xinclude.h"
77
76
  #include "ruby_xml_xpath.h"
78
77
  #include "ruby_xml_xpath_context.h"
@@ -85,6 +84,7 @@ typedef struct rx_xpath_data {
85
84
  #include "ruby_xml_html_parser.h"
86
85
  #include "ruby_xml_reader.h"
87
86
 
87
+ extern VALUE mLibXML;
88
88
  extern VALUE mXML;
89
89
  extern VALUE eXMLError;
90
90
 
@@ -1,9 +1,9 @@
1
- /* $Id: ruby_xml_attr.c 351 2008-07-09 19:55:21Z cfis $ */
1
+ /* $Id: ruby_xml_attr.c 461 2008-07-15 21:35:56Z cfis $ */
2
2
 
3
3
  /* Please see the LICENSE file for copyright and distribution information */
4
4
 
5
5
  /*
6
- * Document-class: XML::Attr
6
+ * Document-class: LibXML::XML::Attr
7
7
  *
8
8
  * Provides access to an single element attribute. Accessed by
9
9
  * calling XML::Node#attributes method.
@@ -463,7 +463,8 @@ ruby_xml_attr_value_set(VALUE self, VALUE val) {
463
463
 
464
464
  // Rdoc needs to know
465
465
  #ifdef RDOC_NEVER_DEFINED
466
- mXML = rb_define_module("XML");
466
+ mLibXML = rb_define_module("LibXML");
467
+ mXML = rb_define_module_under(mLibXML, "XML");
467
468
  #endif
468
469
 
469
470
  void
@@ -1,16 +1,16 @@
1
- /* $Id: ruby_xml_attr.h 351 2008-07-09 19:55:21Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- #ifndef __RUBY_XML_ATTR__
6
- #define __RUBY_XML_ATTR__
7
-
8
- extern VALUE cXMLAttr;
9
-
10
- void ruby_init_xml_attr(void);
11
- VALUE ruby_xml_attr_new(xmlAttrPtr xattr);
12
- VALUE ruby_xml_attr_value_get(VALUE self);
13
- VALUE ruby_xml_attr_value_set(VALUE self, VALUE val);
14
- void ruby_xml_attr_free(xmlAttrPtr xattr);
15
- VALUE ruby_xml_attr_wrap(xmlAttrPtr xattr);
16
- #endif
1
+ /* $Id: ruby_xml_attr.h 351 2008-07-09 19:55:21Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ #ifndef __RUBY_XML_ATTR__
6
+ #define __RUBY_XML_ATTR__
7
+
8
+ extern VALUE cXMLAttr;
9
+
10
+ void ruby_init_xml_attr(void);
11
+ VALUE ruby_xml_attr_new(xmlAttrPtr xattr);
12
+ VALUE ruby_xml_attr_value_get(VALUE self);
13
+ VALUE ruby_xml_attr_value_set(VALUE self, VALUE val);
14
+ void ruby_xml_attr_free(xmlAttrPtr xattr);
15
+ VALUE ruby_xml_attr_wrap(xmlAttrPtr xattr);
16
+ #endif
@@ -1,268 +1,269 @@
1
- /* $Id: ruby_xml_attributes.c 300 2008-07-01 19:14:15Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- /*
6
- * Document-class: XML::Attributes
7
- *
8
- * Provides access to an elements attributes (XML::Attr).
9
- *
10
- * Basic Usage:
11
- * require 'libxml'
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
-
32
- #include "ruby_libxml.h"
33
- #include "ruby_xml_attributes.h"
34
-
35
- VALUE cXMLAttributes;
36
-
37
- void
38
- ruby_xml_attributes_mark(xmlNodePtr xnode) {
39
- ruby_xml_node_mark_common(xnode);
40
- }
41
-
42
- /*
43
- * Creates a new attributes instance. Not exposed to ruby.
44
- */
45
- VALUE
46
- ruby_xml_attributes_new(xmlNodePtr xnode)
47
- {
48
- return Data_Wrap_Struct(cXMLAttributes,
49
- ruby_xml_attributes_mark, NULL,
50
- xnode);
51
- }
52
-
53
- /*
54
- * call-seq:
55
- * attributes.node -> XML::Node
56
- *
57
- * Return the node that owns this attributes list.
58
- *
59
- * doc.root.attributes.node == doc.root
60
- */
61
- VALUE
62
- ruby_xml_attributes_node_get(VALUE self) {
63
- xmlNodePtr xnode;
64
- Data_Get_Struct(self, xmlNode, xnode);
65
- return(ruby_xml_node2_wrap(cXMLNode, xnode));
66
- }
67
-
68
-
69
- /*
70
- * call-seq:
71
- * attributes.get_attribute("name") -> XML::Attr
72
- *
73
- * Returns the specified attribute.
74
- *
75
- * name: The name of the attribute, not including a namespace.
76
- *
77
- * doc.root.attributes.get_attribute("foo")
78
- */
79
- VALUE
80
- ruby_xml_attributes_get_attribute(VALUE self, VALUE name) {
81
- xmlNodePtr xnode;
82
- xmlAttrPtr xattr;
83
-
84
- name = check_string_or_symbol(name);
85
-
86
- Data_Get_Struct(self, xmlNode, xnode);
87
-
88
- xattr = xmlHasProp(xnode, (xmlChar*)StringValuePtr(name));
89
-
90
- if (xattr)
91
- return(ruby_xml_attr_wrap(xattr));
92
- else
93
- return(Qnil);
94
- }
95
-
96
- /*
97
- * call-seq:
98
- * attributes.get_attribute_ns("namespace", "name") -> XML::Attr
99
- *
100
- * Returns the specified attribute.
101
- *
102
- * namespace: The URI of the attribute's namespace.
103
- * name: The name of the attribute, not including a namespace.
104
- *
105
- * doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
106
- */
107
- VALUE
108
- ruby_xml_attributes_get_attribute_ns(VALUE self, VALUE namespace, VALUE name) {
109
- xmlNodePtr xnode;
110
- xmlAttrPtr xattr;
111
-
112
- name = check_string_or_symbol(name);
113
-
114
- Data_Get_Struct(self, xmlNode, xnode);
115
-
116
- xattr = xmlHasNsProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(namespace));
117
-
118
- if (xattr)
119
- return(ruby_xml_attr_wrap(xattr));
120
- else
121
- return(Qnil);
122
- }
123
-
124
- /*
125
- * call-seq:
126
- * attributes["name"] -> String
127
- *
128
- * Fetches an attribute value. If you want to access the underlying
129
- * Attribute itself use get_attribute.
130
- *
131
- * name: The name of the attribute, not including any namespaces.
132
- *
133
- * doc.root.attributes['att'] -> 'some value'
134
- */
135
- VALUE
136
- ruby_xml_attributes_attribute_get(VALUE self, VALUE name) {
137
- VALUE xattr = ruby_xml_attributes_get_attribute(self, name);
138
- if NIL_P(xattr)
139
- return(Qnil);
140
- else
141
- return ruby_xml_attr_value_get(xattr);
142
- }
143
-
144
- /*
145
- * call-seq:
146
- * attributes["name"] = "value"
147
- *
148
- * Sets an attribute value. If you want to get the Attribute itself,
149
- * use get_attribute.
150
- *
151
- * name: The name of the attribute, not including any namespaces.
152
- * value: The new value of the namespace.
153
- *
154
- * doc.root.attributes['att'] = 'some value'
155
- */
156
- VALUE
157
- ruby_xml_attributes_attribute_set(VALUE self, VALUE name, VALUE value) {
158
- VALUE xattr = ruby_xml_attributes_get_attribute(self, name);
159
- if NIL_P(xattr)
160
- {
161
- VALUE args[3];
162
-
163
- args[0] = ruby_xml_attributes_node_get(self);
164
- args[1] = name;
165
- args[2] = value;
166
-
167
- return rb_class_new_instance(sizeof(args)/sizeof(VALUE), args, cXMLAttr);
168
- }
169
- else
170
- {
171
- return ruby_xml_attr_value_set(xattr, value);
172
- }
173
- }
174
-
175
-
176
- /*
177
- * call-seq:
178
- * attributes.each {block} -> XML::Attr
179
- *
180
- * Iterates over each attribute.
181
- *
182
- * doc.root.attributes.each {|attribute| puts attribute.name}
183
- */
184
- VALUE
185
- ruby_xml_attributes_each(VALUE self) {
186
- xmlNodePtr xnode;
187
- xmlAttrPtr xattr;
188
- Data_Get_Struct(self, xmlNode, xnode);
189
-
190
- xattr = xnode->properties;
191
-
192
- while (xattr)
193
- {
194
- VALUE attr = ruby_xml_attr_wrap(xattr);
195
- rb_yield(attr);
196
- xattr = xattr->next;
197
- }
198
-
199
- return self;
200
- }
201
-
202
- /*
203
- * call-seq:
204
- * attributes.length -> Integer
205
- *
206
- * Returns the number of attributes.
207
- *
208
- * doc.root.attributes.length
209
- */
210
- VALUE
211
- ruby_xml_attributes_length(VALUE self) {
212
- int length = 0;
213
- xmlNodePtr xnode;
214
- xmlAttrPtr xattr;
215
- Data_Get_Struct(self, xmlNode, xnode);
216
-
217
- xattr = xnode->properties;
218
-
219
- while (xattr)
220
- {
221
- length++;
222
- xattr = xattr->next;
223
- }
224
-
225
- return INT2NUM(length);
226
- }
227
-
228
- /*
229
- * call-seq:
230
- * attributes.first -> XML::Attr
231
- *
232
- * Returns the first attribute.
233
- *
234
- * doc.root.attributes.first
235
- */
236
- VALUE
237
- ruby_xml_attributes_first(VALUE self) {
238
- xmlNodePtr xnode;
239
- Data_Get_Struct(self, xmlNode, xnode);
240
-
241
- if (xnode->type == XML_ELEMENT_NODE) {
242
- xmlAttrPtr xattr = xnode->properties;
243
-
244
- if (xattr) {
245
- return(ruby_xml_attr_wrap(xattr));
246
- }
247
- }
248
- return(Qnil);
249
- }
250
-
251
- // Rdoc needs to know
1
+ /* $Id: ruby_xml_attributes.c 300 2008-07-01 19:14:15Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ /*
6
+ * Document-class: LibXML::XML::Attributes
7
+ *
8
+ * Provides access to an elements attributes (XML::Attr).
9
+ *
10
+ * Basic Usage:
11
+ * require 'libxml'
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
+
32
+ #include "ruby_libxml.h"
33
+ #include "ruby_xml_attributes.h"
34
+
35
+ VALUE cXMLAttributes;
36
+
37
+ void
38
+ ruby_xml_attributes_mark(xmlNodePtr xnode) {
39
+ ruby_xml_node_mark_common(xnode);
40
+ }
41
+
42
+ /*
43
+ * Creates a new attributes instance. Not exposed to ruby.
44
+ */
45
+ VALUE
46
+ ruby_xml_attributes_new(xmlNodePtr xnode)
47
+ {
48
+ return Data_Wrap_Struct(cXMLAttributes,
49
+ ruby_xml_attributes_mark, NULL,
50
+ xnode);
51
+ }
52
+
53
+ /*
54
+ * call-seq:
55
+ * attributes.node -> XML::Node
56
+ *
57
+ * Return the node that owns this attributes list.
58
+ *
59
+ * doc.root.attributes.node == doc.root
60
+ */
61
+ VALUE
62
+ ruby_xml_attributes_node_get(VALUE self) {
63
+ xmlNodePtr xnode;
64
+ Data_Get_Struct(self, xmlNode, xnode);
65
+ return(ruby_xml_node2_wrap(cXMLNode, xnode));
66
+ }
67
+
68
+
69
+ /*
70
+ * call-seq:
71
+ * attributes.get_attribute("name") -> XML::Attr
72
+ *
73
+ * Returns the specified attribute.
74
+ *
75
+ * name: The name of the attribute, not including a namespace.
76
+ *
77
+ * doc.root.attributes.get_attribute("foo")
78
+ */
79
+ VALUE
80
+ ruby_xml_attributes_get_attribute(VALUE self, VALUE name) {
81
+ xmlNodePtr xnode;
82
+ xmlAttrPtr xattr;
83
+
84
+ name = check_string_or_symbol(name);
85
+
86
+ Data_Get_Struct(self, xmlNode, xnode);
87
+
88
+ xattr = xmlHasProp(xnode, (xmlChar*)StringValuePtr(name));
89
+
90
+ if (xattr)
91
+ return(ruby_xml_attr_wrap(xattr));
92
+ else
93
+ return(Qnil);
94
+ }
95
+
96
+ /*
97
+ * call-seq:
98
+ * attributes.get_attribute_ns("namespace", "name") -> XML::Attr
99
+ *
100
+ * Returns the specified attribute.
101
+ *
102
+ * namespace: The URI of the attribute's namespace.
103
+ * name: The name of the attribute, not including a namespace.
104
+ *
105
+ * doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
106
+ */
107
+ VALUE
108
+ ruby_xml_attributes_get_attribute_ns(VALUE self, VALUE namespace, VALUE name) {
109
+ xmlNodePtr xnode;
110
+ xmlAttrPtr xattr;
111
+
112
+ name = check_string_or_symbol(name);
113
+
114
+ Data_Get_Struct(self, xmlNode, xnode);
115
+
116
+ xattr = xmlHasNsProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(namespace));
117
+
118
+ if (xattr)
119
+ return(ruby_xml_attr_wrap(xattr));
120
+ else
121
+ return(Qnil);
122
+ }
123
+
124
+ /*
125
+ * call-seq:
126
+ * attributes["name"] -> String
127
+ *
128
+ * Fetches an attribute value. If you want to access the underlying
129
+ * Attribute itself use get_attribute.
130
+ *
131
+ * name: The name of the attribute, not including any namespaces.
132
+ *
133
+ * doc.root.attributes['att'] -> 'some value'
134
+ */
135
+ VALUE
136
+ ruby_xml_attributes_attribute_get(VALUE self, VALUE name) {
137
+ VALUE xattr = ruby_xml_attributes_get_attribute(self, name);
138
+ if NIL_P(xattr)
139
+ return(Qnil);
140
+ else
141
+ return ruby_xml_attr_value_get(xattr);
142
+ }
143
+
144
+ /*
145
+ * call-seq:
146
+ * attributes["name"] = "value"
147
+ *
148
+ * Sets an attribute value. If you want to get the Attribute itself,
149
+ * use get_attribute.
150
+ *
151
+ * name: The name of the attribute, not including any namespaces.
152
+ * value: The new value of the namespace.
153
+ *
154
+ * doc.root.attributes['att'] = 'some value'
155
+ */
156
+ VALUE
157
+ ruby_xml_attributes_attribute_set(VALUE self, VALUE name, VALUE value) {
158
+ VALUE xattr = ruby_xml_attributes_get_attribute(self, name);
159
+ if NIL_P(xattr)
160
+ {
161
+ VALUE args[3];
162
+
163
+ args[0] = ruby_xml_attributes_node_get(self);
164
+ args[1] = name;
165
+ args[2] = value;
166
+
167
+ return rb_class_new_instance(sizeof(args)/sizeof(VALUE), args, cXMLAttr);
168
+ }
169
+ else
170
+ {
171
+ return ruby_xml_attr_value_set(xattr, value);
172
+ }
173
+ }
174
+
175
+
176
+ /*
177
+ * call-seq:
178
+ * attributes.each {block} -> XML::Attr
179
+ *
180
+ * Iterates over each attribute.
181
+ *
182
+ * doc.root.attributes.each {|attribute| puts attribute.name}
183
+ */
184
+ VALUE
185
+ ruby_xml_attributes_each(VALUE self) {
186
+ xmlNodePtr xnode;
187
+ xmlAttrPtr xattr;
188
+ Data_Get_Struct(self, xmlNode, xnode);
189
+
190
+ xattr = xnode->properties;
191
+
192
+ while (xattr)
193
+ {
194
+ VALUE attr = ruby_xml_attr_wrap(xattr);
195
+ rb_yield(attr);
196
+ xattr = xattr->next;
197
+ }
198
+
199
+ return self;
200
+ }
201
+
202
+ /*
203
+ * call-seq:
204
+ * attributes.length -> Integer
205
+ *
206
+ * Returns the number of attributes.
207
+ *
208
+ * doc.root.attributes.length
209
+ */
210
+ VALUE
211
+ ruby_xml_attributes_length(VALUE self) {
212
+ int length = 0;
213
+ xmlNodePtr xnode;
214
+ xmlAttrPtr xattr;
215
+ Data_Get_Struct(self, xmlNode, xnode);
216
+
217
+ xattr = xnode->properties;
218
+
219
+ while (xattr)
220
+ {
221
+ length++;
222
+ xattr = xattr->next;
223
+ }
224
+
225
+ return INT2NUM(length);
226
+ }
227
+
228
+ /*
229
+ * call-seq:
230
+ * attributes.first -> XML::Attr
231
+ *
232
+ * Returns the first attribute.
233
+ *
234
+ * doc.root.attributes.first
235
+ */
236
+ VALUE
237
+ ruby_xml_attributes_first(VALUE self) {
238
+ xmlNodePtr xnode;
239
+ Data_Get_Struct(self, xmlNode, xnode);
240
+
241
+ if (xnode->type == XML_ELEMENT_NODE) {
242
+ xmlAttrPtr xattr = xnode->properties;
243
+
244
+ if (xattr) {
245
+ return(ruby_xml_attr_wrap(xattr));
246
+ }
247
+ }
248
+ return(Qnil);
249
+ }
250
+
251
+ // Rdoc needs to know
252
252
  #ifdef RDOC_NEVER_DEFINED
253
- mXML = rb_define_module("XML");
253
+ mLibXML = rb_define_module("LibXML");
254
+ mXML = rb_define_module_under(mLibXML, "XML");
254
255
  #endif
255
-
256
- void
257
- ruby_init_xml_attributes(void) {
258
- cXMLAttributes = rb_define_class_under(mXML, "Attributes", rb_cObject);
259
- rb_include_module(cXMLAttributes, rb_const_get(rb_cObject, rb_intern("Enumerable")));
260
- rb_define_method(cXMLAttributes, "node", ruby_xml_attributes_node_get, 0);
261
- rb_define_method(cXMLAttributes, "get_attribute", ruby_xml_attributes_get_attribute, 1);
262
- rb_define_method(cXMLAttributes, "get_attribute_ns", ruby_xml_attributes_get_attribute_ns, 2);
263
- rb_define_method(cXMLAttributes, "[]", ruby_xml_attributes_attribute_get, 1);
264
- rb_define_method(cXMLAttributes, "[]=", ruby_xml_attributes_attribute_set, 2);
265
- rb_define_method(cXMLAttributes, "each", ruby_xml_attributes_each, 0);
266
- rb_define_method(cXMLAttributes, "length", ruby_xml_attributes_length, 0);
267
- rb_define_method(cXMLAttributes, "first", ruby_xml_attributes_first, 0);
268
- }
256
+
257
+ void
258
+ ruby_init_xml_attributes(void) {
259
+ cXMLAttributes = rb_define_class_under(mXML, "Attributes", rb_cObject);
260
+ rb_include_module(cXMLAttributes, rb_mEnumerable);
261
+ rb_define_method(cXMLAttributes, "node", ruby_xml_attributes_node_get, 0);
262
+ rb_define_method(cXMLAttributes, "get_attribute", ruby_xml_attributes_get_attribute, 1);
263
+ rb_define_method(cXMLAttributes, "get_attribute_ns", ruby_xml_attributes_get_attribute_ns, 2);
264
+ rb_define_method(cXMLAttributes, "[]", ruby_xml_attributes_attribute_get, 1);
265
+ rb_define_method(cXMLAttributes, "[]=", ruby_xml_attributes_attribute_set, 2);
266
+ rb_define_method(cXMLAttributes, "each", ruby_xml_attributes_each, 0);
267
+ rb_define_method(cXMLAttributes, "length", ruby_xml_attributes_length, 0);
268
+ rb_define_method(cXMLAttributes, "first", ruby_xml_attributes_first, 0);
269
+ }