nokogiri 1.11.0.rc3-java → 1.11.4-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of nokogiri might be problematic. Click here for more details.

Files changed (187) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/LICENSE-DEPENDENCIES.md +1015 -947
  4. data/LICENSE.md +1 -1
  5. data/README.md +168 -91
  6. data/dependencies.yml +12 -12
  7. data/ext/java/nokogiri/EncodingHandler.java +76 -89
  8. data/ext/java/nokogiri/HtmlDocument.java +135 -144
  9. data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
  10. data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
  11. data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
  12. data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
  13. data/ext/java/nokogiri/NokogiriService.java +595 -556
  14. data/ext/java/nokogiri/XmlAttr.java +118 -126
  15. data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
  16. data/ext/java/nokogiri/XmlCdata.java +35 -58
  17. data/ext/java/nokogiri/XmlComment.java +46 -67
  18. data/ext/java/nokogiri/XmlDocument.java +645 -572
  19. data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
  20. data/ext/java/nokogiri/XmlDtd.java +448 -414
  21. data/ext/java/nokogiri/XmlElement.java +23 -48
  22. data/ext/java/nokogiri/XmlElementContent.java +343 -316
  23. data/ext/java/nokogiri/XmlElementDecl.java +124 -125
  24. data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
  25. data/ext/java/nokogiri/XmlEntityReference.java +49 -72
  26. data/ext/java/nokogiri/XmlNamespace.java +175 -175
  27. data/ext/java/nokogiri/XmlNode.java +1843 -1622
  28. data/ext/java/nokogiri/XmlNodeSet.java +361 -331
  29. data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
  30. data/ext/java/nokogiri/XmlReader.java +513 -450
  31. data/ext/java/nokogiri/XmlRelaxng.java +89 -101
  32. data/ext/java/nokogiri/XmlSaxParserContext.java +328 -310
  33. data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
  34. data/ext/java/nokogiri/XmlSchema.java +335 -242
  35. data/ext/java/nokogiri/XmlSyntaxError.java +113 -119
  36. data/ext/java/nokogiri/XmlText.java +55 -76
  37. data/ext/java/nokogiri/XmlXpathContext.java +242 -210
  38. data/ext/java/nokogiri/XsltStylesheet.java +280 -269
  39. data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
  40. data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -190
  41. data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
  42. data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
  43. data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
  44. data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
  45. data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
  46. data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
  47. data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
  48. data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
  49. data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +79 -89
  50. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
  51. data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
  52. data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
  53. data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +119 -78
  54. data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -54
  55. data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
  56. data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
  57. data/ext/java/nokogiri/internals/ParserContext.java +206 -211
  58. data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
  59. data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
  60. data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
  61. data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
  62. data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
  63. data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
  64. data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
  65. data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
  66. data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
  67. data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
  68. data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
  69. data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
  70. data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
  71. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
  72. data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
  73. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
  74. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
  75. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
  76. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
  77. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
  78. data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
  79. data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
  80. data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
  81. data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
  82. data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
  83. data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
  84. data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
  85. data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
  86. data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
  87. data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
  88. data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
  89. data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
  90. data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
  91. data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
  92. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
  93. data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
  94. data/ext/nokogiri/depend +37 -358
  95. data/ext/nokogiri/extconf.rb +581 -374
  96. data/ext/nokogiri/html_document.c +78 -82
  97. data/ext/nokogiri/html_element_description.c +84 -71
  98. data/ext/nokogiri/html_entity_lookup.c +21 -16
  99. data/ext/nokogiri/html_sax_parser_context.c +69 -66
  100. data/ext/nokogiri/html_sax_push_parser.c +42 -34
  101. data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
  102. data/ext/nokogiri/nokogiri.c +192 -93
  103. data/ext/nokogiri/test_global_handlers.c +40 -0
  104. data/ext/nokogiri/xml_attr.c +15 -15
  105. data/ext/nokogiri/xml_attribute_decl.c +18 -18
  106. data/ext/nokogiri/xml_cdata.c +13 -18
  107. data/ext/nokogiri/xml_comment.c +19 -26
  108. data/ext/nokogiri/xml_document.c +246 -188
  109. data/ext/nokogiri/xml_document_fragment.c +13 -15
  110. data/ext/nokogiri/xml_dtd.c +54 -48
  111. data/ext/nokogiri/xml_element_content.c +30 -27
  112. data/ext/nokogiri/xml_element_decl.c +22 -22
  113. data/ext/nokogiri/xml_encoding_handler.c +17 -11
  114. data/ext/nokogiri/xml_entity_decl.c +32 -30
  115. data/ext/nokogiri/xml_entity_reference.c +16 -18
  116. data/ext/nokogiri/xml_namespace.c +56 -49
  117. data/ext/nokogiri/xml_node.c +371 -320
  118. data/ext/nokogiri/xml_node_set.c +168 -156
  119. data/ext/nokogiri/xml_processing_instruction.c +17 -19
  120. data/ext/nokogiri/xml_reader.c +191 -157
  121. data/ext/nokogiri/xml_relax_ng.c +52 -28
  122. data/ext/nokogiri/xml_sax_parser.c +118 -118
  123. data/ext/nokogiri/xml_sax_parser_context.c +103 -86
  124. data/ext/nokogiri/xml_sax_push_parser.c +36 -27
  125. data/ext/nokogiri/xml_schema.c +95 -47
  126. data/ext/nokogiri/xml_syntax_error.c +42 -21
  127. data/ext/nokogiri/xml_text.c +13 -17
  128. data/ext/nokogiri/xml_xpath_context.c +206 -123
  129. data/ext/nokogiri/xslt_stylesheet.c +158 -161
  130. data/lib/nokogiri.rb +3 -7
  131. data/lib/nokogiri/css/parser.rb +3 -3
  132. data/lib/nokogiri/css/parser.y +2 -2
  133. data/lib/nokogiri/css/xpath_visitor.rb +70 -42
  134. data/lib/nokogiri/extension.rb +26 -0
  135. data/lib/nokogiri/html/document.rb +12 -26
  136. data/lib/nokogiri/html/document_fragment.rb +15 -15
  137. data/lib/nokogiri/nokogiri.jar +0 -0
  138. data/lib/nokogiri/version.rb +2 -149
  139. data/lib/nokogiri/version/constant.rb +5 -0
  140. data/lib/nokogiri/version/info.rb +205 -0
  141. data/lib/nokogiri/xml/document.rb +91 -35
  142. data/lib/nokogiri/xml/document_fragment.rb +4 -6
  143. data/lib/nokogiri/xml/node.rb +89 -69
  144. data/lib/nokogiri/xml/parse_options.rb +6 -0
  145. data/lib/nokogiri/xml/reader.rb +2 -9
  146. data/lib/nokogiri/xml/relax_ng.rb +6 -2
  147. data/lib/nokogiri/xml/schema.rb +12 -4
  148. data/lib/nokogiri/xml/searchable.rb +3 -1
  149. data/lib/nokogiri/xml/xpath.rb +1 -3
  150. data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
  151. metadata +86 -177
  152. data/ext/nokogiri/html_document.h +0 -10
  153. data/ext/nokogiri/html_element_description.h +0 -10
  154. data/ext/nokogiri/html_entity_lookup.h +0 -8
  155. data/ext/nokogiri/html_sax_parser_context.h +0 -11
  156. data/ext/nokogiri/html_sax_push_parser.h +0 -9
  157. data/ext/nokogiri/nokogiri.h +0 -134
  158. data/ext/nokogiri/xml_attr.h +0 -9
  159. data/ext/nokogiri/xml_attribute_decl.h +0 -9
  160. data/ext/nokogiri/xml_cdata.h +0 -9
  161. data/ext/nokogiri/xml_comment.h +0 -9
  162. data/ext/nokogiri/xml_document.h +0 -23
  163. data/ext/nokogiri/xml_document_fragment.h +0 -10
  164. data/ext/nokogiri/xml_dtd.h +0 -10
  165. data/ext/nokogiri/xml_element_content.h +0 -10
  166. data/ext/nokogiri/xml_element_decl.h +0 -9
  167. data/ext/nokogiri/xml_encoding_handler.h +0 -8
  168. data/ext/nokogiri/xml_entity_decl.h +0 -10
  169. data/ext/nokogiri/xml_entity_reference.h +0 -9
  170. data/ext/nokogiri/xml_io.c +0 -63
  171. data/ext/nokogiri/xml_io.h +0 -11
  172. data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
  173. data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
  174. data/ext/nokogiri/xml_namespace.h +0 -14
  175. data/ext/nokogiri/xml_node.h +0 -13
  176. data/ext/nokogiri/xml_node_set.h +0 -12
  177. data/ext/nokogiri/xml_processing_instruction.h +0 -9
  178. data/ext/nokogiri/xml_reader.h +0 -10
  179. data/ext/nokogiri/xml_relax_ng.h +0 -9
  180. data/ext/nokogiri/xml_sax_parser.h +0 -39
  181. data/ext/nokogiri/xml_sax_parser_context.h +0 -10
  182. data/ext/nokogiri/xml_sax_push_parser.h +0 -9
  183. data/ext/nokogiri/xml_schema.h +0 -9
  184. data/ext/nokogiri/xml_syntax_error.h +0 -13
  185. data/ext/nokogiri/xml_text.h +0 -9
  186. data/ext/nokogiri/xml_xpath_context.h +0 -10
  187. data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -1,17 +1,19 @@
1
- #include <xml_encoding_handler.h>
1
+ #include <nokogiri.h>
2
2
 
3
3
  /*
4
4
  * call-seq: Nokogiri::EncodingHandler.[](name)
5
5
  *
6
6
  * Get the encoding handler for +name+
7
7
  */
8
- static VALUE get(VALUE klass, VALUE key)
8
+ static VALUE
9
+ get(VALUE klass, VALUE key)
9
10
  {
10
11
  xmlCharEncodingHandlerPtr handler;
11
12
 
12
13
  handler = xmlFindCharEncodingHandler(StringValueCStr(key));
13
- if(handler)
14
+ if (handler) {
14
15
  return Data_Wrap_Struct(klass, NULL, NULL, handler);
16
+ }
15
17
 
16
18
  return Qnil;
17
19
  }
@@ -21,9 +23,10 @@ static VALUE get(VALUE klass, VALUE key)
21
23
  *
22
24
  * Delete the encoding alias named +name+
23
25
  */
24
- static VALUE delete(VALUE klass, VALUE name)
26
+ static VALUE
27
+ delete (VALUE klass, VALUE name)
25
28
  {
26
- if(xmlDelEncodingAlias(StringValueCStr(name))) return Qnil;
29
+ if (xmlDelEncodingAlias(StringValueCStr(name))) { return Qnil; }
27
30
 
28
31
  return Qtrue;
29
32
  }
@@ -33,7 +36,8 @@ static VALUE delete(VALUE klass, VALUE name)
33
36
  *
34
37
  * Alias encoding handler with name +from+ to name +to+
35
38
  */
