libxml-ruby 0.8.3-x86-mswin32-60 → 0.9.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/CHANGES +18 -0
  2. data/RAKEFILE +15 -39
  3. data/README +48 -47
  4. data/ext/libxml/libxml.c +847 -22
  5. data/ext/libxml/ruby_libxml.h +71 -95
  6. data/ext/libxml/ruby_xml_attr.c +500 -500
  7. data/ext/libxml/ruby_xml_attributes.c +1 -1
  8. data/ext/libxml/ruby_xml_document.c +1144 -1135
  9. data/ext/libxml/ruby_xml_document.h +4 -11
  10. data/ext/libxml/ruby_xml_dtd.c +27 -0
  11. data/ext/libxml/ruby_xml_encoding.c +164 -0
  12. data/ext/libxml/ruby_xml_encoding.h +13 -0
  13. data/ext/libxml/ruby_xml_error.c +941 -0
  14. data/ext/libxml/ruby_xml_error.h +13 -0
  15. data/ext/libxml/ruby_xml_html_parser.c +71 -387
  16. data/ext/libxml/ruby_xml_html_parser.h +1 -17
  17. data/ext/libxml/ruby_xml_input.c +179 -0
  18. data/ext/libxml/ruby_xml_input.h +18 -0
  19. data/ext/libxml/ruby_xml_input_cbg.c +17 -3
  20. data/ext/libxml/ruby_xml_node.c +1566 -1582
  21. data/ext/libxml/ruby_xml_node.h +1 -4
  22. data/ext/libxml/ruby_xml_ns.c +14 -3
  23. data/ext/libxml/ruby_xml_parser.c +164 -1398
  24. data/ext/libxml/ruby_xml_parser.h +5 -17
  25. data/ext/libxml/ruby_xml_parser_context.c +131 -169
  26. data/ext/libxml/ruby_xml_parser_context.h +2 -9
  27. data/ext/libxml/ruby_xml_reader.c +910 -945
  28. data/ext/libxml/ruby_xml_relaxng.c +32 -3
  29. data/ext/libxml/ruby_xml_sax_parser.c +106 -364
  30. data/ext/libxml/ruby_xml_sax_parser.h +1 -37
  31. data/ext/libxml/ruby_xml_schema.c +174 -145
  32. data/ext/libxml/ruby_xml_xinclude.c +9 -5
  33. data/ext/libxml/ruby_xml_xpath.c +25 -6
  34. data/ext/libxml/ruby_xml_xpath.h +1 -2
  35. data/ext/libxml/ruby_xml_xpath_context.c +17 -19
  36. data/ext/libxml/ruby_xml_xpath_object.c +60 -56
  37. data/ext/libxml/ruby_xml_xpointer.c +11 -5
  38. data/ext/libxml/sax_parser_callbacks.inc +42 -37
  39. data/ext/libxml/version.h +3 -3
  40. data/ext/mingw/Rakefile +20 -27
  41. data/ext/mingw/build.rake +41 -0
  42. data/{lib → ext/mingw}/libiconv-2.dll +0 -0
  43. data/ext/mingw/libxml2-2.dll +0 -0
  44. data/ext/mingw/libxml_ruby.dll.a +0 -0
  45. data/ext/mingw/libxml_ruby.so +0 -0
  46. data/ext/vc/libxml_ruby.vcproj +23 -15
  47. data/lib/libxml.rb +8 -2
  48. data/lib/libxml/document.rb +16 -4
  49. data/lib/libxml/error.rb +84 -0
  50. data/lib/libxml/hpricot.rb +76 -0
  51. data/lib/libxml/html_parser.rb +61 -0
  52. data/lib/libxml/node.rb +36 -25
  53. data/lib/libxml/parser.rb +312 -33
  54. data/lib/libxml/parser_context.rb +17 -0
  55. data/lib/libxml/properties.rb +15 -2
  56. data/lib/libxml/reader.rb +15 -0
  57. data/lib/libxml/sax_callbacks.rb +179 -0
  58. data/lib/libxml/sax_parser.rb +42 -0
  59. data/lib/libxml/tree.rb +1 -2
  60. data/lib/libxml/xpath_object.rb +12 -0
  61. data/test/model/atom.xml +4 -0
  62. data/test/tc_attributes.rb +43 -19
  63. data/test/tc_document.rb +1 -1
  64. data/test/tc_document_write.rb +15 -8
  65. data/test/tc_dtd.rb +36 -20
  66. data/test/tc_encoding.rb +13 -0
  67. data/test/tc_error.rb +136 -0
  68. data/test/tc_node.rb +2 -3
  69. data/test/tc_node_copy.rb +1 -1
  70. data/test/tc_node_edit.rb +6 -0
  71. data/test/tc_ns.rb +18 -0
  72. data/test/tc_parser.rb +113 -228
  73. data/test/tc_parser_context.rb +1 -2
  74. data/test/tc_reader.rb +24 -14
  75. data/test/tc_relaxng.rb +18 -6
  76. data/test/tc_sax_parser.rb +48 -13
  77. data/test/tc_schema.rb +20 -8
  78. data/test/tc_well_formed.rb +2 -1
  79. data/test/tc_xml.rb +212 -0
  80. data/test/tc_xpath.rb +60 -46
  81. data/test/tc_xpointer.rb +7 -11
  82. data/test/test_suite.rb +4 -3
  83. metadata +32 -115
  84. data/doc/rdoc/classes/LibXML.html +0 -241
  85. data/doc/rdoc/classes/LibXML/XML.html +0 -185
  86. data/doc/rdoc/classes/LibXML/XML/Attr.html +0 -1010
  87. data/doc/rdoc/classes/LibXML/XML/Attributes.html +0 -526
  88. data/doc/rdoc/classes/LibXML/XML/Document.html +0 -1489
  89. data/doc/rdoc/classes/LibXML/XML/Dtd.html +0 -213
  90. data/doc/rdoc/classes/LibXML/XML/Error.html +0 -117
  91. data/doc/rdoc/classes/LibXML/XML/HTMLParser.html +0 -348
  92. data/doc/rdoc/classes/LibXML/XML/InputCallbacks.html +0 -160
  93. data/doc/rdoc/classes/LibXML/XML/NS.html +0 -381
  94. data/doc/rdoc/classes/LibXML/XML/Node.html +0 -3396
  95. data/doc/rdoc/classes/LibXML/XML/Node/FailedModify.html +0 -123
  96. data/doc/rdoc/classes/LibXML/XML/Node/Set.html +0 -440
  97. data/doc/rdoc/classes/LibXML/XML/Node/SetNamespace.html +0 -123
  98. data/doc/rdoc/classes/LibXML/XML/Node/UnknownType.html +0 -123
  99. data/doc/rdoc/classes/LibXML/XML/Parser.html +0 -2239
  100. data/doc/rdoc/classes/LibXML/XML/Parser/Context.html +0 -1255
  101. data/doc/rdoc/classes/LibXML/XML/Parser/ParseError.html +0 -123
  102. data/doc/rdoc/classes/LibXML/XML/Reader.html +0 -2264
  103. data/doc/rdoc/classes/LibXML/XML/RelaxNG.html +0 -237
  104. data/doc/rdoc/classes/LibXML/XML/SaxParser.html +0 -415
  105. data/doc/rdoc/classes/LibXML/XML/Schema.html +0 -308
  106. data/doc/rdoc/classes/LibXML/XML/State.html +0 -124
  107. data/doc/rdoc/classes/LibXML/XML/Tree.html +0 -111
  108. data/doc/rdoc/classes/LibXML/XML/XInclude.html +0 -123
  109. data/doc/rdoc/classes/LibXML/XML/XInclude/Error.html +0 -117
  110. data/doc/rdoc/classes/LibXML/XML/XMLParserOptions.html +0 -198
  111. data/doc/rdoc/classes/LibXML/XML/XPath.html +0 -184
  112. data/doc/rdoc/classes/LibXML/XML/XPath/Context.html +0 -404
  113. data/doc/rdoc/classes/LibXML/XML/XPath/InvalidPath.html +0 -172
  114. data/doc/rdoc/classes/LibXML/XML/XPath/Object.html +0 -627
  115. data/doc/rdoc/classes/LibXML/XML/XPointer.html +0 -170
  116. data/doc/rdoc/classes/LibXML/XML/XPointer/Context.html +0 -123
  117. data/doc/rdoc/classes/LibXML/XML/XPointer/Context/InvalidPath.html +0 -117
  118. data/doc/rdoc/classes/LibXML/XML/XPointer/InvalidExpression.html +0 -124
  119. data/doc/rdoc/classes/singleton.html +0 -114
  120. data/doc/rdoc/created.rid +0 -1
  121. data/doc/rdoc/files/CHANGES.html +0 -442
  122. data/doc/rdoc/files/LICENSE.html +0 -133
  123. data/doc/rdoc/files/README.html +0 -388
  124. data/doc/rdoc/files/VERSION.html +0 -107
  125. data/doc/rdoc/files/ext/libxml/cbg_c.html +0 -101
  126. data/doc/rdoc/files/ext/libxml/libxml_c.html +0 -101
  127. data/doc/rdoc/files/ext/libxml/ruby_xml_attr_c.html +0 -101
  128. data/doc/rdoc/files/ext/libxml/ruby_xml_attributes_c.html +0 -101
  129. data/doc/rdoc/files/ext/libxml/ruby_xml_document_c.html +0 -101
  130. data/doc/rdoc/files/ext/libxml/ruby_xml_dtd_c.html +0 -101
  131. data/doc/rdoc/files/ext/libxml/ruby_xml_html_parser_c.html +0 -101
  132. data/doc/rdoc/files/ext/libxml/ruby_xml_input_cbg_c.html +0 -101
  133. data/doc/rdoc/files/ext/libxml/ruby_xml_node_c.html +0 -101
  134. data/doc/rdoc/files/ext/libxml/ruby_xml_node_set_c.html +0 -101
  135. data/doc/rdoc/files/ext/libxml/ruby_xml_ns_c.html +0 -101
  136. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_c.html +0 -101
  137. data/doc/rdoc/files/ext/libxml/ruby_xml_parser_context_c.html +0 -101
  138. data/doc/rdoc/files/ext/libxml/ruby_xml_reader_c.html +0 -101
  139. data/doc/rdoc/files/ext/libxml/ruby_xml_relaxng_c.html +0 -101
  140. data/doc/rdoc/files/ext/libxml/ruby_xml_sax_parser_c.html +0 -101
  141. data/doc/rdoc/files/ext/libxml/ruby_xml_schema_c.html +0 -101
  142. data/doc/rdoc/files/ext/libxml/ruby_xml_state_c.html +0 -101
  143. data/doc/rdoc/files/ext/libxml/ruby_xml_xinclude_c.html +0 -101
  144. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_c.html +0 -101
  145. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_context_c.html +0 -101
  146. data/doc/rdoc/files/ext/libxml/ruby_xml_xpath_object_c.html +0 -101
  147. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_c.html +0 -101
  148. data/doc/rdoc/files/ext/libxml/ruby_xml_xpointer_context_c.html +0 -101
  149. data/doc/rdoc/files/lib/libxml/attr_rb.html +0 -108
  150. data/doc/rdoc/files/lib/libxml/attributes_rb.html +0 -108
  151. data/doc/rdoc/files/lib/libxml/document_rb.html +0 -108
  152. data/doc/rdoc/files/lib/libxml/node_rb.html +0 -108
  153. data/doc/rdoc/files/lib/libxml/node_set_rb.html +0 -108
  154. data/doc/rdoc/files/lib/libxml/parser_options_rb.html +0 -107
  155. data/doc/rdoc/files/lib/libxml/parser_rb.html +0 -101
  156. data/doc/rdoc/files/lib/libxml/properties_rb.html +0 -108
  157. data/doc/rdoc/files/lib/libxml/tree_rb.html +0 -107
  158. data/doc/rdoc/files/lib/libxml_rb.html +0 -124
  159. data/doc/rdoc/files/lib/xml/libxml_rb.html +0 -124
  160. data/doc/rdoc/files/lib/xml_rb.html +0 -134
  161. data/doc/rdoc/fr_class_index.html +0 -62
  162. data/doc/rdoc/fr_file_index.html +0 -66
  163. data/doc/rdoc/fr_method_index.html +0 -392
  164. data/doc/rdoc/index.html +0 -24
  165. data/doc/rdoc/rdoc-style.css +0 -208
  166. data/ext/libxml/ruby_xml_node_set.c +0 -172
  167. data/ext/libxml/ruby_xml_node_set.h +0 -20
  168. data/ext/libxml/ruby_xml_xpointer_context.c +0 -22
  169. data/ext/libxml/ruby_xml_xpointer_context.h +0 -18
  170. data/lib/libxml/node_set.rb +0 -27
  171. data/lib/libxml2-2.dll +0 -0
  172. data/lib/libxml_ruby.dll.a +0 -0
  173. data/lib/libxml_ruby.so +0 -0
  174. data/test/tc_node_set.rb +0 -24
  175. data/test/tc_node_set2.rb +0 -37
@@ -1,95 +1,71 @@
1
- /* Please see the LICENSE file for copyright and distribution information */
2
-
3
- #ifndef __RUBY_LIBXML_H__
4
- #define __RUBY_LIBXML_H__
5
-
6
- #include "version.h"
7
-
8
- #include <ruby.h>
9
- #include <rubyio.h>
10
- #include <util.h>
11
- #include <libxml/parser.h>
12
- #include <libxml/parserInternals.h>
13
- #include <libxml/debugXML.h>
14
- #include <libxml/xmlversion.h>
15
- #include <libxml/xmlmemory.h>
16
- #include <libxml/xpath.h>
17
- #include <libxml/valid.h>
18
- #include <libxml/catalog.h>
19
- #include <libxml/HTMLparser.h>
20
- #include <libxml/xmlreader.h>
21
-
22
- // Maybe not yet defined in ruby
23
- #ifndef RSTRING_LEN
24
- #define RSTRING_LEN(x) RSTRING(x)->len
25
- #endif
26
-
27
- // not in Ruby 1.9
28
- #ifndef GetWriteFile
29
- #define GetWriteFile(fp) rb_io_stdio_file(fp)
30
- #define OpenFile rb_io_t
31
- #endif
32
-
33
- #ifdef LIBXML_DEBUG_ENABLED
34
- #include <libxml/xpathInternals.h>
35
- #endif
36
- #ifdef LIBXML_XINCLUDE_ENABLED
37
- #include <libxml/xinclude.h>
38
- #endif
39
- #ifdef LIBXML_XPTR_ENABLED
40
- #include <libxml/xpointer.h>
41
- #endif
42
-
43
- #define RUBY_LIBXML_SRC_TYPE_NULL 0
44
- #define RUBY_LIBXML_SRC_TYPE_FILE 1
45
- #define RUBY_LIBXML_SRC_TYPE_STRING 2
46
- #define RUBY_LIBXML_SRC_TYPE_IO 3
47
- #define RUBY_LIBXML_SRC_TYPE_XPATH 4
48
-
49
- typedef struct rx_file_data {
50
- VALUE filename; /* Filename/path to self */
51
- } rx_file_data;
52
-
53
- typedef struct rx_io_data {
54
- VALUE io;
55
- } rx_io_data;
56
-
57
- typedef struct rx_string_data {
58
- VALUE str;
59
- } rx_string_data;
60
-
61
- typedef struct rx_xpath_data {
62
- VALUE ctxt;
63
- } rx_xpath_data;
64
-
65
- #include "ruby_xml_state.h"
66
- #include "ruby_xml_attributes.h"
67
- #include "ruby_xml_attr.h"
68
- #include "ruby_xml_document.h"
69
- #include "ruby_xml_node.h"
70
- #include "ruby_xml_node_set.h"
71
- #include "ruby_xml_ns.h"
72
- #include "ruby_xml_parser.h"
73
- #include "ruby_xml_parser_context.h"
74
- #include "ruby_xml_sax_parser.h"
75
- #include "ruby_xml_xinclude.h"
76
- #include "ruby_xml_xpath.h"
77
- #include "ruby_xml_xpath_context.h"
78
- #include "ruby_xml_xpath_object.h"
79
- #include "ruby_xml_xpointer.h"
80
- #include "ruby_xml_xpointer_context.h"
81
- #include "ruby_xml_input_cbg.h"
82
- #include "ruby_xml_dtd.h"
83
- #include "ruby_xml_schema.h"
84
- #include "ruby_xml_relaxng.h"
85
- #include "ruby_xml_html_parser.h"
86
- #include "ruby_xml_reader.h"
87
-
88
- extern VALUE mLibXML;
89
- extern VALUE mXML;
90
- extern VALUE eXMLError;
91
-
92
- void ruby_init_parser(void);
93
- void ruby_xml_parser_free(ruby_xml_parser *rxp);
94
-
95
- #endif
1
+ /* Please see the LICENSE file for copyright and distribution information */
2
+
3
+ #ifndef __RUBY_LIBXML_H__
4
+ #define __RUBY_LIBXML_H__
5
+
6
+ #include "version.h"
7
+
8
+ #include <ruby.h>
9
+ #include <rubyio.h>
10
+ #include <util.h>
11
+ #include <libxml/parser.h>
12
+ #include <libxml/parserInternals.h>
13
+ #include <libxml/debugXML.h>
14
+ #include <libxml/xmlversion.h>
15
+ #include <libxml/xmlmemory.h>
16
+ #include <libxml/xpath.h>
17
+ #include <libxml/valid.h>
18
+ #include <libxml/catalog.h>
19
+ #include <libxml/HTMLparser.h>
20
+ #include <libxml/xmlreader.h>
21
+
22
+ // Maybe not yet defined in ruby
23
+ #ifndef RSTRING_LEN
24
+ #define RSTRING_LEN(x) RSTRING(x)->len
25
+ #endif
26
+
27
+ // not in Ruby 1.9
28
+ #ifndef GetWriteFile
29
+ #define GetWriteFile(fp) rb_io_stdio_file(fp)
30
+ #define OpenFile rb_io_t
31
+ #endif
32
+
33
+ #ifdef LIBXML_DEBUG_ENABLED
34
+ #include <libxml/xpathInternals.h>
35
+ #endif
36
+ #ifdef LIBXML_XINCLUDE_ENABLED
37
+ #include <libxml/xinclude.h>
38
+ #endif
39
+ #ifdef LIBXML_XPTR_ENABLED
40
+ #include <libxml/xpointer.h>
41
+ #endif
42
+
43
+
44
+ #include "ruby_xml_encoding.h"
45
+ #include "ruby_xml_error.h"
46
+ #include "ruby_xml_input.h"
47
+ #include "ruby_xml_state.h"
48
+ #include "ruby_xml_attributes.h"
49
+ #include "ruby_xml_attr.h"
50
+ #include "ruby_xml_document.h"
51
+ #include "ruby_xml_node.h"
52
+ #include "ruby_xml_ns.h"
53
+ #include "ruby_xml_parser.h"
54
+ #include "ruby_xml_parser_context.h"
55
+ #include "ruby_xml_sax_parser.h"
56
+ #include "ruby_xml_xinclude.h"
57
+ #include "ruby_xml_xpath.h"
58
+ #include "ruby_xml_xpath_context.h"
59
+ #include "ruby_xml_xpath_object.h"
60
+ #include "ruby_xml_xpointer.h"
61
+ #include "ruby_xml_input_cbg.h"
62
+ #include "ruby_xml_dtd.h"
63
+ #include "ruby_xml_schema.h"
64
+ #include "ruby_xml_relaxng.h"
65
+ #include "ruby_xml_html_parser.h"
66
+ #include "ruby_xml_reader.h"
67
+
68
+ extern VALUE mLibXML;
69
+ extern VALUE mXML;
70
+
71
+ #endif
@@ -1,500 +1,500 @@
1
- /* $Id: ruby_xml_attr.c 502 2008-07-22 01:45:31Z cfis $ */
2
-
3
- /* Please see the LICENSE file for copyright and distribution information */
4
-
5
- /*
6
- * Document-class: LibXML::XML::Attr
7
- *
8
- * Provides access to an single element attribute. Accessed by
9
- * calling XML::Node#attributes method.
10
- *
11
- * Basic Usage:
12
- * require 'xml'
13
- *
14
- * doc = XML::Document.new(<some_file>)
15
- * attribute = doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
16
- * attribute.name == 'href'
17
- * attribute.value == 'http://www.mydocument.com'
18
- * attribute.remove!
19
- */
20
-
21
- #include "ruby_libxml.h"
22
- #include "ruby_xml_attr.h"
23
-
24
- VALUE cXMLAttr;
25
-
26
- void ruby_xml_attr_free(xmlAttrPtr xattr) {
27
- if (!xattr) return;
28
-
29
- if (xattr != NULL ) {
30
- xattr->_private=NULL;
31
- if (xattr->parent == NULL && xattr->doc == NULL ) {
32
- #ifdef NODE_DEBUG
33
- fprintf(stderr,"ruby_xfree rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)rxn->node,(long)rxn->node->_private);
34
- #endif
35
- xmlFreeProp(xattr);
36
- }
37
-
38
- xattr=NULL;
39
- }
40
- }
41
-
42
- void
43
- ruby_xml_attr_mark(xmlAttrPtr xattr) {
44
- if (xattr == NULL) return;
45
-
46
- if (xattr->_private == NULL ) {
47
- rb_warning("XmlAttr is not bound! (%s:%d)",
48
- __FILE__,__LINE__);
49
- return;
50
- }
51
-
52
- ruby_xml_node_mark_common((xmlNodePtr)xattr);
53
- }
54
-
55
- VALUE
56
- ruby_xml_attr_wrap(xmlAttrPtr xattr)
57
- {
58
- VALUE result;
59
- // This node is already wrapped
60
- if (xattr->_private != NULL)
61
- return (VALUE)xattr->_private;
62
-
63
- result = Data_Wrap_Struct(cXMLAttr,
64
- ruby_xml_attr_mark, ruby_xml_attr_free,
65
- xattr);
66
-
67
- xattr->_private=(void*)result;
68
- #ifdef NODE_DEBUG
69
- fprintf(stderr,"wrap rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)xnode,(long)obj);
70
- #endif
71
- return result;
72
- }
73
-
74
-
75
- VALUE
76
- ruby_xml_attr_alloc(VALUE klass)
77
- {
78
- return Data_Wrap_Struct(cXMLAttr,
79
- ruby_xml_attr_mark, ruby_xml_attr_free,
80
- NULL);
81
- }
82
-
83
- /*
84
- * call-seq:
85
- * attr.initialize(node, "name", "value")
86
- *
87
- * Creates a new attribute for the node.
88
- *
89
- * node: The XML::Node that will contain the attribute
90
- * name: The name of the attribute
91
- * value: The value of the attribute
92
- *
93
- * attr = XML::Attr.new(doc.root, 'name', 'libxml')
94
- */
95
- VALUE
96
- ruby_xml_attr_initialize(int argc, VALUE *argv, VALUE self) {
97
- VALUE node = argv[0];
98
- VALUE name = argv[1];
99
- VALUE value = argv[2];
100
- VALUE ns = (argc == 4 ? argv[3] : Qnil);
101
-
102
- xmlNodePtr xnode;
103
- xmlAttrPtr xattr;
104
-
105
- if ( argc < 3 || argc > 4 )
106
- rb_raise(rb_eArgError, "wrong number of arguments (3 or 4)");
107
-
108
- Check_Type(name, T_STRING);
109
- Check_Type(value, T_STRING);
110
-
111
- Data_Get_Struct(node, xmlNode, xnode);
112
-
113
- if (xnode->type != XML_ELEMENT_NODE)
114
- rb_raise(rb_eArgError, "Attributes can only be created on element nodes.");
115
-
116
- if NIL_P(ns)
117
- {
118
- xattr = xmlNewProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
119
- }
120
- else
121
- {
122
- xmlNsPtr xns;
123
- Data_Get_Struct(ns, xmlNs, xns);
124
- xattr = xmlNewNsProp(xnode, xns, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
125
- }
126
-
127
- if (!xattr)
128
- rb_raise(rb_eRuntimeError, "Could not create attribute.");
129
-
130
- xattr->_private = (void *)self;
131
- DATA_PTR(self) = xattr;
132
- return self;
133
- }
134
-
135
- /*
136
- * call-seq:
137
- * attr.child -> node
138
- *
139
- * Obtain this attribute's child attribute(s).
140
- */
141
- VALUE
142
- ruby_xml_attr_child_get(VALUE self) {
143
- xmlAttrPtr xattr;
144
- Data_Get_Struct(self, xmlAttr, xattr);
145
- if (xattr->children == NULL)
146
- return(Qnil);
147
- else
148
- return(ruby_xml_node2_wrap(cXMLNode, (xmlNodePtr)xattr->children));
149
- }
150
-
151
-
152
- /*
153
- * call-seq:
154
- * attr.child? -> (true|false)
155
- *
156
- * Determine whether this attribute has child attributes.
157
- */
158
- VALUE
159
- ruby_xml_attr_child_q(VALUE self) {
160
- xmlAttrPtr xattr;
161
- Data_Get_Struct(self, xmlAttr, xattr);
162
- if (xattr->children == NULL)
163
- return(Qfalse);
164
- else
165
- return(Qtrue);
166
- }
167
-
168
-
169
- /*
170
- * call-seq:
171
- * attr.doc -> XML::Document
172
- *
173
- * Returns this attribute's document.
174
- *
175
- * doc.root.attributes.get_attribute('name').doc == doc
176
- */
177
- VALUE
178
- ruby_xml_attr_doc_get(VALUE self) {
179
- xmlAttrPtr xattr;
180
- Data_Get_Struct(self, xmlAttr, xattr);
181
- if (xattr->doc == NULL)
182
- return(Qnil);
183
- else
184
- return(ruby_xml_document_wrap(xattr->doc));
185
- }
186
-
187
- /*
188
- * call-seq:
189
- * attr.doc? -> (true|false)
190
- *
191
- * Determine whether this attribute is associated with an
192
- * XML::Document.
193
- */
194
- VALUE
195
- ruby_xml_attr_doc_q(VALUE self) {
196
- xmlAttrPtr xattr;
197
- Data_Get_Struct(self, xmlAttr, xattr);
198
- if (xattr->doc == NULL)
199
- return(Qfalse);
200
- else
201
- return(Qtrue);
202
- }
203
-
204
-
205
- /*
206
- * call-seq:
207
- * attr.last -> node
208
- *
209
- * Obtain the last attribute.
210
- */
211
- VALUE
212
- ruby_xml_attr_last_get(VALUE self) {
213
- xmlAttrPtr xattr;
214
- Data_Get_Struct(self, xmlAttr, xattr);
215
- if (xattr->last == NULL)
216
- return(Qnil);
217
- else
218
- return(ruby_xml_node2_wrap(cXMLNode, xattr->last));
219
- }
220
-
221
-
222
- /*
223
- * call-seq:
224
- * attr.last? -> (true|false)
225
- *
226
- * Determine whether this is the last attribute.
227
- */
228
- VALUE
229
- ruby_xml_attr_last_q(VALUE self) {
230
- xmlAttrPtr xattr;
231
- Data_Get_Struct(self, xmlAttr, xattr);
232
- if (xattr->last == NULL)
233
- return(Qfalse);
234
- else
235
- return(Qtrue);
236
- }
237
-
238
- /*
239
- * call-seq:
240
- * attr.name -> "name"
241
- *
242
- * Obtain this attribute's name.
243
- */
244
- VALUE
245
- ruby_xml_attr_name_get(VALUE self) {
246
- xmlAttrPtr xattr;
247
- Data_Get_Struct(self, xmlAttr, xattr);
248
-
249
- if (xattr->name == NULL)
250
- return(Qnil);
251
- else
252
- return(rb_str_new2((const char*)xattr->name));
253
- }
254
-
255
- /*
256
- * call-seq:
257
- * attr.next -> node
258
- *
259
- * Obtain the next attribute.
260
- */
261
- VALUE
262
- ruby_xml_attr_next_get(VALUE self) {
263
- xmlAttrPtr xattr;
264
- Data_Get_Struct(self, xmlAttr, xattr);
265
- if (xattr->next == NULL)
266
- return(Qnil);
267
- else
268
- return(ruby_xml_attr_wrap(xattr->next));
269
- }
270
-
271
-
272
- /*
273
- * call-seq:
274
- * attr.next? -> (true|false)
275
- *
276
- * Determine whether there is a next attribute.
277
- */
278
- VALUE
279
- ruby_xml_attr_next_q(VALUE self) {
280
- xmlAttrPtr xattr;
281
- Data_Get_Struct(self, xmlAttr, xattr);
282
- if (xattr->next == NULL)
283
- return(Qfalse);
284
- else
285
- return(Qtrue);
286
- }
287
-
288
-
289
- /*
290
- * call-seq:
291
- * attr.type_name -> "attribute"
292
- *
293
- * Obtain this attribute node's type name.
294
- */
295
- VALUE
296
- ruby_xml_attr_node_type_name(VALUE self) {
297
- return(rb_str_new2("attribute"));
298
- }
299
-
300
-
301
- /*
302
- * call-seq:
303
- * attr.ns -> namespace
304
- *
305
- * Obtain this attribute's associated XML::NS, if any.
306
- */
307
- VALUE
308
- ruby_xml_attr_ns_get(VALUE self) {
309
- xmlAttrPtr xattr;
310
- Data_Get_Struct(self, xmlAttr, xattr);
311
- if (xattr->ns == NULL)
312
- return(Qnil);
313
- else
314
- return(ruby_xml_ns_wrap(xattr->ns));
315
- }
316
-
317
-
318
- /*
319
- * call-seq:
320
- * attr.ns? -> (true|false)
321
- *
322
- * Determine whether this attribute has an associated
323
- * namespace.
324
- */
325
- VALUE
326
- ruby_xml_attr_ns_q(VALUE self) {
327
- xmlAttrPtr xattr;
328
- Data_Get_Struct(self, xmlAttr, xattr);
329
- if (xattr->ns == NULL)
330
- return(Qfalse);
331
- else
332
- return(Qtrue);
333
- }
334
-
335
-
336
- /*
337
- * call-seq:
338
- * attr.parent -> node
339
- *
340
- * Obtain this attribute node's parent.
341
- */
342
- VALUE
343
- ruby_xml_attr_parent_get(VALUE self) {
344
- xmlAttrPtr xattr;
345
- Data_Get_Struct(self, xmlAttr, xattr);
346
- if (xattr->parent == NULL)
347
- return(Qnil);
348
- else
349
- return(ruby_xml_node2_wrap(cXMLNode, xattr->parent));
350
- }
351
-
352
-
353
- /*
354
- * call-seq:
355
- * attr.parent? -> (true|false)
356
- *
357
- * Determine whether this attribute has a parent.
358
- */
359
- VALUE
360
- ruby_xml_attr_parent_q(VALUE self) {
361
- xmlAttrPtr xattr;
362
- Data_Get_Struct(self, xmlAttr, xattr);
363
- if (xattr->parent == NULL)
364
- return(Qfalse);
365
- else
366
- return(Qtrue);
367
- }
368
-
369
-
370
- /*
371
- * call-seq:
372
- * attr.prev -> node
373
- *
374
- * Obtain the previous attribute.
375
- */
376
- VALUE
377
- ruby_xml_attr_prev_get(VALUE self) {
378
- xmlAttrPtr xattr;
379
- Data_Get_Struct(self, xmlAttr, xattr);
380
- if (xattr->prev == NULL)
381
- return(Qnil);
382
- else
383
- return(ruby_xml_attr_wrap(xattr->prev));
384
- }
385
-
386
-
387
- /*
388
- * call-seq:
389
- * attr.prev? -> (true|false)
390
- *
391
- * Determine whether there is a previous attribute.
392
- */
393
- VALUE
394
- ruby_xml_attr_prev_q(VALUE self) {
395
- xmlAttrPtr xattr;
396
- Data_Get_Struct(self, xmlAttr, xattr);
397
- if (xattr->prev == NULL)
398
- return(Qfalse);
399
- else
400
- return(Qtrue);
401
- }
402
-
403
-
404
- /*
405
- * call-seq:
406
- * node.remove! -> nil
407
- *
408
- * Removes this attribute from it's parent.
409
- */
410
- VALUE
411
- ruby_xml_attr_remove_ex(VALUE self) {
412
- xmlAttrPtr xattr;
413
- Data_Get_Struct(self, xmlAttr, xattr);
414
-
415
- if (xattr->_private == NULL)
416
- xmlRemoveProp(xattr);
417
- else
418
- xmlUnlinkNode((xmlNodePtr)xattr);
419
-
420
- return(Qnil);
421
- }
422
-
423
- /*
424
- * call-seq:
425
- * attr.value -> "value"
426
- *
427
- * Obtain the value of this attribute.
428
- */
429
- VALUE
430
- ruby_xml_attr_value_get(VALUE self) {
431
- xmlAttrPtr xattr;
432
- xmlChar *value;
433
- VALUE result = Qnil;
434
-
435
- Data_Get_Struct(self, xmlAttr, xattr);
436
- if (ruby_xml_attr_parent_q(self) == Qtrue) {
437
- value = xmlGetProp(xattr->parent, xattr->name);
438
- if (value != NULL)
439
- {
440
- result = rb_str_new2((const char*)value);
441
- xmlFree(value);
442
- }
443
- }
444
- return(result);
445
- }
446
-
447
-
448
- /*
449
- * call-seq:
450
- * attr.value = "value"
451
- *
452
- * Sets the value of this attribute.
453
- */
454
- VALUE
455
- ruby_xml_attr_value_set(VALUE self, VALUE val) {
456
- xmlAttrPtr xattr;
457
-
458
- Check_Type(val, T_STRING);
459
- Data_Get_Struct(self, xmlAttr, xattr);
460
-
461
- if (xattr->ns)
462
- xmlSetNsProp(xattr->parent, xattr->ns, xattr->name, (xmlChar*)StringValuePtr(val));
463
- else
464
- xmlSetProp(xattr->parent, xattr->name, (xmlChar*)StringValuePtr(val));
465
-
466
- return(self);
467
- }
468
-
469
-
470
- // Rdoc needs to know
471
- #ifdef RDOC_NEVER_DEFINED
472
- mLibXML = rb_define_module("LibXML");
473
- mXML = rb_define_module_under(mLibXML, "XML");
474
- #endif
475
-
476
- void
477
- ruby_init_xml_attr(void) {
478
- cXMLAttr = rb_define_class_under(mXML, "Attr", rb_cObject);
479
- rb_define_alloc_func(cXMLAttr, ruby_xml_attr_alloc);
480
- rb_define_method(cXMLAttr, "initialize", ruby_xml_attr_initialize, -1);
481
- rb_define_method(cXMLAttr, "child", ruby_xml_attr_child_get, 0);
482
- rb_define_method(cXMLAttr, "child?", ruby_xml_attr_child_q, 0);
483
- rb_define_method(cXMLAttr, "doc", ruby_xml_attr_doc_get, 0);
484
- rb_define_method(cXMLAttr, "doc?", ruby_xml_attr_doc_q, 0);
485
- rb_define_method(cXMLAttr, "last", ruby_xml_attr_last_get, 0);
486
- rb_define_method(cXMLAttr, "last?", ruby_xml_attr_last_q, 0);
487
- rb_define_method(cXMLAttr, "name", ruby_xml_attr_name_get, 0);
488
- rb_define_method(cXMLAttr, "next", ruby_xml_attr_next_get, 0);
489
- rb_define_method(cXMLAttr, "next?", ruby_xml_attr_next_q, 0);
490
- rb_define_method(cXMLAttr, "node_type_name", ruby_xml_attr_node_type_name, 0);
491
- rb_define_method(cXMLAttr, "ns", ruby_xml_attr_ns_get, 0);
492
- rb_define_method(cXMLAttr, "ns?", ruby_xml_attr_ns_q, 0);
493
- rb_define_method(cXMLAttr, "parent", ruby_xml_attr_parent_get, 0);
494
- rb_define_method(cXMLAttr, "parent?", ruby_xml_attr_parent_q, 0);
495
- rb_define_method(cXMLAttr, "prev", ruby_xml_attr_prev_get, 0);
496
- rb_define_method(cXMLAttr, "prev?", ruby_xml_attr_prev_q, 0);
497
- rb_define_method(cXMLAttr, "remove!", ruby_xml_attr_remove_ex, 0);
498
- rb_define_method(cXMLAttr, "value", ruby_xml_attr_value_get, 0);
499
- rb_define_method(cXMLAttr, "value=", ruby_xml_attr_value_set, 1);
500
- }
1
+ /* $Id: ruby_xml_attr.c 553 2008-11-18 02:34:38Z cfis $ */
2
+
3
+ /* Please see the LICENSE file for copyright and distribution information */
4
+
5
+ /*
6
+ * Document-class: LibXML::XML::Attr
7
+ *
8
+ * Provides access to an single element attribute.
9
+ *
10
+ * Basic Usage:
11
+ *
12
+ * require 'xml'
13
+ *
14
+ * doc = XML::Document.new(<some_file>)
15
+ * attribute = doc.root.attributes.get_attribute_ns('http://www.w3.org/1999/xlink', 'href')
16
+ * attribute.name == 'href'
17
+ * attribute.value == 'http://www.mydocument.com'
18
+ * attribute.remove!
19
+ */
20
+
21
+ #include "ruby_libxml.h"
22
+ #include "ruby_xml_attr.h"
23
+
24
+ VALUE cXMLAttr;
25
+
26
+ void ruby_xml_attr_free(xmlAttrPtr xattr) {
27
+ if (!xattr) return;
28
+
29
+ if (xattr != NULL ) {
30
+ xattr->_private=NULL;
31
+ if (xattr->parent == NULL && xattr->doc == NULL ) {
32
+ #ifdef NODE_DEBUG
33
+ fprintf(stderr,"ruby_xfree rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)rxn->node,(long)rxn->node->_private);
34
+ #endif
35
+ xmlFreeProp(xattr);
36
+ }
37
+
38
+ xattr=NULL;
39
+ }
40
+ }
41
+
42
+ void
43
+ ruby_xml_attr_mark(xmlAttrPtr xattr) {
44
+ if (xattr == NULL) return;
45
+
46
+ if (xattr->_private == NULL ) {
47
+ rb_warning("XmlAttr is not bound! (%s:%d)",
48
+ __FILE__,__LINE__);
49
+ return;
50
+ }
51
+
52
+ ruby_xml_node_mark_common((xmlNodePtr)xattr);
53
+ }
54
+
55
+ VALUE
56
+ ruby_xml_attr_wrap(xmlAttrPtr xattr)
57
+ {
58
+ VALUE result;
59
+ // This node is already wrapped
60
+ if (xattr->_private != NULL)
61
+ return (VALUE)xattr->_private;
62
+
63
+ result = Data_Wrap_Struct(cXMLAttr,
64
+ ruby_xml_attr_mark, ruby_xml_attr_free,
65
+ xattr);
66
+
67
+ xattr->_private=(void*)result;
68
+ #ifdef NODE_DEBUG
69
+ fprintf(stderr,"wrap rxn=0x%x xn=0x%x o=0x%x\n",(long)rxn,(long)xnode,(long)obj);
70
+ #endif
71
+ return result;
72
+ }
73
+
74
+
75
+ VALUE
76
+ ruby_xml_attr_alloc(VALUE klass)
77
+ {
78
+ return Data_Wrap_Struct(cXMLAttr,
79
+ ruby_xml_attr_mark, ruby_xml_attr_free,
80
+ NULL);
81
+ }
82
+
83
+ /*
84
+ * call-seq:
85
+ * attr.initialize(node, "name", "value")
86
+ *
87
+ * Creates a new attribute for the node.
88
+ *
89
+ * node: The XML::Node that will contain the attribute
90
+ * name: The name of the attribute
91
+ * value: The value of the attribute
92
+ *
93
+ * attr = XML::Attr.new(doc.root, 'name', 'libxml')
94
+ */
95
+ VALUE
96
+ ruby_xml_attr_initialize(int argc, VALUE *argv, VALUE self) {
97
+ VALUE node = argv[0];
98
+ VALUE name = argv[1];
99
+ VALUE value = argv[2];
100
+ VALUE ns = (argc == 4 ? argv[3] : Qnil);
101
+
102
+ xmlNodePtr xnode;
103
+ xmlAttrPtr xattr;
104
+
105
+ if ( argc < 3 || argc > 4 )
106
+ rb_raise(rb_eArgError, "Wrong number of arguments (3 or 4)");
107
+
108
+ Check_Type(name, T_STRING);
109
+ Check_Type(value, T_STRING);
110
+
111
+ Data_Get_Struct(node, xmlNode, xnode);
112
+
113
+ if (xnode->type != XML_ELEMENT_NODE)
114
+ rb_raise(rb_eArgError, "Attributes can only be created on element nodes.");
115
+
116
+ if NIL_P(ns)
117
+ {
118
+ xattr = xmlNewProp(xnode, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
119
+ }
120
+ else
121
+ {
122
+ xmlNsPtr xns;
123
+ Data_Get_Struct(ns, xmlNs, xns);
124
+ xattr = xmlNewNsProp(xnode, xns, (xmlChar*)StringValuePtr(name), (xmlChar*)StringValuePtr(value));
125
+ }
126
+
127
+ if (!xattr)
128
+ rb_raise(rb_eRuntimeError, "Could not create attribute.");
129
+
130
+ xattr->_private = (void *)self;
131
+ DATA_PTR(self) = xattr;
132
+ return self;
133
+ }
134
+
135
+ /*
136
+ * call-seq:
137
+ * attr.child -> node
138
+ *
139
+ * Obtain this attribute's child attribute(s).
140
+ */
141
+ VALUE
142
+ ruby_xml_attr_child_get(VALUE self) {
143
+ xmlAttrPtr xattr;
144
+ Data_Get_Struct(self, xmlAttr, xattr);
145
+ if (xattr->children == NULL)
146
+ return(Qnil);
147
+ else
148
+ return(ruby_xml_node2_wrap(cXMLNode, (xmlNodePtr)xattr->children));
149
+ }
150
+
151
+
152
+ /*
153
+ * call-seq:
154
+ * attr.child? -> (true|false)
155
+ *
156
+ * Returns whether this attribute has child attributes.
157
+ */
158
+ VALUE
159
+ ruby_xml_attr_child_q(VALUE self) {
160
+ xmlAttrPtr xattr;
161
+ Data_Get_Struct(self, xmlAttr, xattr);
162
+ if (xattr->children == NULL)
163
+ return(Qfalse);
164
+ else
165
+ return(Qtrue);
166
+ }
167
+
168
+
169
+ /*
170
+ * call-seq:
171
+ * attr.doc -> XML::Document
172
+ *
173
+ * Returns this attribute's document.
174
+ *
175
+ * doc.root.attributes.get_attribute('name').doc == doc
176
+ */
177
+ VALUE
178
+ ruby_xml_attr_doc_get(VALUE self) {
179
+ xmlAttrPtr xattr;
180
+ Data_Get_Struct(self, xmlAttr, xattr);
181
+ if (xattr->doc == NULL)
182
+ return(Qnil);
183
+ else
184
+ return(ruby_xml_document_wrap(xattr->doc));
185
+ }
186
+
187
+ /*
188
+ * call-seq:
189
+ * attr.doc? -> (true|false)
190
+ *
191
+ * Determine whether this attribute is associated with an
192
+ * XML::Document.
193
+ */
194
+ VALUE
195
+ ruby_xml_attr_doc_q(VALUE self) {
196
+ xmlAttrPtr xattr;
197
+ Data_Get_Struct(self, xmlAttr, xattr);
198
+ if (xattr->doc == NULL)
199
+ return(Qfalse);
200
+ else
201
+ return(Qtrue);
202
+ }
203
+
204
+
205
+ /*
206
+ * call-seq:
207
+ * attr.last -> node
208
+ *
209
+ * Obtain the last attribute.
210
+ */
211
+ VALUE
212
+ ruby_xml_attr_last_get(VALUE self) {
213
+ xmlAttrPtr xattr;
214
+ Data_Get_Struct(self, xmlAttr, xattr);
215
+ if (xattr->last == NULL)
216
+ return(Qnil);
217
+ else
218
+ return(ruby_xml_node2_wrap(cXMLNode, xattr->last));
219
+ }
220
+
221
+
222
+ /*
223
+ * call-seq:
224
+ * attr.last? -> (true|false)
225
+ *
226
+ * Determine whether this is the last attribute.
227
+ */
228
+ VALUE
229
+ ruby_xml_attr_last_q(VALUE self) {
230
+ xmlAttrPtr xattr;
231
+ Data_Get_Struct(self, xmlAttr, xattr);
232
+ if (xattr->last == NULL)
233
+ return(Qfalse);
234
+ else
235
+ return(Qtrue);
236
+ }
237
+
238
+ /*
239
+ * call-seq:
240
+ * attr.name -> "name"
241
+ *
242
+ * Obtain this attribute's name.
243
+ */
244
+ VALUE
245
+ ruby_xml_attr_name_get(VALUE self) {
246
+ xmlAttrPtr xattr;
247
+ Data_Get_Struct(self, xmlAttr, xattr);
248
+
249
+ if (xattr->name == NULL)
250
+ return(Qnil);
251
+ else
252
+ return(rb_str_new2((const char*)xattr->name));
253
+ }
254
+
255
+ /*
256
+ * call-seq:
257
+ * attr.next -> node
258
+ *
259
+ * Obtain the next attribute.
260
+ */
261
+ VALUE
262
+ ruby_xml_attr_next_get(VALUE self) {
263
+ xmlAttrPtr xattr;
264
+ Data_Get_Struct(self, xmlAttr, xattr);
265
+ if (xattr->next == NULL)
266
+ return(Qnil);
267
+ else
268
+ return(ruby_xml_attr_wrap(xattr->next));
269
+ }
270
+
271
+
272
+ /*
273
+ * call-seq:
274
+ * attr.next? -> (true|false)
275
+ *
276
+ * Determine whether there is a next attribute.
277
+ */
278
+ VALUE
279
+ ruby_xml_attr_next_q(VALUE self) {
280
+ xmlAttrPtr xattr;
281
+ Data_Get_Struct(self, xmlAttr, xattr);
282
+ if (xattr->next == NULL)
283
+ return(Qfalse);
284
+ else
285
+ return(Qtrue);
286
+ }
287
+
288
+
289
+ /*
290
+ * call-seq:
291
+ * attr.type_name -> "attribute"
292
+ *
293
+ * Obtain this attribute node's type name.
294
+ */
295
+ VALUE
296
+ ruby_xml_attr_node_type_name(VALUE self) {
297
+ return(rb_str_new2("attribute"));
298
+ }
299
+
300
+
301
+ /*
302
+ * call-seq:
303
+ * attr.ns -> namespace
304
+ *
305
+ * Obtain this attribute's associated XML::NS, if any.
306
+ */
307
+ VALUE
308
+ ruby_xml_attr_ns_get(VALUE self) {
309
+ xmlAttrPtr xattr;
310
+ Data_Get_Struct(self, xmlAttr, xattr);
311
+ if (xattr->ns == NULL)
312
+ return(Qnil);
313
+ else
314
+ return(ruby_xml_ns_wrap(xattr->ns));
315
+ }
316
+
317
+
318
+ /*
319
+ * call-seq:
320
+ * attr.ns? -> (true|false)
321
+ *
322
+ * Determine whether this attribute has an associated
323
+ * namespace.
324
+ */
325
+ VALUE
326
+ ruby_xml_attr_ns_q(VALUE self) {
327
+ xmlAttrPtr xattr;
328
+ Data_Get_Struct(self, xmlAttr, xattr);
329
+ if (xattr->ns == NULL)
330
+ return(Qfalse);
331
+ else
332
+ return(Qtrue);
333
+ }
334
+
335
+
336
+ /*
337
+ * call-seq:
338
+ * attr.parent -> node
339
+ *
340
+ * Obtain this attribute node's parent.
341
+ */
342
+ VALUE
343
+ ruby_xml_attr_parent_get(VALUE self) {
344
+ xmlAttrPtr xattr;
345
+ Data_Get_Struct(self, xmlAttr, xattr);
346
+ if (xattr->parent == NULL)
347
+ return(Qnil);
348
+ else
349
+ return(ruby_xml_node2_wrap(cXMLNode, xattr->parent));
350
+ }
351
+
352
+
353
+ /*
354
+ * call-seq:
355
+ * attr.parent? -> (true|false)
356
+ *
357
+ * Determine whether this attribute has a parent.
358
+ */
359
+ VALUE
360
+ ruby_xml_attr_parent_q(VALUE self) {
361
+ xmlAttrPtr xattr;
362
+ Data_Get_Struct(self, xmlAttr, xattr);
363
+ if (xattr->parent == NULL)
364
+ return(Qfalse);
365
+ else
366
+ return(Qtrue);
367
+ }
368
+
369
+
370
+ /*
371
+ * call-seq:
372
+ * attr.prev -> node
373
+ *
374
+ * Obtain the previous attribute.
375
+ */
376
+ VALUE
377
+ ruby_xml_attr_prev_get(VALUE self) {
378
+ xmlAttrPtr xattr;
379
+ Data_Get_Struct(self, xmlAttr, xattr);
380
+ if (xattr->prev == NULL)
381
+ return(Qnil);
382
+ else
383
+ return(ruby_xml_attr_wrap(xattr->prev));
384
+ }
385
+
386
+
387
+ /*
388
+ * call-seq:
389
+ * attr.prev? -> (true|false)
390
+ *
391
+ * Determine whether there is a previous attribute.
392
+ */
393
+ VALUE
394
+ ruby_xml_attr_prev_q(VALUE self) {
395
+ xmlAttrPtr xattr;
396
+ Data_Get_Struct(self, xmlAttr, xattr);
397
+ if (xattr->prev == NULL)
398
+ return(Qfalse);
399
+ else
400
+ return(Qtrue);
401
+ }
402
+
403
+
404
+ /*
405
+ * call-seq:
406
+ * node.remove! -> nil
407
+ *
408
+ * Removes this attribute from it's parent.
409
+ */
410
+ VALUE
411
+ ruby_xml_attr_remove_ex(VALUE self) {
412
+ xmlAttrPtr xattr;
413
+ Data_Get_Struct(self, xmlAttr, xattr);
414
+
415
+ if (xattr->_private == NULL)
416
+ xmlRemoveProp(xattr);
417
+ else
418
+ xmlUnlinkNode((xmlNodePtr)xattr);
419
+
420
+ return(Qnil);
421
+ }
422
+
423
+ /*
424
+ * call-seq:
425
+ * attr.value -> "value"
426
+ *
427
+ * Obtain the value of this attribute.
428
+ */
429
+ VALUE
430
+ ruby_xml_attr_value_get(VALUE self) {
431
+ xmlAttrPtr xattr;
432
+ xmlChar *value;
433
+ VALUE result = Qnil;
434
+
435
+ Data_Get_Struct(self, xmlAttr, xattr);
436
+ if (ruby_xml_attr_parent_q(self) == Qtrue) {
437
+ value = xmlGetProp(xattr->parent, xattr->name);
438
+ if (value != NULL)
439
+ {
440
+ result = rb_str_new2((const char*)value);
441
+ xmlFree(value);
442
+ }
443
+ }
444
+ return(result);
445
+ }
446
+
447
+
448
+ /*
449
+ * call-seq:
450
+ * attr.value = "value"
451
+ *
452
+ * Sets the value of this attribute.
453
+ */
454
+ VALUE
455
+ ruby_xml_attr_value_set(VALUE self, VALUE val) {
456
+ xmlAttrPtr xattr;
457
+
458
+ Check_Type(val, T_STRING);
459
+ Data_Get_Struct(self, xmlAttr, xattr);
460
+
461
+ if (xattr->ns)
462
+ xmlSetNsProp(xattr->parent, xattr->ns, xattr->name, (xmlChar*)StringValuePtr(val));
463
+ else
464
+ xmlSetProp(xattr->parent, xattr->name, (xmlChar*)StringValuePtr(val));
465
+
466
+ return(self);
467
+ }
468
+
469
+
470
+ // Rdoc needs to know
471
+ #ifdef RDOC_NEVER_DEFINED
472
+ mLibXML = rb_define_module("LibXML");
473
+ mXML = rb_define_module_under(mLibXML, "XML");
474
+ #endif
475
+
476
+ void
477
+ ruby_init_xml_attr(void) {
478
+ cXMLAttr = rb_define_class_under(mXML, "Attr", rb_cObject);
479
+ rb_define_alloc_func(cXMLAttr, ruby_xml_attr_alloc);
480
+ rb_define_method(cXMLAttr, "initialize", ruby_xml_attr_initialize, -1);
481
+ rb_define_method(cXMLAttr, "child", ruby_xml_attr_child_get, 0);
482
+ rb_define_method(cXMLAttr, "child?", ruby_xml_attr_child_q, 0);
483
+ rb_define_method(cXMLAttr, "doc", ruby_xml_attr_doc_get, 0);
484
+ rb_define_method(cXMLAttr, "doc?", ruby_xml_attr_doc_q, 0);
485
+ rb_define_method(cXMLAttr, "last", ruby_xml_attr_last_get, 0);
486
+ rb_define_method(cXMLAttr, "last?", ruby_xml_attr_last_q, 0);
487
+ rb_define_method(cXMLAttr, "name", ruby_xml_attr_name_get, 0);
488
+ rb_define_method(cXMLAttr, "next", ruby_xml_attr_next_get, 0);
489
+ rb_define_method(cXMLAttr, "next?", ruby_xml_attr_next_q, 0);
490
+ rb_define_method(cXMLAttr, "node_type_name", ruby_xml_attr_node_type_name, 0);
491
+ rb_define_method(cXMLAttr, "ns", ruby_xml_attr_ns_get, 0);
492
+ rb_define_method(cXMLAttr, "ns?", ruby_xml_attr_ns_q, 0);
493
+ rb_define_method(cXMLAttr, "parent", ruby_xml_attr_parent_get, 0);
494
+ rb_define_method(cXMLAttr, "parent?", ruby_xml_attr_parent_q, 0);
495
+ rb_define_method(cXMLAttr, "prev", ruby_xml_attr_prev_get, 0);
496
+ rb_define_method(cXMLAttr, "prev?", ruby_xml_attr_prev_q, 0);
497
+ rb_define_method(cXMLAttr, "remove!", ruby_xml_attr_remove_ex, 0);
498
+ rb_define_method(cXMLAttr, "value", ruby_xml_attr_value_get, 0);
499
+ rb_define_method(cXMLAttr, "value=", ruby_xml_attr_value_set, 1);
500
+ }