36
- static VALUE alias(VALUE klass, VALUE from, VALUE to)
39
+ static VALUE
40
+ alias(VALUE klass, VALUE from, VALUE to)
37
41
  {
38
42
  xmlAddEncodingAlias(StringValueCStr(from), StringValueCStr(to));
39
43
 
@@ -45,7 +49,8 @@ static VALUE alias(VALUE klass, VALUE from, VALUE to)
45
49
  *
46
50
  * Remove all encoding aliases.
47
51
  */
48
- static VALUE clear_aliases(VALUE klass)
52
+ static VALUE
53
+ clear_aliases(VALUE klass)
49
54
  {
50
55
  xmlCleanupEncodingAliases();
51
56
 
@@ -57,7 +62,8 @@ static VALUE clear_aliases(VALUE klass)
57
62
  *
58
63
  * Get the name of this EncodingHandler
59
64
  */
60
- static VALUE name(VALUE self)
65
+ static VALUE
66
+ name(VALUE self)
61
67
  {
62
68
  xmlCharEncodingHandlerPtr handler;
63
69
 
@@ -66,10 +72,10 @@ static VALUE name(VALUE self)
66
72
  return NOKOGIRI_STR_NEW2(handler->name);
67
73
  }
68
74
 
69
- void init_xml_encoding_handler()
75
+ void
76
+ noko_init_xml_encoding_handler()
70
77
  {
71
- VALUE nokogiri = rb_define_module("Nokogiri");
72
- VALUE klass = rb_define_class_under(nokogiri, "EncodingHandler", rb_cObject);
78
+ VALUE klass = rb_define_class_under(mNokogiri, "EncodingHandler", rb_cObject);
73
79
 
74
80
  rb_define_singleton_method(klass, "[]", get, 1);
75
81
  rb_define_singleton_method(klass, "delete", delete, 1);
@@ -1,4 +1,6 @@
1
- #include <xml_entity_decl.h>
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlEntityDecl;
2
4
 
3
5
  /*
4
6
  * call-seq:
@@ -6,12 +8,13 @@
6
8
  *
7
9
  * Get the original_content before ref substitution
8
10
  */
9
- static VALUE original_content(VALUE self)
11
+ static VALUE
12
+ original_content(VALUE self)
10
13
  {
11
14
  xmlEntityPtr node;
12
15
  Data_Get_Struct(self, xmlEntity, node);
13
16
 
14
- if(!node->orig) return Qnil;
17
+ if (!node->orig) { return Qnil; }
15
18
 
16
19
  return NOKOGIRI_STR_NEW2(node->orig);
17
20
  }
@@ -22,12 +25,13 @@ static VALUE original_content(VALUE self)
22
25
  *
23
26
  * Get the content
24
27
  */
25
- static VALUE get_content(VALUE self)
28
+ static VALUE
29
+ get_content(VALUE self)
26
30
  {
27
31
  xmlEntityPtr node;
28
32
  Data_Get_Struct(self, xmlEntity, node);
29
33
 
30
- if(!node->content) return Qnil;
34
+ if (!node->content) { return Qnil; }
31
35
 
32
36
  return NOKOGIRI_STR_NEW(node->content, node->length);
33
37
  }
@@ -38,7 +42,8 @@ static VALUE get_content(VALUE self)
38
42
  *
39
43
  * Get the entity type
40
44
  */
41
- static VALUE entity_type(VALUE self)
45
+ static VALUE
46
+ entity_type(VALUE self)
42
47
  {
43
48
  xmlEntityPtr node;
44
49
  Data_Get_Struct(self, xmlEntity, node);
@@ -52,12 +57,13 @@ static VALUE entity_type(VALUE self)
52
57
  *
53
58
  * Get the external identifier for PUBLIC
54
59
  */
55
- static VALUE external_id(VALUE self)
60
+ static VALUE
61
+ external_id(VALUE self)
56
62
  {
57
63
  xmlEntityPtr node;
58
64
  Data_Get_Struct(self, xmlEntity, node);
59
65
 
60
- if(!node->ExternalID) return Qnil;
66
+ if (!node->ExternalID) { return Qnil; }
61
67
 
62
68
  return NOKOGIRI_STR_NEW2(node->ExternalID);
63
69
  }
@@ -68,43 +74,39 @@ static VALUE external_id(VALUE self)
68
74
  *
69
75
  * Get the URI for a SYSTEM or PUBLIC Entity
70
76
  */
71
- static VALUE system_id(VALUE self)
77
+ static VALUE
78
+ system_id(VALUE self)
72
79
  {
73
80
  xmlEntityPtr node;
74
81
  Data_Get_Struct(self, xmlEntity, node);
75
82
 
76
- if(!node->SystemID) return Qnil;
83
+ if (!node->SystemID) { return Qnil; }
77
84
 
78
85
  return NOKOGIRI_STR_NEW2(node->SystemID);
79
86
  }
80
87
 
81
- VALUE cNokogiriXmlEntityDecl;
82
-
83
- void init_xml_entity_decl()
88
+ void
89
+ noko_init_xml_entity_decl()
84
90
  {
85
- VALUE nokogiri = rb_define_module("Nokogiri");
86
- VALUE xml = rb_define_module_under(nokogiri, "XML");
87
- VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
88
- VALUE klass = rb_define_class_under(xml, "EntityDecl", node);
89
-
90
- cNokogiriXmlEntityDecl = klass;
91
+ assert(cNokogiriXmlNode);
92
+ cNokogiriXmlEntityDecl = rb_define_class_under(mNokogiriXml, "EntityDecl", cNokogiriXmlNode);
91
93
 
92
- rb_define_method(klass, "original_content", original_content, 0);
93
- rb_define_method(klass, "content", get_content, 0);
94
- rb_define_method(klass, "entity_type", entity_type, 0);
95
- rb_define_method(klass, "external_id", external_id, 0);
96
- rb_define_method(klass, "system_id", system_id, 0);
94
+ rb_define_method(cNokogiriXmlEntityDecl, "original_content", original_content, 0);
95
+ rb_define_method(cNokogiriXmlEntityDecl, "content", get_content, 0);
96
+ rb_define_method(cNokogiriXmlEntityDecl, "entity_type", entity_type, 0);
97
+ rb_define_method(cNokogiriXmlEntityDecl, "external_id", external_id, 0);
98
+ rb_define_method(cNokogiriXmlEntityDecl, "system_id", system_id, 0);
97
99
 
98
100
  rb_const_set(cNokogiriXmlEntityDecl, rb_intern("INTERNAL_GENERAL"),
99
- INT2NUM(XML_INTERNAL_GENERAL_ENTITY));
101
+ INT2NUM(XML_INTERNAL_GENERAL_ENTITY));
100
102
  rb_const_set(cNokogiriXmlEntityDecl, rb_intern("EXTERNAL_GENERAL_PARSED"),
101
- INT2NUM(XML_EXTERNAL_GENERAL_PARSED_ENTITY));
103
+ INT2NUM(XML_EXTERNAL_GENERAL_PARSED_ENTITY));
102
104
  rb_const_set(cNokogiriXmlEntityDecl, rb_intern("EXTERNAL_GENERAL_UNPARSED"),
103
- INT2NUM(XML_EXTERNAL_GENERAL_UNPARSED_ENTITY));
105
+ INT2NUM(XML_EXTERNAL_GENERAL_UNPARSED_ENTITY));
104
106
  rb_const_set(cNokogiriXmlEntityDecl, rb_intern("INTERNAL_PARAMETER"),
105
- INT2NUM(XML_INTERNAL_PARAMETER_ENTITY));
107
+ INT2NUM(XML_INTERNAL_PARAMETER_ENTITY));
106
108
  rb_const_set(cNokogiriXmlEntityDecl, rb_intern("EXTERNAL_PARAMETER"),
107
- INT2NUM(XML_EXTERNAL_PARAMETER_ENTITY));
109
+ INT2NUM(XML_EXTERNAL_PARAMETER_ENTITY));
108
110
  rb_const_set(cNokogiriXmlEntityDecl, rb_intern("INTERNAL_PREDEFINED"),
109
- INT2NUM(XML_INTERNAL_PREDEFINED_ENTITY));
111
+ INT2NUM(XML_INTERNAL_PREDEFINED_ENTITY));
110
112
  }
@@ -1,4 +1,6 @@
1
- #include <xml_entity_reference.h>
1
+ #include <nokogiri.h>
2
+
3
+ VALUE cNokogiriXmlEntityReference;
2
4
 
3
5
  /*
4
6
  * call-seq:
@@ -6,7 +8,8 @@
6
8
  *
7
9
  * Create a new EntityReference element on the +document+ with +name+
8
10
  */
9
- static VALUE new(int argc, VALUE *argv, VALUE klass)
11
+ static VALUE
12
+ new (int argc, VALUE *argv, VALUE klass)
10
13
  {
11
14
  xmlDocPtr xml_doc;
12
15
  xmlNodePtr node;
@@ -20,33 +23,28 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
20
23
  Data_Get_Struct(document, xmlDoc, xml_doc);
21
24
 
22
25
  node = xmlNewReference(
23
- xml_doc,
24
- (const xmlChar *)StringValueCStr(name)
25
- );
26
+ xml_doc,
27
+ (const xmlChar *)StringValueCStr(name)
28
+ );
26
29
 
27
- nokogiri_root_node(node);
30
+ noko_xml_document_pin_node(node);
28
31
 
29
- rb_node = Nokogiri_wrap_xml_node(klass, node);
32
+ rb_node = noko_xml_node_wrap(klass, node);
30
33
  rb_obj_call_init(rb_node, argc, argv);
31
34
 
32
- if(rb_block_given_p()) rb_yield(rb_node);
35
+ if (rb_block_given_p()) { rb_yield(rb_node); }
33
36
 
34
37
  return rb_node;
35
38
  }
36
39
 
37
- VALUE cNokogiriXmlEntityReference;
38
- void init_xml_entity_reference()
40
+ void
41
+ noko_init_xml_entity_reference()
39
42
  {
40
- VALUE nokogiri = rb_define_module("Nokogiri");
41
- VALUE xml = rb_define_module_under(nokogiri, "XML");
42
- VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
43
-
43
+ assert(cNokogiriXmlNode);
44
44
  /*
45
45
  * EntityReference represents an EntityReference node in an xml document.
46
46
  */
47
- VALUE klass = rb_define_class_under(xml, "EntityReference", node);
48
-
49
- cNokogiriXmlEntityReference = klass;
47
+ cNokogiriXmlEntityReference = rb_define_class_under(mNokogiriXml, "EntityReference", cNokogiriXmlNode);
50
48
 
51
- rb_define_singleton_method(klass, "new", new, -1);
49
+ rb_define_singleton_method(cNokogiriXmlEntityReference, "new", new, -1);
52
50
  }
@@ -1,16 +1,35 @@
1
- #include <xml_namespace.h>
1
+ #include <nokogiri.h>
2
+
3
+ /*
4
+ * The lifecycle of a Namespace node is more complicated than other Nodes, for two reasons:
5
+ *
6
+ * 1. the underlying C structure has a different layout than all the other node structs, with the
7
+ * `_private` member where we store a pointer to Ruby object data not being in first position.
8
+ * 2. xmlNs structures returned in an xmlNodeset from an XPath query are copies of the document's
9
+ * namespaces, and so do not share the same memory lifecycle as everything else in a document.
10
+ *
11
+ * As a result of 1, you may see special handling of XML_NAMESPACE_DECL node types throughout the
12
+ * Nokogiri C code, though I intend to wrap up that logic in ruby_object_{get,set} functions
13
+ * shortly.
14
+ *
15
+ * As a result of 2, you will see we have special handling in this file and in xml_node_set.c to
16
+ * carefully manage the memory lifecycle of xmlNs structs to match the Ruby object's GC
17
+ * lifecycle. In xml_node_set.c we have local versions of xmlXPathNodeSetDel() and
18
+ * xmlXPathFreeNodeSet() that avoid freeing xmlNs structs in the node set. In this file, we decide
19
+ * whether or not to call dealloc_namespace() depending on whether the xmlNs struct appears to be
20
+ * in an xmlNodeSet (and thus the result of an XPath query) or not.
21
+ *
22
+ * Yes, this is madness.
23
+ */
2
24
 
3
25
  VALUE cNokogiriXmlNamespace ;
4
26
 
5
- static void dealloc_namespace(xmlNsPtr ns)
27
+ static void
28
+ dealloc_namespace(xmlNsPtr ns)
6
29
  {
7
30
  /*
8
- *
9
31
  * this deallocator is only used for namespace nodes that are part of an xpath
10
- * node set.
11
- *
12
- * see Nokogiri_wrap_xml_namespace() for more details.
13
- *
32
+ * node set. see noko_xml_namespace_wrap().
14
33
  */
15
34
  NOKOGIRI_DEBUG_START(ns) ;
16
35
  if (ns->href) {
@@ -30,12 +49,13 @@ static void dealloc_namespace(xmlNsPtr ns)
30
49
  *
31
50
  * Get the prefix for this namespace. Returns +nil+ if there is no prefix.
32
51
  */
33
- static VALUE prefix(VALUE self)
52
+ static VALUE
53
+ prefix(VALUE self)
34
54
  {
35
55
  xmlNsPtr ns;
36
56
 
37
57
  Data_Get_Struct(self, xmlNs, ns);
38
- if(!ns->prefix) return Qnil;
58
+ if (!ns->prefix) { return Qnil; }
39
59
 
40
60
  return NOKOGIRI_STR_NEW2(ns->prefix);
41
61
  }
@@ -46,66 +66,53 @@ static VALUE prefix(VALUE self)
46
66
  *
47
67
  * Get the href for this namespace
48
68
  */
49
- static VALUE href(VALUE self)
69
+ static VALUE
70
+ href(VALUE self)
50
71
  {
51
72
  xmlNsPtr ns;
52
73
 
53
74
  Data_Get_Struct(self, xmlNs, ns);
54
- if(!ns->href) return Qnil;
75
+ if (!ns->href) { return Qnil; }
55
76
 
56
77
  return NOKOGIRI_STR_NEW2(ns->href);
57
78
  }
58
79
 
59
- static int part_of_an_xpath_node_set_eh(xmlNsPtr node)
60
- {
61
- return (node->next && ! NOKOGIRI_NAMESPACE_EH(node->next));
62
- }
63
-
64
- VALUE Nokogiri_wrap_xml_namespace(xmlDocPtr doc, xmlNsPtr node)
80
+ VALUE
81
+ noko_xml_namespace_wrap(xmlNsPtr c_namespace, xmlDocPtr c_document)
65
82
  {
66
- VALUE ns = 0, document, node_cache;
67
-
68
- assert(doc->type == XML_DOCUMENT_NODE || doc->type == XML_HTML_DOCUMENT_NODE);
69
-
70
- if (node->_private) return (VALUE)node->_private;
83
+ VALUE rb_namespace;
71
84
 
72
- if (doc->type == XML_DOCUMENT_FRAG_NODE) doc = doc->doc;
85
+ if (c_namespace->_private) {
86
+ return (VALUE)c_namespace->_private;
87
+ }
73
88
 
74
- if (DOC_RUBY_OBJECT_TEST(doc)) {
75
- document = DOC_RUBY_OBJECT(doc);
89
+ if (c_document) {
90
+ rb_namespace = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, c_namespace);
76
91
 
77
- if (part_of_an_xpath_node_set_eh(node)) {
78
- /*
79
- * this is a duplicate returned as part of an xpath query node set, and so
80
- * we need to make sure we manage this memory.
81
- *
82
- * see comments in xml_node_set.c for more details.
83
- */
84
- ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, dealloc_namespace, node);
85
- } else {
86
- ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, node);
87
- node_cache = rb_iv_get(document, "@node_cache");
88
- rb_ary_push(node_cache, ns);
92
+ if (DOC_RUBY_OBJECT_TEST(c_document)) {
93
+ rb_iv_set(rb_namespace, "@document", DOC_RUBY_OBJECT(c_document));
94
+ rb_ary_push(DOC_NODE_CACHE(c_document), rb_namespace);
89
95
  }
90
-
91
- rb_iv_set(ns, "@document", document);
92
96
  } else {
93
- ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, node);
97
+ rb_namespace = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, dealloc_namespace, c_namespace);
94
98
  }
95
99
 
96
- node->_private = (void *)ns;
100
+ c_namespace->_private = (void *)rb_namespace;
97
101
 
98
- return ns;
102
+ return rb_namespace;
99
103
  }
100
104
 
101
- void init_xml_namespace()
105
+ VALUE
106
+ noko_xml_namespace_wrap_xpath_copy(xmlNsPtr c_namespace)
102
107
  {
103
- VALUE nokogiri = rb_define_module("Nokogiri");
104
- VALUE xml = rb_define_module_under(nokogiri, "XML");
105
- VALUE klass = rb_define_class_under(xml, "Namespace", rb_cObject);
108
+ return noko_xml_namespace_wrap(c_namespace, NULL);
109
+ }
106
110
 
107
- cNokogiriXmlNamespace = klass;
111
+ void
112
+ noko_init_xml_namespace()
113
+ {
114
+ cNokogiriXmlNamespace = rb_define_class_under(mNokogiriXml, "Namespace", rb_cObject);
108
115
 
109
- rb_define_method(klass, "prefix", prefix, 0);
110
- rb_define_method(klass, "href", href, 0);
116
+ rb_define_method(cNokogiriXmlNamespace, "prefix", prefix, 0);
117
+ rb_define_method(cNokogiriXmlNamespace, "href", href, 0);
111
118
  }
@@ -1,9 +1,12 @@
1
- #include <xml_node.h>
1
+ #include <nokogiri.h>
2
2
 
3
- static ID decorate, decorate_bang;
3
+ VALUE cNokogiriXmlNode ;
4
+
5
+ static ID id_decorate, id_decorate_bang;
4
6
 
5
7
  #ifdef DEBUG
6
- static void debug_node_dealloc(xmlNodePtr x)
8
+ static void
9
+ debug_node_dealloc(xmlNodePtr x)
7
10
  {
8
11
  NOKOGIRI_DEBUG_START(x)
9
12
  NOKOGIRI_DEBUG_END(x)
@@ -12,23 +15,25 @@ static void debug_node_dealloc(xmlNodePtr x)
12
15
  # define debug_node_dealloc 0
13
16
  #endif
14
17
 
15
- static void mark(xmlNodePtr node)
18
+ static void
19
+ mark(xmlNodePtr node)
16
20
  {
17
21
  xmlDocPtr doc = node->doc;
18
- if(doc->type == XML_DOCUMENT_NODE || doc->type == XML_HTML_DOCUMENT_NODE) {
19
- if(DOC_RUBY_OBJECT_TEST(doc)) {
22
+ if (doc->type == XML_DOCUMENT_NODE || doc->type == XML_HTML_DOCUMENT_NODE) {
23
+ if (DOC_RUBY_OBJECT_TEST(doc)) {
20
24
  rb_gc_mark(DOC_RUBY_OBJECT(doc));
21
25
  }
22
- } else if(node->doc->_private) {
26
+ } else if (node->doc->_private) {
23
27
  rb_gc_mark((VALUE)doc->_private);
24
28
  }
25
29
  }
26
30
 
27
31
  /* :nodoc: */
28
- typedef xmlNodePtr (*pivot_reparentee_func)(xmlNodePtr, xmlNodePtr);
32
+ typedef xmlNodePtr(*pivot_reparentee_func)(xmlNodePtr, xmlNodePtr);
29
33
 
30
34
  /* :nodoc: */
31
- static void relink_namespace(xmlNodePtr reparented)
35
+ static void
36
+ relink_namespace(xmlNodePtr reparented)
32
37
  {
33
38
  xmlNodePtr child;
34
39
 
@@ -42,7 +47,7 @@ static void relink_namespace(xmlNodePtr reparented)
42
47
  name = xmlSplitQName2(reparented->name, &prefix);
43
48
 
44
49
  if (reparented->type == XML_ATTRIBUTE_NODE) {
45
- if (prefix == NULL || strcmp((char*)prefix, XMLNS_PREFIX) == 0) {
50
+ if (prefix == NULL || strcmp((char *)prefix, XMLNS_PREFIX) == 0) {
46
51
  xmlFree(name);
47
52
  xmlFree(prefix);
48
53
  return;
@@ -87,7 +92,7 @@ static void relink_namespace(xmlNodePtr reparented)
87
92
  } else {
88
93
  reparented->nsDef = curr->next;
89
94
  }
90
- nokogiri_root_nsdef(curr, reparented->doc);
95
+ noko_xml_document_pin_namespace(curr, reparented->doc);
91
96
  } else {
92
97
  prev = curr;
93
98
  }
@@ -128,7 +133,7 @@ static void relink_namespace(xmlNodePtr reparented)
128
133
 
129
134
  if (reparented->type == XML_ELEMENT_NODE) {
130
135
  child = (xmlNodePtr)((xmlElementPtr)reparented)->attributes;
131
- while(NULL != child) {
136
+ while (NULL != child) {
132
137
  relink_namespace(child);
133
138
  child = child->next;
134
139
  }
@@ -136,7 +141,8 @@ static void relink_namespace(xmlNodePtr reparented)
136
141
  }
137
142
 
138
143
  /* :nodoc: */
139
- static xmlNodePtr xmlReplaceNodeWrapper(xmlNodePtr pivot, xmlNodePtr new_node)
144
+ static xmlNodePtr
145
+ xmlReplaceNodeWrapper(xmlNodePtr pivot, xmlNodePtr new_node)
140
146
  {
141
147
  xmlNodePtr retval ;
142
148
 
@@ -160,16 +166,17 @@ static xmlNodePtr xmlReplaceNodeWrapper(xmlNodePtr pivot, xmlNodePtr new_node)
160
166
  }
161
167
 
162
168
  /* :nodoc: */
163
- static VALUE reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_reparentee_func prf)
169
+ static VALUE
170
+ reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_reparentee_func prf)
164
171
  {
165
172
  VALUE reparented_obj ;
166
173
  xmlNodePtr reparentee, pivot, reparented, next_text, new_next_text, parent ;
167
174
  int original_ns_prefix_is_default = 0 ;
168
175
 
169
- if(!rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlNode)) {
176
+ if (!rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlNode)) {
170
177
  rb_raise(rb_eArgError, "node must be a Nokogiri::XML::Node");
171
178
  }
172
- if(rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlDocument)) {
179
+ if (rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlDocument)) {
173
180
  rb_raise(rb_eArgError, "node must be a Nokogiri::XML::Node");
174
181
  }
175
182
 
@@ -290,7 +297,7 @@ ok:
290
297
  original_ns_prefix_is_default = 1;
291
298
  }
292
299
 
293
- nokogiri_root_node(reparentee);
300
+ noko_xml_document_pin_node(reparentee);
294
301
 
295
302
  if (!(reparentee = xmlDocCopyNode(reparentee, pivot->doc, 1))) {
296
303
  rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
@@ -301,7 +308,7 @@ ok:
301
308
  * issue #391, where new node's prefix may become the string "default"
302
309
  * see libxml2 tree.c xmlNewReconciliedNs which implements this behavior.
303
310
  */
304
- xmlFree(reparentee->ns->prefix);
311
+ xmlFree((xmlChar *)reparentee->ns->prefix);
305
312
  reparentee->ns->prefix = NULL;
306
313
  }
307
314
  }
@@ -330,12 +337,12 @@ ok:
330
337
  new_next_text = xmlDocCopyNode(next_text, pivot->doc, 1) ;
331
338
 
332
339
  xmlUnlinkNode(next_text);
333
- nokogiri_root_node(next_text);
340
+ noko_xml_document_pin_node(next_text);
334
341
 
335
342
  xmlAddNextSibling(pivot, new_next_text);
336
343
  }
337
344
 
338
- if(!(reparented = (*prf)(pivot, reparentee))) {
345
+ if (!(reparented = (*prf)(pivot, reparentee))) {
339
346
  rb_raise(rb_eRuntimeError, "Could not reparent node");
340
347
  }
341
348
 
@@ -348,9 +355,9 @@ ok:
348
355
 
349
356
  relink_namespace(reparented);
350
357
 
351
- reparented_obj = Nokogiri_wrap_xml_node(Qnil, reparented);
358
+ reparented_obj = noko_xml_node_wrap(Qnil, reparented);
352
359
 
353
- rb_funcall(reparented_obj, decorate_bang, 0);
360
+ rb_funcall(reparented_obj, id_decorate_bang, 0);
354
361
 
355
362
  return reparented_obj ;
356
363
  }
@@ -362,7 +369,8 @@ ok:
362
369
  *
363
370
  * Get the document for this Node
364
371
  */
365
- static VALUE document(VALUE self)
372
+ static VALUE
373
+ document(VALUE self)
366
374
  {
367
375
  xmlNodePtr node;
368
376
  Data_Get_Struct(self, xmlNode, node);
@@ -375,7 +383,8 @@ static VALUE document(VALUE self)
375
383
  *
376
384
  * Get the internal pointer number
377
385
  */
378
- static VALUE pointer_id(VALUE self)
386
+ static VALUE
387
+ pointer_id(VALUE self)
379
388
  {
380
389
  xmlNodePtr node;
381
390
  Data_Get_Struct(self, xmlNode, node);
@@ -389,7 +398,8 @@ static VALUE pointer_id(VALUE self)
389
398
  *
390
399
  * Encode any special characters in +string+
391
400
  */
392
- static VALUE encode_special_chars(VALUE self, VALUE string)
401
+ static VALUE
402
+ encode_special_chars(VALUE self, VALUE string)
393
403
  {
394
404
  xmlNodePtr node;
395
405
  xmlChar *encoded;
@@ -419,7 +429,8 @@ static VALUE encode_special_chars(VALUE self, VALUE string)
419
429
  * doc.create_internal_subset("chapter", nil, "chapter.dtd")
420
430
  * # => <!DOCTYPE chapter SYSTEM "chapter.dtd">
421
431
  */
422
- static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, VALUE system_id)
432
+ static VALUE
433
+ create_internal_subset(VALUE self, VALUE name, VALUE external_id, VALUE system_id)
423
434
  {
424
435
  xmlNodePtr node;
425
436
  xmlDocPtr doc;
@@ -429,7 +440,7 @@ static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, V
429
440
 
430
441
  doc = node->doc;
431
442
 
432
- if(xmlGetIntSubset(doc)) {
443
+ if (xmlGetIntSubset(doc)) {
433
444
  rb_raise(rb_eRuntimeError, "Document already has an internal subset");
434
445
  }
435
446
 
@@ -440,9 +451,9 @@ static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, V
440
451
  NIL_P(system_id) ? NULL : (const xmlChar *)StringValueCStr(system_id)
441
452
  );
442
453
 
443
- if(!dtd) { return Qnil; }
454
+ if (!dtd) { return Qnil; }
444
455
 
445
- return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)dtd);
456
+ return noko_xml_node_wrap(Qnil, (xmlNodePtr)dtd);
446
457
  }
447
458
 
448
459
  /*
@@ -451,7 +462,8 @@ static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, V
451
462
  *
452
463
  * Create an external subset
453
464
  */
454
- static VALUE create_external_subset(VALUE self, VALUE name, VALUE external_id, VALUE system_id)
465
+ static VALUE
466
+ create_external_subset(VALUE self, VALUE name, VALUE external_id, VALUE system_id)
455
467
  {
456
468
  xmlNodePtr node;
457
469
  xmlDocPtr doc;
@@ -461,7 +473,7 @@ static VALUE create_external_subset(VALUE self, VALUE name, VALUE external_id, V
461
473
 
462
474
  doc = node->doc;
463
475
 
464
- if(doc->extSubset) {
476
+ if (doc->extSubset) {
465
477
  rb_raise(rb_eRuntimeError, "Document already has an external subset");
466
478
  }
467
479
 
@@ -472,9 +484,9 @@ static VALUE create_external_subset(VALUE self, VALUE name, VALUE external_id, V
472
484
  NIL_P(system_id) ? NULL : (const xmlChar *)StringValueCStr(system_id)
473
485
  );
474
486
 
475
- if(!dtd) { return Qnil; }
487
+ if (!dtd) { return Qnil; }
476
488
 
477
- return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)dtd);
489
+ return noko_xml_node_wrap(Qnil, (xmlNodePtr)dtd);
478
490
  }
479
491
 
480
492
  /*
@@ -483,7 +495,8 @@ static VALUE create_external_subset(VALUE self, VALUE name, VALUE external_id, V
483
495
  *
484
496
  * Get the external subset
485
497
  */
486
- static VALUE external_subset(VALUE self)
498
+ static VALUE
499
+ external_subset(VALUE self)
487
500
  {
488
501
  xmlNodePtr node;
489
502
  xmlDocPtr doc;
@@ -491,14 +504,14 @@ static VALUE external_subset(VALUE self)
491
504
 
492
505
  Data_Get_Struct(self, xmlNode, node);
493
506
 
494
- if(!node->doc) { return Qnil; }
507
+ if (!node->doc) { return Qnil; }
495
508
 
496
509
  doc = node->doc;
497
510
  dtd = doc->extSubset;
498
511
 
499
- if(!dtd) { return Qnil; }
512
+ if (!dtd) { return Qnil; }
500
513
 
501
- return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)dtd);
514
+ return noko_xml_node_wrap(Qnil, (xmlNodePtr)dtd);
502
515
  }
503
516
 
504
517
  /*
@@ -507,7 +520,8 @@ static VALUE external_subset(VALUE self)
507
520
  *
508
521
  * Get the internal subset
509
522
  */
510
- static VALUE internal_subset(VALUE self)
523
+ static VALUE
524
+ internal_subset(VALUE self)
511
525
  {
512
526
  xmlNodePtr node;
513
527
  xmlDocPtr doc;
@@ -515,14 +529,14 @@ static VALUE internal_subset(VALUE self)
515
529
 
516
530
  Data_Get_Struct(self, xmlNode, node);
517
531
 
518
- if(!node->doc) { return Qnil; }
532
+ if (!node->doc) { return Qnil; }
519
533
 
520
534
  doc = node->doc;
521
535
  dtd = xmlGetIntSubset(doc);
522
536
 
523
- if(!dtd) { return Qnil; }
537
+ if (!dtd) { return Qnil; }
524
538
 
525
- return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)dtd);
539
+ return noko_xml_node_wrap(Qnil, (xmlNodePtr)dtd);
526
540
  }
527
541
 
528
542
  /*
@@ -537,7 +551,8 @@ static VALUE internal_subset(VALUE self)
537
551
  * node's parent document. Defaults to the current node's document.
538
552
  * current document.
539
553
  */
540
- static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
554
+ static VALUE
555
+ duplicate_node(int argc, VALUE *argv, VALUE self)
541
556
  {
542
557
  VALUE r_level, r_new_parent_doc;
543
558
  int level;
@@ -561,11 +576,11 @@ static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
561
576
  }
562
577
 
563
578
  dup = xmlDocCopyNode(node, new_parent_doc, level);
564
- if(dup == NULL) { return Qnil; }
579
+ if (dup == NULL) { return Qnil; }
565
580
 
566
- nokogiri_root_node(dup);
581
+ noko_xml_document_pin_node(dup);
567
582
 
568
- return Nokogiri_wrap_xml_node(rb_obj_class(self), dup);
583
+ return noko_xml_node_wrap(rb_obj_class(self), dup);
569
584
  }
570
585
 
571
586
  /*
@@ -574,12 +589,13 @@ static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
574
589
  *
575
590
  * Unlink this node from its current context.
576
591
  */
577
- static VALUE unlink_node(VALUE self)
592
+ static VALUE
593
+ unlink_node(VALUE self)
578
594
  {
579
595
  xmlNodePtr node;
580
596
  Data_Get_Struct(self, xmlNode, node);
581
597
  xmlUnlinkNode(node);
582
- nokogiri_root_node(node);
598
+ noko_xml_document_pin_node(node);
583
599
  return self;
584
600
  }
585
601
 
@@ -589,7 +605,8 @@ static VALUE unlink_node(VALUE self)
589
605
  *
590
606
  * Is this node blank?
591
607
  */
592
- static VALUE blank_eh(VALUE self)
608
+ static VALUE
609
+ blank_eh(VALUE self)
593
610
  {
594
611
  xmlNodePtr node;
595
612
  Data_Get_Struct(self, xmlNode, node);
@@ -602,15 +619,16 @@ static VALUE blank_eh(VALUE self)
602
619
  *
603
620
  * Returns the next sibling node
604
621
  */
605
- static VALUE next_sibling(VALUE self)
622
+ static VALUE
623
+ next_sibling(VALUE self)
606
624
  {
607
625
  xmlNodePtr node, sibling;
608
626
  Data_Get_Struct(self, xmlNode, node);
609
627
 
610
628
  sibling = node->next;
611
- if(!sibling) { return Qnil; }
629
+ if (!sibling) { return Qnil; }
612
630
 
613
- return Nokogiri_wrap_xml_node(Qnil, sibling) ;
631
+ return noko_xml_node_wrap(Qnil, sibling) ;
614
632
  }
615
633
 
616
634
  /*
@@ -619,15 +637,16 @@ static VALUE next_sibling(VALUE self)
619
637
  *
620
638
  * Returns the previous sibling node
621
639
  */
622
- static VALUE previous_sibling(VALUE self)
640
+ static VALUE
641
+ previous_sibling(VALUE self)
623
642
  {
624
643
  xmlNodePtr node, sibling;
625
644
  Data_Get_Struct(self, xmlNode, node);
626
645
 
627
646
  sibling = node->prev;
628
- if(!sibling) { return Qnil; }
647
+ if (!sibling) { return Qnil; }
629
648
 
630
- return Nokogiri_wrap_xml_node(Qnil, sibling);
649
+ return noko_xml_node_wrap(Qnil, sibling);
631
650
  }
632
651
 
633
652
  /*
@@ -636,15 +655,16 @@ static VALUE previous_sibling(VALUE self)
636
655
  *
637
656
  * Returns the next Nokogiri::XML::Element type sibling node.
638
657
  */
639
- static VALUE next_element(VALUE self)
658
+ static VALUE
659
+ next_element(VALUE self)
640
660
  {
641
661
  xmlNodePtr node, sibling;
642
662
  Data_Get_Struct(self, xmlNode, node);
643
663
 
644
664
  sibling = xmlNextElementSibling(node);
645
- if(!sibling) { return Qnil; }
665
+ if (!sibling) { return Qnil; }
646
666
 
647
- return Nokogiri_wrap_xml_node(Qnil, sibling);
667
+ return noko_xml_node_wrap(Qnil, sibling);
648
668
  }
649
669
 
650
670
  /*
@@ -653,7 +673,8 @@ static VALUE next_element(VALUE self)
653
673
  *
654
674
  * Returns the previous Nokogiri::XML::Element type sibling node.
655
675
  */
656
- static VALUE previous_element(VALUE self)
676
+ static VALUE
677
+ previous_element(VALUE self)
657
678
  {
658
679
  xmlNodePtr node, sibling;
659
680
  Data_Get_Struct(self, xmlNode, node);
@@ -662,23 +683,24 @@ static VALUE previous_element(VALUE self)
662
683
  * note that we don't use xmlPreviousElementSibling here because it's buggy pre-2.7.7.
663
684
  */
664
685
  sibling = node->prev;
665
- if(!sibling) { return Qnil; }
686
+ if (!sibling) { return Qnil; }
666
687
 
667
- while(sibling && sibling->type != XML_ELEMENT_NODE) {
688
+ while (sibling && sibling->type != XML_ELEMENT_NODE) {
668
689
  sibling = sibling->prev;
669
690
  }
670
691
 
671
- return sibling ? Nokogiri_wrap_xml_node(Qnil, sibling) : Qnil ;
692
+ return sibling ? noko_xml_node_wrap(Qnil, sibling) : Qnil ;
672
693
  }
673
694
 
674
695
  /* :nodoc: */
675
- static VALUE replace(VALUE self, VALUE new_node)
696
+ static VALUE
697
+ replace(VALUE self, VALUE new_node)
676
698
  {
677
699
  VALUE reparent = reparent_node_with(self, new_node, xmlReplaceNodeWrapper);
678
700
 
679
701
  xmlNodePtr pivot;
680
702
  Data_Get_Struct(self, xmlNode, pivot);
681
- nokogiri_root_node(pivot);
703
+ noko_xml_document_pin_node(pivot);
682
704
 
683
705
  return reparent;
684
706
  }
@@ -689,7 +711,8 @@ static VALUE replace(VALUE self, VALUE new_node)
689
711
  *
690
712
  * Get the list of children for this node as a NodeSet
691
713
  */
692
- static VALUE children(VALUE self)
714
+ static VALUE
715
+ children(VALUE self)
693
716
  {
694
717
  xmlNodePtr node;
695
718
  xmlNodePtr child;
@@ -704,15 +727,15 @@ static VALUE children(VALUE self)
704
727
 
705
728
  document = DOC_RUBY_OBJECT(node->doc);
706
729
 
707
- if(!child) { return Nokogiri_wrap_xml_node_set(set, document); }
730
+ if (!child) { return noko_xml_node_set_wrap(set, document); }
708
731
 
709
732
  child = child->next;
710
- while(NULL != child) {
733
+ while (NULL != child) {
711
734
  xmlXPathNodeSetAddUnique(set, child);
712
735
  child = child->next;
713
736
  }
714
737
 
715
- node_set = Nokogiri_wrap_xml_node_set(set, document);
738
+ node_set = noko_xml_node_set_wrap(set, document);
716
739
 
717
740
  return node_set;
718
741
  }
@@ -728,7 +751,8 @@ static VALUE children(VALUE self)
728
751
  *
729
752
  * @doc.root.element_children.all? { |x| x.element? } # => true
730
753
  */
731
- static VALUE element_children(VALUE self)
754
+ static VALUE
755
+ element_children(VALUE self)
732
756
  {
733
757
  xmlNodePtr node;
734
758
  xmlNodePtr child;
@@ -743,15 +767,15 @@ static VALUE element_children(VALUE self)
743
767
 
744
768
  document = DOC_RUBY_OBJECT(node->doc);
745
769
 
746
- if(!child) { return Nokogiri_wrap_xml_node_set(set, document); }
770
+ if (!child) { return noko_xml_node_set_wrap(set, document); }
747
771
 
748
772
  child = xmlNextElementSibling(child);
749
- while(NULL != child) {
773
+ while (NULL != child) {
750
774
  xmlXPathNodeSetAddUnique(set, child);
751
775
  child = xmlNextElementSibling(child);
752
776
  }
753
777
 
754
- node_set = Nokogiri_wrap_xml_node_set(set, document);
778
+ node_set = noko_xml_node_set_wrap(set, document);
755
779
 
756
780
  return node_set;
757
781
  }
@@ -762,15 +786,16 @@ static VALUE element_children(VALUE self)
762
786
  *
763
787
  * Returns the child node
764
788
  */
765
- static VALUE child(VALUE self)
789
+ static VALUE
790
+ child(VALUE self)
766
791
  {
767
792
  xmlNodePtr node, child;
768
793
  Data_Get_Struct(self, xmlNode, node);
769
794
 
770
795
  child = node->children;
771
- if(!child) { return Qnil; }
796
+ if (!child) { return Qnil; }
772
797
 
773
- return Nokogiri_wrap_xml_node(Qnil, child);
798
+ return noko_xml_node_wrap(Qnil, child);
774
799
  }
775
800
 
776
801
  /*
@@ -783,15 +808,16 @@ static VALUE child(VALUE self)
783
808
  *
784
809
  * @doc.root.first_element_child.element? # => true
785
810
  */
786
- static VALUE first_element_child(VALUE self)
811
+ static VALUE
812
+ first_element_child(VALUE self)
787
813
  {
788
814
  xmlNodePtr node, child;
789
815
  Data_Get_Struct(self, xmlNode, node);
790
816
 
791
817
  child = xmlFirstElementChild(node);
792
- if(!child) { return Qnil; }
818
+ if (!child) { return Qnil; }
793
819
 
794
- return Nokogiri_wrap_xml_node(Qnil, child);
820
+ return noko_xml_node_wrap(Qnil, child);
795
821
  }
796
822
 
797
823
  /*
@@ -804,15 +830,16 @@ static VALUE first_element_child(VALUE self)
804
830
  *
805
831
  * @doc.root.last_element_child.element? # => true
806
832
  */
807
- static VALUE last_element_child(VALUE self)
833
+ static VALUE
834
+ last_element_child(VALUE self)
808
835
  {
809
836
  xmlNodePtr node, child;
810
837
  Data_Get_Struct(self, xmlNode, node);
811
838
 
812
839
  child = xmlLastElementChild(node);
813
- if(!child) { return Qnil; }
840
+ if (!child) { return Qnil; }
814
841
 
815
- return Nokogiri_wrap_xml_node(Qnil, child);
842
+ return noko_xml_node_wrap(Qnil, child);
816
843
  }
817
844
 
818
845
  /*
@@ -821,11 +848,12 @@ static VALUE last_element_child(VALUE self)
821
848
  *
822
849
  * Returns true if +attribute+ is set
823
850
  */
824
- static VALUE key_eh(VALUE self, VALUE attribute)
851
+ static VALUE
852
+ key_eh(VALUE self, VALUE attribute)
825
853
  {
826
854
  xmlNodePtr node;
827
855
  Data_Get_Struct(self, xmlNode, node);
828
- if(xmlHasProp(node, (xmlChar *)StringValueCStr(attribute))) {
856
+ if (xmlHasProp(node, (xmlChar *)StringValueCStr(attribute))) {
829
857
  return Qtrue;
830
858
  }
831
859
  return Qfalse;
@@ -837,12 +865,13 @@ static VALUE key_eh(VALUE self, VALUE attribute)
837
865
  *
838
866
  * Returns true if +attribute+ is set with +namespace+
839
867
  */
840
- static VALUE namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
868
+ static VALUE
869
+ namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
841
870
  {
842
871
  xmlNodePtr node;
843
872
  Data_Get_Struct(self, xmlNode, node);
844
- if(xmlHasNsProp(node, (xmlChar *)StringValueCStr(attribute),
845
- NIL_P(namespace) ? NULL : (xmlChar *)StringValueCStr(namespace))) {
873
+ if (xmlHasNsProp(node, (xmlChar *)StringValueCStr(attribute),
874
+ NIL_P(namespace) ? NULL : (xmlChar *)StringValueCStr(namespace))) {
846
875
  return Qtrue;
847
876
  }
848
877
  return Qfalse;
@@ -854,7 +883,8 @@ static VALUE namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
854
883
  *
855
884
  * Set the +property+ to +value+
856
885
  */
857
- static VALUE set(VALUE self, VALUE property, VALUE value)
886
+ static VALUE
887
+ set(VALUE self, VALUE property, VALUE value)
858
888
  {
859
889
  xmlNodePtr node, cur;
860
890
  xmlAttrPtr prop;
@@ -867,13 +897,13 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
867
897
  * We can avoid this by unlinking these nodes first.
868
898
  */
869
899
  if (node->type != XML_ELEMENT_NODE) {
870
- return(Qnil);
900
+ return (Qnil);
871
901
  }
872
902
  prop = xmlHasProp(node, (xmlChar *)StringValueCStr(property));
873
903
  if (prop && prop->children) {
874
904
  for (cur = prop->children; cur; cur = cur->next) {
875
905
  if (cur->_private) {
876
- nokogiri_root_node(cur);
906
+ noko_xml_document_pin_node(cur);
877
907
  xmlUnlinkNode(cur);
878
908
  }
879
909
  }
@@ -891,7 +921,8 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
891
921
  *
892
922
  * Get the value for +attribute+
893
923
  */
894
- static VALUE get(VALUE self, VALUE rattribute)
924
+ static VALUE
925
+ get(VALUE self, VALUE rattribute)
895
926
  {
896
927
  xmlNodePtr node;
897
928
  xmlChar *value = 0;
@@ -917,7 +948,7 @@ static VALUE get(VALUE self, VALUE rattribute)
917
948
  if (ns) {
918
949
  value = xmlGetNsProp(node, attr_name, ns->href);
919
950
  } else {
920
- value = xmlGetProp(node, (xmlChar*)StringValueCStr(rattribute));
951
+ value = xmlGetProp(node, (xmlChar *)StringValueCStr(rattribute));
921
952
  }
922
953
  } else {
923
954
  value = xmlGetNoNsProp(node, attribute);
@@ -938,14 +969,15 @@ static VALUE get(VALUE self, VALUE rattribute)
938
969
  *
939
970
  * Set the namespace to +namespace+
940
971
  */
941
- static VALUE set_namespace(VALUE self, VALUE namespace)
972
+ static VALUE
973
+ set_namespace(VALUE self, VALUE namespace)
942
974
  {
943
975
  xmlNodePtr node;
944
976
  xmlNsPtr ns = NULL;
945
977
 
946
978
  Data_Get_Struct(self, xmlNode, node);
947
979
 
948
- if(!NIL_P(namespace)) {
980
+ if (!NIL_P(namespace)) {
949
981
  Data_Get_Struct(namespace, xmlNs, ns);
950
982
  }
951
983
 
@@ -960,15 +992,16 @@ static VALUE set_namespace(VALUE self, VALUE namespace)
960
992
  *
961
993
  * Get the attribute node with +name+
962
994
  */
963
- static VALUE attr(VALUE self, VALUE name)
995
+ static VALUE
996
+ attr(VALUE self, VALUE name)
964
997
  {
965
998
  xmlNodePtr node;
966
999
  xmlAttrPtr prop;
967
1000
  Data_Get_Struct(self, xmlNode, node);
968
1001
  prop = xmlHasProp(node, (xmlChar *)StringValueCStr(name));
969
1002
 
970
- if(! prop) { return Qnil; }
971
- return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)prop);
1003
+ if (! prop) { return Qnil; }
1004
+ return noko_xml_node_wrap(Qnil, (xmlNodePtr)prop);
972
1005
  }
973
1006
 
974
1007
  /*
@@ -977,7 +1010,8 @@ static VALUE attr(VALUE self, VALUE name)
977
1010
  *
978
1011
  * Get the attribute node with +name+ and +namespace+
979
1012
  */
980
- static VALUE attribute_with_ns(VALUE self, VALUE name, VALUE namespace)
1013
+ static VALUE
1014
+ attribute_with_ns(VALUE self, VALUE name, VALUE namespace)
981
1015
  {
982
1016
  xmlNodePtr node;
983
1017
  xmlAttrPtr prop;
@@ -985,28 +1019,23 @@ static VALUE attribute_with_ns(VALUE self, VALUE name, VALUE namespace)
985
1019
  prop = xmlHasNsProp(node, (xmlChar *)StringValueCStr(name),
986
1020
  NIL_P(namespace) ? NULL : (xmlChar *)StringValueCStr(namespace));
987
1021
 
988
- if(! prop) { return Qnil; }
989
- return Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)prop);
1022
+ if (! prop) { return Qnil; }
1023
+ return noko_xml_node_wrap(Qnil, (xmlNodePtr)prop);
990
1024
  }
991
1025
 
992
1026
  /*
993
- * call-seq:
994
- * attribute_nodes()
995
- *
996
- * returns a list containing the Node attributes.
1027
+ * @overload attribute_nodes()
1028
+ * Get the attributes for a Node
1029
+ * @return [Array<Nokogiri::XML::Attr>] containing the Node's attributes.
997
1030
  */
998
- static VALUE attribute_nodes(VALUE self)
1031
+ static VALUE
1032
+ attribute_nodes(VALUE rb_node)
999
1033
  {
1000
- /* this code in the mode of xmlHasProp() */
1001
- xmlNodePtr node;
1002
- VALUE attr;
1034
+ xmlNodePtr c_node;
1003
1035
 
1004
- Data_Get_Struct(self, xmlNode, node);
1036
+ Data_Get_Struct(rb_node, xmlNode, c_node);
1005
1037
 
1006
- attr = rb_ary_new();
1007
- Nokogiri_xml_node_properties(node, attr);
1008
-
1009
- return attr ;
1038
+ return noko_xml_node_attrs(c_node);
1010
1039
  }
1011
1040
 
1012
1041
 
@@ -1017,16 +1046,17 @@ static VALUE attribute_nodes(VALUE self)
1017
1046
  * returns the namespace of the element or attribute node as a Namespace
1018
1047
  * object, or nil if there is no namespace for the element or attribute.
1019
1048
  */
1020
- static VALUE namespace(VALUE self)
1049
+ static VALUE
1050
+ noko_xml_node_namespace(VALUE rb_node)
1021
1051
  {
1022
- xmlNodePtr node ;
1023
- Data_Get_Struct(self, xmlNode, node);
1052
+ xmlNodePtr c_node ;
1053
+ Data_Get_Struct(rb_node, xmlNode, c_node);
1024
1054
 
1025
- if (node->ns) {
1026
- return Nokogiri_wrap_xml_namespace(node->doc, node->ns);
1027
- }
1055
+ if (c_node->ns) {
1056
+ return noko_xml_namespace_wrap(c_node->ns, c_node->doc);
1057
+ }
1028
1058
 
1029
- return Qnil ;
1059
+ return Qnil ;
1030
1060
  }
1031
1061
 
1032
1062
  /*
@@ -1035,27 +1065,27 @@ return Qnil ;
1035
1065
  *
1036
1066
  * returns namespaces defined on self element directly, as an array of Namespace objects. Includes both a default namespace (as in"xmlns="), and prefixed namespaces (as in "xmlns:prefix=").
1037
1067
  */
1038
- static VALUE namespace_definitions(VALUE self)
1068
+ static VALUE
1069
+ namespace_definitions(VALUE rb_node)
1039
1070
  {
1040
1071
  /* this code in the mode of xmlHasProp() */
1041
- xmlNodePtr node ;
1042
- VALUE list;
1043
- xmlNsPtr ns;
1044
-
1045
- Data_Get_Struct(self, xmlNode, node);
1046
-
1047
- list = rb_ary_new();
1072
+ xmlNodePtr c_node ;
1073
+ xmlNsPtr c_namespace;
1074
+ VALUE definitions = rb_ary_new();
1048
1075
 
1049
- ns = node->nsDef;
1076
+ Data_Get_Struct(rb_node, xmlNode, c_node);
1050
1077
 
1051
- if(!ns) { return list; }
1078
+ c_namespace = c_node->nsDef;
1079
+ if (!c_namespace) {
1080
+ return definitions;
1081
+ }
1052
1082
 
1053
- while(NULL != ns) {
1054
- rb_ary_push(list, Nokogiri_wrap_xml_namespace(node->doc, ns));
1055
- ns = ns->next;
1083
+ while (c_namespace != NULL) {
1084
+ rb_ary_push(definitions, noko_xml_namespace_wrap(c_namespace, c_node->doc));
1085
+ c_namespace = c_namespace->next;
1056
1086
  }
1057
1087
 
1058
- return list;
1088
+ return definitions;
1059
1089
  }
1060
1090
 
1061
1091
  /*
@@ -1067,26 +1097,27 @@ static VALUE namespace_definitions(VALUE self)
1067
1097
  * namespaces ("xmlns=" style) for self are included in this array; Default
1068
1098
  * namespaces for ancestors, however, are not. See also #namespaces
1069
1099
  */
1070
- static VALUE namespace_scopes(VALUE self)
1100
+ static VALUE
1101
+ namespace_scopes(VALUE rb_node)
1071
1102
  {
1072
- xmlNodePtr node ;
1073
- VALUE list;
1074
- xmlNsPtr *ns_list;
1103
+ xmlNodePtr c_node ;
1104
+ xmlNsPtr *namespaces;
1105
+ VALUE scopes = rb_ary_new();
1075
1106
  int j;
1076
1107
 
1077
- Data_Get_Struct(self, xmlNode, node);
1078
-
1079
- list = rb_ary_new();
1080
- ns_list = xmlGetNsList(node->doc, node);
1108
+ Data_Get_Struct(rb_node, xmlNode, c_node);
1081
1109
 
1082
- if(!ns_list) { return list; }
1110
+ namespaces = xmlGetNsList(c_node->doc, c_node);
1111
+ if (!namespaces) {
1112
+ return scopes;
1113
+ }
1083
1114
 
1084
- for (j = 0 ; ns_list[j] != NULL ; ++j) {
1085
- rb_ary_push(list, Nokogiri_wrap_xml_namespace(node->doc, ns_list[j]));
1115
+ for (j = 0 ; namespaces[j] != NULL ; ++j) {
1116
+ rb_ary_push(scopes, noko_xml_namespace_wrap(namespaces[j], c_node->doc));
1086
1117
  }
1087
1118
 
1088
- xmlFree(ns_list);
1089
- return list;
1119
+ xmlFree(namespaces);
1120
+ return scopes;
1090
1121
  }
1091
1122
 
1092
1123
  /*
@@ -1095,7 +1126,8 @@ static VALUE namespace_scopes(VALUE self)
1095
1126
  *
1096
1127
  * Get the type for this Node
1097
1128
  */
1098
- static VALUE node_type(VALUE self)
1129
+ static VALUE
1130
+ node_type(VALUE self)
1099
1131
  {
1100
1132
  xmlNodePtr node;
1101
1133
  Data_Get_Struct(self, xmlNode, node);
@@ -1108,7 +1140,8 @@ static VALUE node_type(VALUE self)
1108
1140
  *
1109
1141
  * Set the content for this Node
1110
1142
  */
1111
- static VALUE set_native_content(VALUE self, VALUE content)
1143
+ static VALUE
1144
+ set_native_content(VALUE self, VALUE content)
1112
1145
  {
1113
1146
  xmlNodePtr node, child, next ;
1114
1147
  Data_Get_Struct(self, xmlNode, node);
@@ -1117,7 +1150,7 @@ static VALUE set_native_content(VALUE self, VALUE content)
1117
1150
  while (NULL != child) {
1118
1151
  next = child->next ;
1119
1152
  xmlUnlinkNode(child) ;
1120
- nokogiri_root_node(child);
1153
+ noko_xml_document_pin_node(child);
1121
1154
  child = next ;
1122
1155
  }
1123
1156
 
@@ -1132,15 +1165,16 @@ static VALUE set_native_content(VALUE self, VALUE content)
1132
1165
  * Returns the plaintext content for this Node. Note that entities will always
1133
1166
  * be expanded in the returned string.
1134
1167
  */
1135
- static VALUE get_native_content(VALUE self)
1168
+ static VALUE
1169
+ get_native_content(VALUE self)
1136
1170
  {
1137
1171
  xmlNodePtr node;
1138
- xmlChar * content;
1172
+ xmlChar *content;
1139
1173
 
1140
1174
  Data_Get_Struct(self, xmlNode, node);
1141
1175
 
1142
1176
  content = xmlNodeGetContent(node);
1143
- if(content) {
1177
+ if (content) {
1144
1178
  VALUE rval = NOKOGIRI_STR_NEW2(content);
1145
1179
  xmlFree(content);
1146
1180
  return rval;
@@ -1154,13 +1188,14 @@ static VALUE get_native_content(VALUE self)
1154
1188
  *
1155
1189
  * Set the language of a node, i.e. the values of the xml:lang attribute.
1156
1190
  */
1157
- static VALUE set_lang(VALUE self_rb, VALUE lang_rb)
1191
+ static VALUE
1192
+ set_lang(VALUE self_rb, VALUE lang_rb)
1158
1193
  {
1159
1194
  xmlNodePtr self ;
1160
- xmlChar* lang ;
1195
+ xmlChar *lang ;
1161
1196
 
1162
1197
  Data_Get_Struct(self_rb, xmlNode, self);
1163
- lang = (xmlChar*)StringValueCStr(lang_rb);
1198
+ lang = (xmlChar *)StringValueCStr(lang_rb);
1164
1199
 
1165
1200
  xmlNodeSetLang(self, lang);
1166
1201
 
@@ -1174,10 +1209,11 @@ static VALUE set_lang(VALUE self_rb, VALUE lang_rb)
1174
1209
  * Searches the language of a node, i.e. the values of the xml:lang attribute or
1175
1210
  * the one carried by the nearest ancestor.
1176
1211
  */
1177
- static VALUE get_lang(VALUE self_rb)
1212
+ static VALUE
1213
+ get_lang(VALUE self_rb)
1178
1214
  {
1179
1215
  xmlNodePtr self ;
1180
- xmlChar* lang ;
1216
+ xmlChar *lang ;
1181
1217
  VALUE lang_rb ;
1182
1218
 
1183
1219
  Data_Get_Struct(self_rb, xmlNode, self);
@@ -1193,7 +1229,8 @@ static VALUE get_lang(VALUE self_rb)
1193
1229
  }
1194
1230
 
1195
1231
  /* :nodoc: */
1196
- static VALUE add_child(VALUE self, VALUE new_child)
1232
+ static VALUE
1233
+ add_child(VALUE self, VALUE new_child)
1197
1234
  {
1198
1235
  return reparent_node_with(self, new_child, xmlAddChild);
1199
1236
  }
@@ -1204,15 +1241,16 @@ static VALUE add_child(VALUE self, VALUE new_child)
1204
1241
  *
1205
1242
  * Get the parent Node for this Node
1206
1243
  */
1207
- static VALUE get_parent(VALUE self)
1244
+ static VALUE
1245
+ get_parent(VALUE self)
1208
1246
  {
1209
1247
  xmlNodePtr node, parent;
1210
1248
  Data_Get_Struct(self, xmlNode, node);
1211
1249
 
1212
1250
  parent = node->parent;
1213
- if(!parent) { return Qnil; }
1251
+ if (!parent) { return Qnil; }
1214
1252
 
1215
- return Nokogiri_wrap_xml_node(Qnil, parent) ;
1253
+ return noko_xml_node_wrap(Qnil, parent) ;
1216
1254
  }
1217
1255
 
1218
1256
  /*
@@ -1221,11 +1259,12 @@ static VALUE get_parent(VALUE self)
1221
1259
  *
1222
1260
  * Set the name for this Node
1223
1261
  */
1224
- static VALUE set_name(VALUE self, VALUE new_name)
1262
+ static VALUE
1263
+ set_name(VALUE self, VALUE new_name)
1225
1264
  {
1226
1265
  xmlNodePtr node;
1227
1266
  Data_Get_Struct(self, xmlNode, node);
1228
- xmlNodeSetName(node, (xmlChar*)StringValueCStr(new_name));
1267
+ xmlNodeSetName(node, (xmlChar *)StringValueCStr(new_name));
1229
1268
  return new_name;
1230
1269
  }
1231
1270
 
@@ -1235,11 +1274,12 @@ static VALUE set_name(VALUE self, VALUE new_name)
1235
1274
  *
1236
1275
  * Returns the name for this Node
1237
1276
  */
1238
- static VALUE get_name(VALUE self)
1277
+ static VALUE
1278
+ get_name(VALUE self)
1239
1279
  {
1240
1280
  xmlNodePtr node;
1241
1281
  Data_Get_Struct(self, xmlNode, node);
1242
- if(node->name) {
1282
+ if (node->name) {
1243
1283
  return NOKOGIRI_STR_NEW2(node->name);
1244
1284
  }
1245
1285
  return Qnil;
@@ -1251,7 +1291,8 @@ static VALUE get_name(VALUE self)
1251
1291
  *
1252
1292
  * Returns the path associated with this Node
1253
1293
  */
1254
- static VALUE path(VALUE self)
1294
+ static VALUE
1295
+ path(VALUE self)
1255
1296
  {
1256
1297
  xmlNodePtr node;
1257
1298
  xmlChar *path ;
@@ -1266,13 +1307,15 @@ static VALUE path(VALUE self)
1266
1307
  }
1267
1308
 
1268
1309
  /* :nodoc: */
1269
- static VALUE add_next_sibling(VALUE self, VALUE new_sibling)
1310
+ static VALUE
1311
+ add_next_sibling(VALUE self, VALUE new_sibling)
1270
1312
  {
1271
1313
  return reparent_node_with(self, new_sibling, xmlAddNextSibling) ;
1272
1314
  }
1273
1315
 
1274
1316
  /* :nodoc: */
1275
- static VALUE add_previous_sibling(VALUE self, VALUE new_sibling)
1317
+ static VALUE
1318
+ add_previous_sibling(VALUE self, VALUE new_sibling)
1276
1319
  {
1277
1320
  return reparent_node_with(self, new_sibling, xmlAddPrevSibling) ;
1278
1321
  }
@@ -1283,7 +1326,8 @@ static VALUE add_previous_sibling(VALUE self, VALUE new_sibling)
1283
1326
  *
1284
1327
  * Write this Node to +io+ with +encoding+ and +options+
1285
1328
  */
1286
- static VALUE native_write_to(
1329
+ static VALUE
1330
+ native_write_to(
1287
1331
  VALUE self,
1288
1332
  VALUE io,
1289
1333
  VALUE encoding,
@@ -1292,7 +1336,7 @@ static VALUE native_write_to(
1292
1336
  )
1293
1337
  {
1294
1338
  xmlNodePtr node;
1295
- const char * before_indent;
1339
+ const char *before_indent;
1296
1340
  xmlSaveCtxtPtr savectx;
1297
1341
 
1298
1342
  Data_Get_Struct(self, xmlNode, node);
@@ -1304,8 +1348,8 @@ static VALUE native_write_to(
1304
1348
  xmlTreeIndentString = StringValueCStr(indent_string);
1305
1349
 
1306
1350
  savectx = xmlSaveToIO(
1307
- (xmlOutputWriteCallback)io_write_callback,
1308
- (xmlOutputCloseCallback)io_close_callback,
1351
+ (xmlOutputWriteCallback)noko_io_write,
1352
+ (xmlOutputCloseCallback)noko_io_close,
1309
1353
  (void *)io,
1310
1354
  RTEST(encoding) ? StringValueCStr(encoding) : NULL,
1311
1355
  (int)NUM2INT(options)
@@ -1324,7 +1368,8 @@ static VALUE native_write_to(
1324
1368
  *
1325
1369
  * Returns the line for this Node
1326
1370
  */
1327
- static VALUE line(VALUE self)
1371
+ static VALUE
1372
+ line(VALUE self)
1328
1373
  {
1329
1374
  xmlNodePtr node;
1330
1375
  Data_Get_Struct(self, xmlNode, node);
@@ -1338,12 +1383,13 @@ static VALUE line(VALUE self)
1338
1383
  *
1339
1384
  * Sets the line for this Node. num must be less than 65535.
1340
1385
  */
1341
- static VALUE set_line(VALUE self, VALUE num)
1386
+ static VALUE
1387
+ set_line(VALUE self, VALUE num)
1342
1388
  {
1343
1389
  xmlNodePtr node;
1344
- Data_Get_Struct(self, xmlNode, node);
1345
-
1346
1390
  int value = NUM2INT(num);
1391
+
1392
+ Data_Get_Struct(self, xmlNode, node);
1347
1393
  if (value < 65535) {
1348
1394
  node->line = value;
1349
1395
  }
@@ -1362,45 +1408,47 @@ static VALUE set_line(VALUE self, VALUE num)
1362
1408
  * show up in #attributes, but they will be included as an xmlns attribute
1363
1409
  * when the node is serialized to XML.
1364
1410
  */
1365
- static VALUE add_namespace_definition(VALUE self, VALUE prefix, VALUE href)
1411
+ static VALUE
1412
+ add_namespace_definition(VALUE rb_node, VALUE rb_prefix, VALUE rb_href)
1366
1413
  {
1367
- xmlNodePtr node, namespace;
1368
- xmlNsPtr ns;
1414
+ xmlNodePtr c_node, element;
1415
+ xmlNsPtr c_namespace;
1416
+ const xmlChar *c_prefix = (const xmlChar *)(NIL_P(rb_prefix) ? NULL : StringValueCStr(rb_prefix));
1369
1417
 
1370
- Data_Get_Struct(self, xmlNode, node);
1371
- namespace = node ;
1418
+ Data_Get_Struct(rb_node, xmlNode, c_node);
1419
+ element = c_node ;
1372
1420
 
1373
- ns = xmlSearchNs(
1374
- node->doc,
1375
- node,
1376
- (const xmlChar *)(NIL_P(prefix) ? NULL : StringValueCStr(prefix))
1377
- );
1421
+ c_namespace = xmlSearchNs(c_node->doc, c_node, c_prefix);
1378
1422
 
1379
- if(!ns) {
1380
- if (node->type != XML_ELEMENT_NODE) {
1381
- namespace = node->parent;
1423
+ if (!c_namespace) {
1424
+ if (c_node->type != XML_ELEMENT_NODE) {
1425
+ element = c_node->parent;
1382
1426
  }
1383
- ns = xmlNewNs(
1384
- namespace,
1385
- (const xmlChar *)StringValueCStr(href),
1386
- (const xmlChar *)(NIL_P(prefix) ? NULL : StringValueCStr(prefix))
1387
- );
1427
+ c_namespace = xmlNewNs(element, (const xmlChar *)StringValueCStr(rb_href), c_prefix);
1388
1428
  }
1389
1429
 
1390
- if (!ns) { return Qnil ; }
1430
+ if (!c_namespace) {
1431
+ return Qnil ;
1432
+ }
1391
1433
 
1392
- if(NIL_P(prefix) || node != namespace) { xmlSetNs(node, ns); }
1434
+ if (NIL_P(rb_prefix) || c_node != element) {
1435
+ xmlSetNs(c_node, c_namespace);
1436
+ }
1393
1437
 
1394
- return Nokogiri_wrap_xml_namespace(node->doc, ns);
1438
+ return noko_xml_namespace_wrap(c_namespace, c_node->doc);
1395
1439
  }
1396
1440
 
1397
1441
  /*
1398
- * call-seq:
1399
- * new(name, document)
1400
- *
1401
- * Create a new node with +name+ sharing GC lifecycle with +document+
1442
+ * @overload new(name, document)
1443
+ * Create a new node with +name+ sharing GC lifecycle with +document+.
1444
+ * @param name [String]
1445
+ * @param document [Nokogiri::XML::Document]
1446
+ * @yieldparam node [Nokogiri::XML::Node]
1447
+ * @return [Nokogiri::XML::Node]
1448
+ * @see Nokogiri::XML::Node#initialize
1402
1449
  */
1403
- static VALUE new(int argc, VALUE *argv, VALUE klass)
1450
+ static VALUE
1451
+ rb_xml_node_new(int argc, VALUE *argv, VALUE klass)
1404
1452
  {
1405
1453
  xmlDocPtr doc;
1406
1454
  xmlNodePtr node;
@@ -1415,15 +1463,15 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
1415
1463
 
1416
1464
  node = xmlNewNode(NULL, (xmlChar *)StringValueCStr(name));
1417
1465
  node->doc = doc->doc;
1418
- nokogiri_root_node(node);
1466
+ noko_xml_document_pin_node(node);
1419
1467
 
1420
- rb_node = Nokogiri_wrap_xml_node(
1468
+ rb_node = noko_xml_node_wrap(
1421
1469
  klass == cNokogiriXmlNode ? (VALUE)NULL : klass,
1422
1470
  node
1423
1471
  );
1424
1472
  rb_obj_call_init(rb_node, argc, argv);
1425
1473
 
1426
- if(rb_block_given_p()) { rb_yield(rb_node); }
1474
+ if (rb_block_given_p()) { rb_yield(rb_node); }
1427
1475
 
1428
1476
  return rb_node;
1429
1477
  }
@@ -1434,7 +1482,8 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
1434
1482
  *
1435
1483
  * Returns the Node as html.
1436
1484
  */
1437
- static VALUE dump_html(VALUE self)
1485
+ static VALUE
1486
+ dump_html(VALUE self)
1438
1487
  {
1439
1488
  xmlBufferPtr buf ;
1440
1489
  xmlNodePtr node ;
@@ -1455,7 +1504,8 @@ static VALUE dump_html(VALUE self)
1455
1504
  *
1456
1505
  * Compare this Node to +other+ with respect to their Document
1457
1506
  */
1458
- static VALUE compare(VALUE self, VALUE _other)
1507
+ static VALUE
1508
+ compare(VALUE self, VALUE _other)
1459
1509
  {
1460
1510
  xmlNodePtr node, other;
1461
1511
  Data_Get_Struct(self, xmlNode, node);
@@ -1472,7 +1522,8 @@ static VALUE compare(VALUE self, VALUE _other)
1472
1522
  * Loads and substitutes all xinclude elements below the node. The
1473
1523
  * parser context will be initialized with +options+.
1474
1524
  */
1475
- static VALUE process_xincludes(VALUE self, VALUE options)
1525
+ static VALUE
1526
+ process_xincludes(VALUE self, VALUE options)
1476
1527
  {
1477
1528
  int rcode ;
1478
1529
  xmlNodePtr node;
@@ -1488,7 +1539,7 @@ static VALUE process_xincludes(VALUE self, VALUE options)
1488
1539
  xmlErrorPtr error;
1489
1540
 
1490
1541
  error = xmlGetLastError();
1491
- if(error) {
1542
+ if (error) {
1492
1543
  rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
1493
1544
  } else {
1494
1545
  rb_raise(rb_eRuntimeError, "Could not perform xinclude substitution");
@@ -1500,7 +1551,8 @@ static VALUE process_xincludes(VALUE self, VALUE options)
1500
1551
 
1501
1552
 
1502
1553
  /* TODO: DOCUMENT ME */
1503
- static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
1554
+ static VALUE
1555
+ in_context(VALUE self, VALUE _str, VALUE _options)
1504
1556
  {
1505
1557
  xmlNodePtr node, list = 0, tmp, child_iter, node_children, doc_children;
1506
1558
  xmlNodeSetPtr set;
@@ -1595,179 +1647,178 @@ static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
1595
1647
  tmp = list->next;
1596
1648
  list->next = NULL;
1597
1649
  xmlXPathNodeSetAddUnique(set, list);
1598
- nokogiri_root_node(list);
1650
+ noko_xml_document_pin_node(list);
1599
1651
  list = tmp;
1600
1652
  }
1601
1653
 
1602
- return Nokogiri_wrap_xml_node_set(set, doc);
1654
+ return noko_xml_node_set_wrap(set, doc);
1603
1655
  }
1604
1656
 
1605
1657
 
1606
- VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
1658
+ VALUE
1659
+ noko_xml_node_wrap(VALUE rb_class, xmlNodePtr c_node)
1607
1660
  {
1608
- VALUE document = Qnil ;
1609
- VALUE node_cache = Qnil ;
1610
- VALUE rb_node = Qnil ;
1661
+ VALUE rb_document, rb_node_cache, rb_node;
1611
1662
  nokogiriTuplePtr node_has_a_document;
1612
- xmlDocPtr doc;
1663
+ xmlDocPtr c_doc;
1613
1664
  void (*mark_method)(xmlNodePtr) = NULL ;
1614
1665
 
1615
- assert(node);
1666
+ assert(c_node);
1616
1667
 
1617
- if(node->type == XML_DOCUMENT_NODE || node->type == XML_HTML_DOCUMENT_NODE) {
1618
- return DOC_RUBY_OBJECT(node->doc);
1668
+ if (c_node->type == XML_DOCUMENT_NODE || c_node->type == XML_HTML_DOCUMENT_NODE) {
1669
+ return DOC_RUBY_OBJECT(c_node->doc);
1619
1670
  }
1620
1671
 
1621
1672
  /* It's OK if the node doesn't have a fully-realized document (as in XML::Reader). */
1622
1673
  /* see https://github.com/sparklemotion/nokogiri/issues/95 */
1623
1674
  /* and https://github.com/sparklemotion/nokogiri/issues/439 */
1624
- doc = node->doc;
1625
- if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
1626
- node_has_a_document = DOC_RUBY_OBJECT_TEST(doc);
1675
+ c_doc = c_node->doc;
1676
+ if (c_doc->type == XML_DOCUMENT_FRAG_NODE) { c_doc = c_doc->doc; }
1677
+ node_has_a_document = DOC_RUBY_OBJECT_TEST(c_doc);
1627
1678
 
1628
- if(node->_private && node_has_a_document) {
1629
- return (VALUE)node->_private;
1679
+ if (c_node->_private && node_has_a_document) {
1680
+ return (VALUE)c_node->_private;
1630
1681
  }
1631
1682
 
1632
- if(!RTEST(klass)) {
1633
- switch(node->type) {
1683
+ if (!RTEST(rb_class)) {
1684
+ switch (c_node->type) {
1634
1685
  case XML_ELEMENT_NODE:
1635
- klass = cNokogiriXmlElement;
1686
+ rb_class = cNokogiriXmlElement;
1636
1687
  break;
1637
1688
  case XML_TEXT_NODE:
1638
- klass = cNokogiriXmlText;
1689
+ rb_class = cNokogiriXmlText;
1639
1690
  break;
1640
1691
  case XML_ATTRIBUTE_NODE:
1641
- klass = cNokogiriXmlAttr;
1692
+ rb_class = cNokogiriXmlAttr;
1642
1693
  break;
1643
1694
  case XML_ENTITY_REF_NODE:
1644
- klass = cNokogiriXmlEntityReference;
1695
+ rb_class = cNokogiriXmlEntityReference;
1645
1696
  break;
1646
1697
  case XML_COMMENT_NODE:
1647
- klass = cNokogiriXmlComment;
1698
+ rb_class = cNokogiriXmlComment;
1648
1699
  break;
1649
1700
  case XML_DOCUMENT_FRAG_NODE:
1650
- klass = cNokogiriXmlDocumentFragment;
1701
+ rb_class = cNokogiriXmlDocumentFragment;
1651
1702
  break;
1652
1703
  case XML_PI_NODE:
1653
- klass = cNokogiriXmlProcessingInstruction;
1704
+ rb_class = cNokogiriXmlProcessingInstruction;
1654
1705
  break;
1655
1706
  case XML_ENTITY_DECL:
1656
- klass = cNokogiriXmlEntityDecl;
1707
+ rb_class = cNokogiriXmlEntityDecl;
1657
1708
  break;
1658
1709
  case XML_CDATA_SECTION_NODE:
1659
- klass = cNokogiriXmlCData;
1710
+ rb_class = cNokogiriXmlCData;
1660
1711
  break;
1661
1712
  case XML_DTD_NODE:
1662
- klass = cNokogiriXmlDtd;
1713
+ rb_class = cNokogiriXmlDtd;
1663
1714
  break;
1664
1715
  case XML_ATTRIBUTE_DECL:
1665
- klass = cNokogiriXmlAttributeDecl;
1716
+ rb_class = cNokogiriXmlAttributeDecl;
1666
1717
  break;
1667
1718
  case XML_ELEMENT_DECL:
1668
- klass = cNokogiriXmlElementDecl;
1719
+ rb_class = cNokogiriXmlElementDecl;
1669
1720
  break;
1670
1721
  default:
1671
- klass = cNokogiriXmlNode;
1722
+ rb_class = cNokogiriXmlNode;
1672
1723
  }
1673
1724
  }
1674
1725
 
1675
1726
  mark_method = node_has_a_document ? mark : NULL ;
1676
1727
 
1677
- rb_node = Data_Wrap_Struct(klass, mark_method, debug_node_dealloc, node) ;
1678
- node->_private = (void *)rb_node;
1728
+ rb_node = Data_Wrap_Struct(rb_class, mark_method, debug_node_dealloc, c_node) ;
1729
+ c_node->_private = (void *)rb_node;
1679
1730
 
1680
1731
  if (node_has_a_document) {
1681
- document = DOC_RUBY_OBJECT(doc);
1682
- node_cache = DOC_NODE_CACHE(doc);
1683
- rb_ary_push(node_cache, rb_node);
1684
- rb_funcall(document, decorate, 1, rb_node);
1732
+ rb_document = DOC_RUBY_OBJECT(c_doc);
1733
+ rb_node_cache = DOC_NODE_CACHE(c_doc);
1734
+ rb_ary_push(rb_node_cache, rb_node);
1735
+ rb_funcall(rb_document, id_decorate, 1, rb_node);
1685
1736
  }
1686
1737
 
1687
1738
  return rb_node ;
1688
1739
  }
1689
1740
 
1690
1741
 
1691
- void Nokogiri_xml_node_properties(xmlNodePtr node, VALUE attr_list)
1742
+ /*
1743
+ * return Array<Nokogiri::XML::Attr> containing the node's attributes
1744
+ */
1745
+ VALUE
1746
+ noko_xml_node_attrs(xmlNodePtr c_node)
1692
1747
  {
1693
- xmlAttrPtr prop;
1694
- prop = node->properties ;
1695
- while (prop != NULL) {
1696
- rb_ary_push(attr_list, Nokogiri_wrap_xml_node(Qnil, (xmlNodePtr)prop));
1697
- prop = prop->next ;
1748
+ VALUE rb_properties = rb_ary_new();
1749
+ xmlAttrPtr c_property;
1750
+
1751
+ c_property = c_node->properties ;
1752
+ while (c_property != NULL) {
1753
+ rb_ary_push(rb_properties, noko_xml_node_wrap(Qnil, (xmlNodePtr)c_property));
1754
+ c_property = c_property->next ;
1698
1755
  }
1699
- }
1700
1756
 
1701
- VALUE cNokogiriXmlNode ;
1702
- VALUE cNokogiriXmlElement ;
1757
+ return rb_properties;
1758
+ }
1703
1759
 
1704
- void init_xml_node()
1760
+ void
1761
+ noko_init_xml_node()
1705
1762
  {
1706
- VALUE nokogiri = rb_define_module("Nokogiri");
1707
- VALUE xml = rb_define_module_under(nokogiri, "XML");
1708
- VALUE klass = rb_define_class_under(xml, "Node", rb_cObject);
1709
-
1710
- cNokogiriXmlNode = klass;
1711
-
1712
- cNokogiriXmlElement = rb_define_class_under(xml, "Element", klass);
1713
-
1714
- rb_define_singleton_method(klass, "new", new, -1);
1715
-
1716
- rb_define_method(klass, "add_namespace_definition", add_namespace_definition, 2);
1717
- rb_define_method(klass, "node_name", get_name, 0);
1718
- rb_define_method(klass, "document", document, 0);
1719
- rb_define_method(klass, "node_name=", set_name, 1);
1720
- rb_define_method(klass, "parent", get_parent, 0);
1721
- rb_define_method(klass, "child", child, 0);
1722
- rb_define_method(klass, "first_element_child", first_element_child, 0);
1723
- rb_define_method(klass, "last_element_child", last_element_child, 0);
1724
- rb_define_method(klass, "children", children, 0);
1725
- rb_define_method(klass, "element_children", element_children, 0);
1726
- rb_define_method(klass, "next_sibling", next_sibling, 0);
1727
- rb_define_method(klass, "previous_sibling", previous_sibling, 0);
1728
- rb_define_method(klass, "next_element", next_element, 0);
1729
- rb_define_method(klass, "previous_element", previous_element, 0);
1730
- rb_define_method(klass, "node_type", node_type, 0);
1731
- rb_define_method(klass, "path", path, 0);
1732
- rb_define_method(klass, "key?", key_eh, 1);
1733
- rb_define_method(klass, "namespaced_key?", namespaced_key_eh, 2);
1734
- rb_define_method(klass, "blank?", blank_eh, 0);
1735
- rb_define_method(klass, "attribute_nodes", attribute_nodes, 0);
1736
- rb_define_method(klass, "attribute", attr, 1);
1737
- rb_define_method(klass, "attribute_with_ns", attribute_with_ns, 2);
1738
- rb_define_method(klass, "namespace", namespace, 0);
1739
- rb_define_method(klass, "namespace_definitions", namespace_definitions, 0);
1740
- rb_define_method(klass, "namespace_scopes", namespace_scopes, 0);
1741
- rb_define_method(klass, "encode_special_chars", encode_special_chars, 1);
1742
- rb_define_method(klass, "dup", duplicate_node, -1);
1743
- rb_define_method(klass, "unlink", unlink_node, 0);
1744
- rb_define_method(klass, "internal_subset", internal_subset, 0);
1745
- rb_define_method(klass, "external_subset", external_subset, 0);
1746
- rb_define_method(klass, "create_internal_subset", create_internal_subset, 3);
1747
- rb_define_method(klass, "create_external_subset", create_external_subset, 3);
1748
- rb_define_method(klass, "pointer_id", pointer_id, 0);
1749
- rb_define_method(klass, "line", line, 0);
1750
- rb_define_method(klass, "line=", set_line, 1);
1751
- rb_define_method(klass, "content", get_native_content, 0);
1752
- rb_define_method(klass, "native_content=", set_native_content, 1);
1753
- rb_define_method(klass, "lang", get_lang, 0);
1754
- rb_define_method(klass, "lang=", set_lang, 1);
1755
-
1756
- rb_define_private_method(klass, "process_xincludes", process_xincludes, 1);
1757
- rb_define_private_method(klass, "in_context", in_context, 2);
1758
- rb_define_private_method(klass, "add_child_node", add_child, 1);
1759
- rb_define_private_method(klass, "add_previous_sibling_node", add_previous_sibling, 1);
1760
- rb_define_private_method(klass, "add_next_sibling_node", add_next_sibling, 1);
1761
- rb_define_private_method(klass, "replace_node", replace, 1);
1762
- rb_define_private_method(klass, "dump_html", dump_html, 0);
1763
- rb_define_private_method(klass, "native_write_to", native_write_to, 4);
1764
- rb_define_private_method(klass, "get", get, 1);
1765
- rb_define_private_method(klass, "set", set, 2);
1766
- rb_define_private_method(klass, "set_namespace", set_namespace, 1);
1767
- rb_define_private_method(klass, "compare", compare, 1);
1768
-
1769
- decorate = rb_intern("decorate");
1770
- decorate_bang = rb_intern("decorate!");
1763
+ cNokogiriXmlNode = rb_define_class_under(mNokogiriXml, "Node", rb_cObject);
1764
+
1765
+ rb_define_singleton_method(cNokogiriXmlNode, "new", rb_xml_node_new, -1);
1766
+
1767
+ rb_define_method(cNokogiriXmlNode, "add_namespace_definition", add_namespace_definition, 2);
1768
+ rb_define_method(cNokogiriXmlNode, "node_name", get_name, 0);
1769
+ rb_define_method(cNokogiriXmlNode, "document", document, 0);
1770
+ rb_define_method(cNokogiriXmlNode, "node_name=", set_name, 1);
1771
+ rb_define_method(cNokogiriXmlNode, "parent", get_parent, 0);
1772
+ rb_define_method(cNokogiriXmlNode, "child", child, 0);
1773
+ rb_define_method(cNokogiriXmlNode, "first_element_child", first_element_child, 0);
1774
+ rb_define_method(cNokogiriXmlNode, "last_element_child", last_element_child, 0);
1775
+ rb_define_method(cNokogiriXmlNode, "children", children, 0);
1776
+ rb_define_method(cNokogiriXmlNode, "element_children", element_children, 0);
1777
+ rb_define_method(cNokogiriXmlNode, "next_sibling", next_sibling, 0);
1778
+ rb_define_method(cNokogiriXmlNode, "previous_sibling", previous_sibling, 0);
1779
+ rb_define_method(cNokogiriXmlNode, "next_element", next_element, 0);
1780
+ rb_define_method(cNokogiriXmlNode, "previous_element", previous_element, 0);
1781
+ rb_define_method(cNokogiriXmlNode, "node_type", node_type, 0);
1782
+ rb_define_method(cNokogiriXmlNode, "path", path, 0);
1783
+ rb_define_method(cNokogiriXmlNode, "key?", key_eh, 1);
1784
+ rb_define_method(cNokogiriXmlNode, "namespaced_key?", namespaced_key_eh, 2);
1785
+ rb_define_method(cNokogiriXmlNode, "blank?", blank_eh, 0);
1786
+ rb_define_method(cNokogiriXmlNode, "attribute_nodes", attribute_nodes, 0);
1787
+ rb_define_method(cNokogiriXmlNode, "attribute", attr, 1);
1788
+ rb_define_method(cNokogiriXmlNode, "attribute_with_ns", attribute_with_ns, 2);
1789
+ rb_define_method(cNokogiriXmlNode, "namespace", noko_xml_node_namespace, 0);
1790
+ rb_define_method(cNokogiriXmlNode, "namespace_definitions", namespace_definitions, 0);
1791
+ rb_define_method(cNokogiriXmlNode, "namespace_scopes", namespace_scopes, 0);
1792
+ rb_define_method(cNokogiriXmlNode, "encode_special_chars", encode_special_chars, 1);
1793
+ rb_define_method(cNokogiriXmlNode, "dup", duplicate_node, -1);
1794
+ rb_define_method(cNokogiriXmlNode, "unlink", unlink_node, 0);
1795
+ rb_define_method(cNokogiriXmlNode, "internal_subset", internal_subset, 0);
1796
+ rb_define_method(cNokogiriXmlNode, "external_subset", external_subset, 0);
1797
+ rb_define_method(cNokogiriXmlNode, "create_internal_subset", create_internal_subset, 3);
1798
+ rb_define_method(cNokogiriXmlNode, "create_external_subset", create_external_subset, 3);
1799
+ rb_define_method(cNokogiriXmlNode, "pointer_id", pointer_id, 0);
1800
+ rb_define_method(cNokogiriXmlNode, "line", line, 0);
1801
+ rb_define_method(cNokogiriXmlNode, "line=", set_line, 1);
1802
+ rb_define_method(cNokogiriXmlNode, "content", get_native_content, 0);
1803
+ rb_define_method(cNokogiriXmlNode, "native_content=", set_native_content, 1);
1804
+ rb_define_method(cNokogiriXmlNode, "lang", get_lang, 0);
1805
+ rb_define_method(cNokogiriXmlNode, "lang=", set_lang, 1);
1806
+
1807
+ rb_define_private_method(cNokogiriXmlNode, "process_xincludes", process_xincludes, 1);
1808
+ rb_define_private_method(cNokogiriXmlNode, "in_context", in_context, 2);
1809
+ rb_define_private_method(cNokogiriXmlNode, "add_child_node", add_child, 1);
1810
+ rb_define_private_method(cNokogiriXmlNode, "add_previous_sibling_node", add_previous_sibling, 1);
1811
+ rb_define_private_method(cNokogiriXmlNode, "add_next_sibling_node", add_next_sibling, 1);
1812
+ rb_define_private_method(cNokogiriXmlNode, "replace_node", replace, 1);
1813
+ rb_define_private_method(cNokogiriXmlNode, "dump_html", dump_html, 0);
1814
+ rb_define_private_method(cNokogiriXmlNode, "native_write_to", native_write_to, 4);
1815
+ rb_define_private_method(cNokogiriXmlNode, "get", get, 1);
1816
+ rb_define_private_method(cNokogiriXmlNode, "set", set, 2);
1817
+ rb_define_private_method(cNokogiriXmlNode, "set_namespace", set_namespace, 1);
1818
+ rb_define_private_method(cNokogiriXmlNode, "compare", compare, 1);
1819
+
1820
+ id_decorate = rb_intern("decorate");
1821
+ id_decorate_bang = rb_intern("decorate!");
1771
1822
  }
1772
1823
 
1773
1824
  /* vim: set noet sw=4 sws=4 */