nokogiri 1.2.3-java → 1.3.0-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 (200) hide show
  1. data/.autotest +14 -2
  2. data/CHANGELOG.ja.rdoc +38 -0
  3. data/CHANGELOG.rdoc +43 -0
  4. data/Manifest.txt +80 -5
  5. data/README.ja.rdoc +12 -11
  6. data/README.rdoc +4 -2
  7. data/Rakefile +103 -173
  8. data/bin/nokogiri +47 -0
  9. data/ext/nokogiri/extconf.rb +19 -13
  10. data/ext/nokogiri/html_document.c +39 -3
  11. data/ext/nokogiri/html_document.h +1 -1
  12. data/ext/nokogiri/html_element_description.c +272 -0
  13. data/ext/nokogiri/html_element_description.h +10 -0
  14. data/ext/nokogiri/html_entity_lookup.h +1 -1
  15. data/ext/nokogiri/html_sax_parser.h +1 -1
  16. data/ext/nokogiri/{native.c → nokogiri.c} +11 -3
  17. data/ext/nokogiri/{native.h → nokogiri.h} +18 -4
  18. data/ext/nokogiri/xml_attr.c +14 -5
  19. data/ext/nokogiri/xml_attr.h +1 -1
  20. data/ext/nokogiri/xml_cdata.c +15 -6
  21. data/ext/nokogiri/xml_cdata.h +1 -1
  22. data/ext/nokogiri/xml_comment.c +13 -4
  23. data/ext/nokogiri/xml_comment.h +1 -1
  24. data/ext/nokogiri/xml_document.c +50 -41
  25. data/ext/nokogiri/xml_document.h +1 -1
  26. data/ext/nokogiri/xml_document_fragment.c +12 -4
  27. data/ext/nokogiri/xml_document_fragment.h +1 -1
  28. data/ext/nokogiri/xml_dtd.c +1 -1
  29. data/ext/nokogiri/xml_dtd.h +1 -1
  30. data/ext/nokogiri/xml_entity_reference.c +13 -4
  31. data/ext/nokogiri/xml_entity_reference.h +1 -1
  32. data/ext/nokogiri/xml_io.h +1 -1
  33. data/ext/nokogiri/xml_namespace.c +69 -0
  34. data/ext/nokogiri/xml_namespace.h +12 -0
  35. data/ext/nokogiri/xml_node.c +232 -124
  36. data/ext/nokogiri/xml_node.h +3 -4
  37. data/ext/nokogiri/xml_node_set.c +204 -17
  38. data/ext/nokogiri/xml_node_set.h +1 -1
  39. data/ext/nokogiri/xml_processing_instruction.c +14 -4
  40. data/ext/nokogiri/xml_processing_instruction.h +1 -1
  41. data/ext/nokogiri/xml_reader.c +87 -7
  42. data/ext/nokogiri/xml_reader.h +1 -1
  43. data/ext/nokogiri/xml_relax_ng.c +106 -0
  44. data/ext/nokogiri/xml_relax_ng.h +9 -0
  45. data/ext/nokogiri/xml_sax_parser.c +122 -2
  46. data/ext/nokogiri/xml_sax_parser.h +1 -1
  47. data/ext/nokogiri/xml_sax_push_parser.c +1 -0
  48. data/ext/nokogiri/xml_sax_push_parser.h +1 -1
  49. data/ext/nokogiri/xml_schema.c +107 -0
  50. data/ext/nokogiri/xml_schema.h +9 -0
  51. data/ext/nokogiri/xml_syntax_error.h +1 -1
  52. data/ext/nokogiri/xml_text.c +10 -3
  53. data/ext/nokogiri/xml_text.h +1 -1
  54. data/ext/nokogiri/xml_xpath.h +1 -1
  55. data/ext/nokogiri/xml_xpath_context.h +1 -1
  56. data/ext/nokogiri/xslt_stylesheet.c +29 -16
  57. data/ext/nokogiri/xslt_stylesheet.h +1 -1
  58. data/lib/action-nokogiri.rb +7 -1
  59. data/lib/nokogiri.rb +21 -5
  60. data/lib/nokogiri/css/generated_parser.rb +49 -14
  61. data/lib/nokogiri/css/generated_tokenizer.rb +2 -2
  62. data/lib/nokogiri/css/node.rb +13 -3
  63. data/lib/nokogiri/css/parser.rb +8 -0
  64. data/lib/nokogiri/css/parser.y +7 -7
  65. data/lib/nokogiri/css/tokenizer.rb +2 -0
  66. data/lib/nokogiri/css/xpath_visitor.rb +10 -6
  67. data/lib/nokogiri/decorators/hpricot/node.rb +1 -1
  68. data/lib/nokogiri/decorators/hpricot/node_set.rb +2 -2
  69. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +2 -0
  70. data/lib/nokogiri/decorators/slop.rb +3 -1
  71. data/lib/nokogiri/ffi/html/document.rb +37 -0
  72. data/lib/nokogiri/ffi/html/element_description.rb +85 -0
  73. data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
  74. data/lib/nokogiri/ffi/html/sax/parser.rb +21 -0
  75. data/lib/nokogiri/ffi/io_callbacks.rb +32 -0
  76. data/lib/nokogiri/ffi/libxml.rb +314 -0
  77. data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
  78. data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
  79. data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
  80. data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
  81. data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
  82. data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
  83. data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
  84. data/lib/nokogiri/ffi/structs/xml_dtd.rb +26 -0
  85. data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
  86. data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
  87. data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
  88. data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
  89. data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
  90. data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
  91. data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +14 -0
  92. data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
  93. data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
  94. data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
  95. data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
  96. data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
  97. data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
  98. data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
  99. data/lib/nokogiri/ffi/xml/attr.rb +41 -0
  100. data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
  101. data/lib/nokogiri/ffi/xml/comment.rb +18 -0
  102. data/lib/nokogiri/ffi/xml/document.rb +107 -0
  103. data/lib/nokogiri/ffi/xml/document_fragment.rb +26 -0
  104. data/lib/nokogiri/ffi/xml/dtd.rb +42 -0
  105. data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
  106. data/lib/nokogiri/ffi/xml/namespace.rb +38 -0
  107. data/lib/nokogiri/ffi/xml/node.rb +380 -0
  108. data/lib/nokogiri/ffi/xml/node_set.rb +130 -0
  109. data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
  110. data/lib/nokogiri/ffi/xml/reader.rb +217 -0
  111. data/lib/nokogiri/ffi/xml/relax_ng.rb +51 -0
  112. data/lib/nokogiri/ffi/xml/sax/parser.rb +148 -0
  113. data/lib/nokogiri/ffi/xml/sax/push_parser.rb +38 -0
  114. data/lib/nokogiri/ffi/xml/schema.rb +55 -0
  115. data/lib/nokogiri/ffi/xml/syntax_error.rb +76 -0
  116. data/lib/nokogiri/ffi/xml/text.rb +18 -0
  117. data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
  118. data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
  119. data/lib/nokogiri/ffi/xslt/stylesheet.rb +47 -0
  120. data/lib/nokogiri/hpricot.rb +14 -3
  121. data/lib/nokogiri/html.rb +11 -46
  122. data/lib/nokogiri/html/builder.rb +27 -1
  123. data/lib/nokogiri/html/document.rb +62 -6
  124. data/lib/nokogiri/html/document_fragment.rb +15 -0
  125. data/lib/nokogiri/html/element_description.rb +23 -0
  126. data/lib/nokogiri/html/entity_lookup.rb +2 -0
  127. data/lib/nokogiri/html/sax/parser.rb +27 -1
  128. data/lib/nokogiri/version.rb +26 -1
  129. data/lib/nokogiri/version_warning.rb +11 -0
  130. data/lib/nokogiri/xml.rb +25 -51
  131. data/lib/nokogiri/xml/builder.rb +166 -10
  132. data/lib/nokogiri/xml/cdata.rb +3 -1
  133. data/lib/nokogiri/xml/document.rb +39 -6
  134. data/lib/nokogiri/xml/document_fragment.rb +41 -1
  135. data/lib/nokogiri/xml/dtd.rb +3 -1
  136. data/lib/nokogiri/xml/entity_declaration.rb +3 -1
  137. data/lib/nokogiri/xml/fragment_handler.rb +24 -3
  138. data/lib/nokogiri/xml/namespace.rb +7 -0
  139. data/lib/nokogiri/xml/node.rb +314 -65
  140. data/lib/nokogiri/xml/node/save_options.rb +12 -2
  141. data/lib/nokogiri/xml/node_set.rb +58 -8
  142. data/lib/nokogiri/xml/parse_options.rb +80 -0
  143. data/lib/nokogiri/xml/processing_instruction.rb +2 -0
  144. data/lib/nokogiri/xml/reader.rb +42 -3
  145. data/lib/nokogiri/xml/relax_ng.rb +32 -0
  146. data/lib/nokogiri/xml/sax.rb +0 -7
  147. data/lib/nokogiri/xml/sax/document.rb +84 -0
  148. data/lib/nokogiri/xml/sax/parser.rb +38 -2
  149. data/lib/nokogiri/xml/sax/push_parser.rb +12 -0
  150. data/lib/nokogiri/xml/schema.rb +65 -0
  151. data/lib/nokogiri/xml/syntax_error.rb +11 -0
  152. data/lib/nokogiri/xml/xpath.rb +1 -1
  153. data/lib/nokogiri/xml/xpath_context.rb +2 -0
  154. data/lib/nokogiri/xslt.rb +21 -1
  155. data/lib/nokogiri/xslt/stylesheet.rb +19 -0
  156. data/lib/xsd/xmlparser/nokogiri.rb +12 -2
  157. data/tasks/test.rb +42 -19
  158. data/test/css/test_parser.rb +29 -0
  159. data/test/ffi/test_document.rb +35 -0
  160. data/test/files/address_book.rlx +12 -0
  161. data/test/files/address_book.xml +10 -0
  162. data/test/files/po.xml +32 -0
  163. data/test/files/po.xsd +66 -0
  164. data/test/helper.rb +38 -8
  165. data/test/html/sax/test_parser.rb +12 -0
  166. data/test/html/test_builder.rb +25 -2
  167. data/test/html/test_document.rb +91 -20
  168. data/test/html/test_document_fragment.rb +97 -0
  169. data/test/html/test_element_description.rb +95 -0
  170. data/test/html/test_node.rb +66 -3
  171. data/test/test_convert_xpath.rb +1 -1
  172. data/test/test_memory_leak.rb +57 -18
  173. data/test/test_nokogiri.rb +24 -2
  174. data/test/test_reader.rb +77 -0
  175. data/test/test_xslt_transforms.rb +120 -82
  176. data/test/xml/node/test_subclass.rb +44 -0
  177. data/test/xml/sax/test_parser.rb +9 -0
  178. data/test/xml/sax/test_push_parser.rb +24 -0
  179. data/test/xml/test_attr.rb +7 -0
  180. data/test/xml/test_builder.rb +48 -0
  181. data/test/xml/test_cdata.rb +19 -0
  182. data/test/xml/test_comment.rb +6 -0
  183. data/test/xml/test_document.rb +101 -2
  184. data/test/xml/test_document_fragment.rb +55 -3
  185. data/test/xml/test_entity_reference.rb +4 -0
  186. data/test/xml/test_namespace.rb +43 -0
  187. data/test/xml/test_node.rb +255 -8
  188. data/test/xml/test_node_attributes.rb +34 -0
  189. data/test/xml/test_node_encoding.rb +9 -2
  190. data/test/xml/test_node_set.rb +197 -1
  191. data/test/xml/test_parse_options.rb +52 -0
  192. data/test/xml/test_processing_instruction.rb +5 -0
  193. data/test/xml/test_relax_ng.rb +60 -0
  194. data/test/xml/test_schema.rb +65 -0
  195. data/test/xml/test_text.rb +5 -0
  196. data/test/xml/test_unparented_node.rb +3 -3
  197. metadata +129 -13
  198. data/lib/nokogiri/xml/comment.rb +0 -6
  199. data/lib/nokogiri/xml/element.rb +0 -6
  200. data/lib/nokogiri/xml/text.rb +0 -6
@@ -0,0 +1,10 @@
1
+ #ifndef NOKOGIRI_HTML_ELEMENT_DESCRIPTION
2
+ #define NOKOGIRI_HTML_ELEMENT_DESCRIPTION
3
+
4
+ #include <nokogiri.h>
5
+
6
+ void init_html_element_description();
7
+
8
+ extern VALUE cNokogiriHtmlElementDescription ;
9
+
10
+ #endif
@@ -1,7 +1,7 @@
1
1
  #ifndef NOKOGIRI_HTML_ENTITY_LOOKUP
2
2
  #define NOKOGIRI_HTML_ENTITY_LOOKUP
3
3
 
4
- #include <native.h>
4
+ #include <nokogiri.h>
5
5
 
6
6
  void init_html_entity_lookup();
7
7
 
@@ -1,7 +1,7 @@
1
1
  #ifndef NOKOGIRI_HTML_SAX_PARSER
2
2
  #define NOKOGIRI_HTML_SAX_PARSER
3
3
 
4
- #include <native.h>
4
+ #include <nokogiri.h>
5
5
 
6
6
  void init_html_sax_parser();
7
7
 
@@ -1,4 +1,4 @@
1
- #include <native.h>
1
+ #include <nokogiri.h>
2
2
 
3
3
  VALUE mNokogiri ;
4
4
  VALUE mNokogiriXml ;
@@ -7,7 +7,7 @@ VALUE mNokogiriXslt ;
7
7
  VALUE mNokogiriXmlSax ;
8
8
  VALUE mNokogiriHtmlSax ;
9
9
 
10
- #ifdef XP_WIN
10
+ #ifdef USE_INCLUDED_VASPRINTF
11
11
  /*
12
12
  * I srsly hate windows. it doesn't have vasprintf.
13
13
  * Thank you Geoffroy Couprie for this implementation of vasprintf!
@@ -23,8 +23,12 @@ int vasprintf (char **strp, const char *fmt, va_list ap)
23
23
  }
24
24
  #endif
25
25
 
26
+ int is_2_6_16(void)
27
+ {
28
+ return (strcmp(xmlParserVersion, "20616") <= 0) ? 1 : 0 ;
29
+ }
26
30
 
27
- void Init_native()
31
+ void Init_nokogiri()
28
32
  {
29
33
  xmlMemSetup(
30
34
  (xmlFreeFunc)ruby_xfree,
@@ -66,8 +70,12 @@ void Init_native()
66
70
  init_xml_sax_push_parser();
67
71
  init_xml_reader();
68
72
  init_xml_dtd();
73
+ init_xml_namespace();
69
74
  init_html_sax_parser();
70
75
  init_xslt_stylesheet();
71
76
  init_xml_syntax_error();
72
77
  init_html_entity_lookup();
78
+ init_html_element_description();
79
+ init_xml_schema();
80
+ init_xml_relax_ng();
73
81
  }
@@ -9,9 +9,23 @@
9
9
  #include <libxml/xpathInternals.h>
10
10
  #include <libxml/xmlreader.h>
11
11
  #include <libxml/xmlsave.h>
12
+ #include <libxml/xmlschemas.h>
12
13
  #include <libxml/HTMLparser.h>
13
14
  #include <libxml/HTMLtree.h>
14
15
 
16
+ #ifdef USE_INCLUDED_VASPRINTF
17
+ int vasprintf (char **strp, const char *fmt, va_list ap);
18
+ #else
19
+
20
+ #ifndef _GNU_SOURCE
21
+ #define _GNU_SOURCE
22
+ #endif
23
+
24
+ # include <stdio.h>
25
+
26
+ #endif
27
+
28
+ int is_2_6_16(void) ;
15
29
 
16
30
  #ifndef UNUSED
17
31
  # if defined(__GNUC__)
@@ -62,10 +76,6 @@
62
76
  rb_str_new((const char *)str, (long)len)
63
77
  #endif
64
78
 
65
- #ifdef XP_WIN
66
- int vasprintf (char **strp, const char *fmt, va_list ap);
67
- #endif
68
-
69
79
  #include <xml_io.h>
70
80
  #include <xml_document.h>
71
81
  #include <html_entity_lookup.h>
@@ -88,6 +98,10 @@ int vasprintf (char **strp, const char *fmt, va_list ap);
88
98
  #include <html_sax_parser.h>
89
99
  #include <xslt_stylesheet.h>
90
100
  #include <xml_syntax_error.h>
101
+ #include <xml_schema.h>
102
+ #include <xml_relax_ng.h>
103
+ #include <html_element_description.h>
104
+ #include <xml_namespace.h>
91
105
 
92
106
  extern VALUE mNokogiri ;
93
107
  extern VALUE mNokogiriXml ;
@@ -42,14 +42,20 @@ static VALUE set_value(VALUE self, VALUE content)
42
42
 
43
43
  /*
44
44
  * call-seq:
45
- * new(document, content)
45
+ * new(document, name)
46
46
  *
47
47
  * Create a new Attr element on the +document+ with +name+
48
48
  */
49
- static VALUE new(VALUE klass, VALUE doc, VALUE name)
49
+ static VALUE new(int argc, VALUE *argv, VALUE klass)
50
50
  {
51
51
  xmlDocPtr xml_doc;
52
- Data_Get_Struct(doc, xmlDoc, xml_doc);
52
+ VALUE document;
53
+ VALUE name;
54
+ VALUE rest;
55
+
56
+ rb_scan_args(argc, argv, "2*", &document, &name, &rest);
57
+
58
+ Data_Get_Struct(document, xmlDoc, xml_doc);
53
59
 
54
60
  xmlAttrPtr node = xmlNewDocProp(
55
61
  xml_doc,
@@ -57,7 +63,10 @@ static VALUE new(VALUE klass, VALUE doc, VALUE name)
57
63
  NULL
58
64
  );
59
65
 
60
- VALUE rb_node = Nokogiri_wrap_xml_node((xmlNodePtr)node);
66
+ NOKOGIRI_ROOT_NODE((xmlNodePtr)node);
67
+
68
+ VALUE rb_node = Nokogiri_wrap_xml_node(klass, (xmlNodePtr)node);
69
+ rb_funcall2(rb_node, rb_intern("initialize"), argc, argv);
61
70
 
62
71
  if(rb_block_given_p()) rb_yield(rb_node);
63
72
 
@@ -78,6 +87,6 @@ void init_xml_attr()
78
87
 
79
88
  cNokogiriXmlAttr = klass;
80
89
 
81
- rb_define_singleton_method(klass, "new", new, 2);
90
+ rb_define_singleton_method(klass, "new", new, -1);
82
91
  rb_define_method(klass, "value=", set_value, 1);
83
92
  }
@@ -1,7 +1,7 @@
1
1
  #ifndef NOKOGIRI_XML_ATTR
2
2
  #define NOKOGIRI_XML_ATTR
3
3
 
4
- #include <native.h>
4
+ #include <nokogiri.h>
5
5
 
6
6
  void init_xml_attr();
7
7
 
@@ -6,18 +6,27 @@
6
6
  *
7
7
  * Create a new CData element on the +document+ with +content+
8
8
  */
9
- static VALUE new(VALUE klass, VALUE doc, VALUE content)
9
+ static VALUE new(int argc, VALUE *argv, VALUE klass)
10
10
  {
11
11
  xmlDocPtr xml_doc;
12
+ VALUE doc;
13
+ VALUE content;
14
+ VALUE rest;
15
+
16
+ rb_scan_args(argc, argv, "2*", &doc, &content, &rest);
17
+
12
18
  Data_Get_Struct(doc, xmlDoc, xml_doc);
13
19
 
14
20
  xmlNodePtr node = xmlNewCDataBlock(
15
- xml_doc,
16
- (const xmlChar *)StringValuePtr(content),
17
- RSTRING_LEN(content)
21
+ xml_doc->doc,
22
+ Qnil == content ? NULL : (const xmlChar *)StringValuePtr(content),
23
+ Qnil == content ? 0 : RSTRING_LEN(content)
18
24
  );
19
25
 
20
- VALUE rb_node = Nokogiri_wrap_xml_node(node);
26
+ NOKOGIRI_ROOT_NODE(node);
27
+
28
+ VALUE rb_node = Nokogiri_wrap_xml_node(klass, node);
29
+ rb_funcall2(rb_node, rb_intern("initialize"), argc, argv);
21
30
 
22
31
  if(rb_block_given_p()) rb_yield(rb_node);
23
32
 
@@ -40,5 +49,5 @@ void init_xml_cdata()
40
49
 
41
50
  cNokogiriXmlCData = klass;
42
51
 
43
- rb_define_singleton_method(klass, "new", new, 2);
52
+ rb_define_singleton_method(klass, "new", new, -1);
44
53
  }
@@ -1,7 +1,7 @@
1
1
  #ifndef NOKOGIRI_XML_CDATA
2
2
  #define NOKOGIRI_XML_CDATA
3
3
 
4
- #include <native.h>
4
+ #include <nokogiri.h>
5
5
 
6
6
  void init_xml_cdata();
7
7
 
@@ -6,17 +6,26 @@
6
6
  *
7
7
  * Create a new Comment element on the +document+ with +content+
8
8
  */
9
- static VALUE new(VALUE klass, VALUE doc, VALUE content)
9
+ static VALUE new(int argc, VALUE *argv, VALUE klass)
10
10
  {
11
11
  xmlDocPtr xml_doc;
12
- Data_Get_Struct(doc, xmlDoc, xml_doc);
12
+ VALUE document;
13
+ VALUE content;
14
+ VALUE rest;
15
+
16
+ rb_scan_args(argc, argv, "2*", &document, &content, &rest);
17
+
18
+ Data_Get_Struct(document, xmlDoc, xml_doc);
13
19
 
14
20
  xmlNodePtr node = xmlNewDocComment(
15
21
  xml_doc,
16
22
  (const xmlChar *)StringValuePtr(content)
17
23
  );
18
24
 
19
- VALUE rb_node = Nokogiri_wrap_xml_node(node);
25
+ VALUE rb_node = Nokogiri_wrap_xml_node(klass, node);
26
+ rb_funcall2(rb_node, rb_intern("initialize"), argc, argv);
27
+
28
+ NOKOGIRI_ROOT_NODE(node);
20
29
 
21
30
  if(rb_block_given_p()) rb_yield(rb_node);
22
31
 
@@ -38,5 +47,5 @@ void init_xml_comment()
38
47
 
39
48
  cNokogiriXmlComment = klass;
40
49
 
41
- rb_define_singleton_method(klass, "new", new, 2);
50
+ rb_define_singleton_method(klass, "new", new, -1);
42
51
  }
@@ -1,7 +1,7 @@
1
1
  #ifndef NOKOGIRI_XML_COMMENT
2
2
  #define NOKOGIRI_XML_COMMENT
3
3
 
4
- #include <native.h>
4
+ #include <nokogiri.h>
5
5
 
6
6
  void init_xml_comment();
7
7
 
@@ -7,9 +7,21 @@ static void dealloc(xmlDocPtr doc)
7
7
  nokogiriTuplePtr tuple = doc->_private;
8
8
  xmlNodeSetPtr node_set = tuple->unlinkedNodes;
9
9
 
10
- int i;
11
- for(i = 0; i < node_set->nodeNr; i++) {
12
- xmlAddChild((xmlNodePtr)doc, node_set->nodeTab[i]);
10
+ xmlDeregisterNodeFunc func = xmlDeregisterNodeDefault(NULL);
11
+
12
+ int j ;
13
+ for(j = 0 ; j < node_set->nodeNr ; j++) {
14
+ xmlNodePtr node = node_set->nodeTab[j];
15
+ switch(node->type)
16
+ {
17
+ case XML_ATTRIBUTE_NODE:
18
+ xmlFreePropList((xmlAttrPtr)node);
19
+ break;
20
+ default:
21
+ if(node->parent == NULL) {
22
+ xmlAddChild((xmlNodePtr)doc, node);
23
+ }
24
+ }
13
25
  }
14
26
 
15
27
  if (node_set->nodeTab != NULL)
@@ -20,6 +32,8 @@ static void dealloc(xmlDocPtr doc)
20
32
  doc->_private = NULL;
21
33
  xmlFreeDoc(doc);
22
34
 
35
+ xmlDeregisterNodeDefault(func);
36
+
23
37
  NOKOGIRI_DEBUG_END(doc);
24
38
  }
25
39
 
@@ -72,7 +86,23 @@ static VALUE root(VALUE self)
72
86
  xmlNodePtr root = xmlDocGetRootElement(doc);
73
87
 
74
88
  if(!root) return Qnil;
75
- return Nokogiri_wrap_xml_node(root) ;
89
+ return Nokogiri_wrap_xml_node(Qnil, root) ;
90
+ }
91
+
92
+ /*
93
+ * call-seq:
94
+ * encoding= encoding
95
+ *
96
+ * Set the encoding string for this Document
97
+ */
98
+ static VALUE set_encoding(VALUE self, VALUE encoding)
99
+ {
100
+ xmlDocPtr doc;
101
+ Data_Get_Struct(self, xmlDoc, doc);
102
+
103
+ doc->encoding = xmlStrdup((xmlChar *)StringValuePtr(encoding));
104
+
105
+ return encoding;
76
106
  }
77
107
 
78
108
  /*
@@ -203,50 +233,29 @@ static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
203
233
  if(dup == NULL) return Qnil;
204
234
 
205
235
  dup->type = doc->type;
206
- if(dup->type == XML_DOCUMENT_NODE)
207
- return Nokogiri_wrap_xml_document(cNokogiriXmlDocument, dup);
208
- else
209
- return Nokogiri_wrap_xml_document(cNokogiriHtmlDocument, dup);
236
+ return Nokogiri_wrap_xml_document(RBASIC(self)->klass, dup);
210
237
  }
211
238
 
212
239
  /*
213
240
  * call-seq:
214
- * new
241
+ * new(version = default)
215
242
  *
216
- * Create a new document
243
+ * Create a new document with +version+ (defaults to "1.0")
217
244
  */
218
245
  static VALUE new(int argc, VALUE *argv, VALUE klass)
219
246
  {
220
- VALUE version;
221
- if(rb_scan_args(argc, argv, "01", &version) == 0)
247
+ VALUE version, rest, rb_doc ;
248
+
249
+ rb_scan_args(argc, argv, "0*", &rest);
250
+ version = rb_ary_entry(rest, 0);
251
+ if (version == Qnil) {
222
252
  version = rb_str_new2("1.0");
253
+ }
223
254
 
224
255
  xmlDocPtr doc = xmlNewDoc((xmlChar *)StringValuePtr(version));
225
- return Nokogiri_wrap_xml_document(klass, doc);
226
- }
227
-
228
- /*
229
- * call-seq:
230
- * substitute_entities=(boolean)
231
- *
232
- * Set the global XML default for substitute entities.
233
- */
234
- static VALUE substitute_entities_set(VALUE klass, VALUE value)
235
- {
236
- xmlSubstituteEntitiesDefault(NUM2INT(value));
237
- return Qnil ;
238
- }
239
-
240
- /*
241
- * call-seq:
242
- * load_external_subsets=(boolean)
243
- *
244
- * Set the global XML default for load external subsets.
245
- */
246
- static VALUE load_external_subsets_set(VALUE klass, VALUE value)
247
- {
248
- xmlLoadExtDtdDefaultValue = NUM2INT(value);
249
- return Qnil ;
256
+ rb_doc = Nokogiri_wrap_xml_document(klass, doc);
257
+ rb_funcall2(rb_doc, rb_intern("initialize"), argc, argv);
258
+ return rb_doc ;
250
259
  }
251
260
 
252
261
  VALUE cNokogiriXmlDocument ;
@@ -266,12 +275,11 @@ void init_xml_document()
266
275
  rb_define_singleton_method(klass, "read_memory", read_memory, 4);
267
276
  rb_define_singleton_method(klass, "read_io", read_io, 4);
268
277
  rb_define_singleton_method(klass, "new", new, -1);
269
- rb_define_singleton_method(klass, "substitute_entities=", substitute_entities_set, 1);
270
- rb_define_singleton_method(klass, "load_external_subsets=", load_external_subsets_set, 1);
271
278
 
272
279
  rb_define_method(klass, "root", root, 0);
273
280
  rb_define_method(klass, "root=", set_root, 1);
274
281
  rb_define_method(klass, "encoding", encoding, 0);
282
+ rb_define_method(klass, "encoding=", set_encoding, 1);
275
283
  rb_define_method(klass, "dup", duplicate_node, -1);
276
284
  rb_define_method(klass, "url", url, 0);
277
285
  }
@@ -280,16 +288,17 @@ void init_xml_document()
280
288
  /* this takes klass as a param because it's used for HtmlDocument, too. */
281
289
  VALUE Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc)
282
290
  {
283
- VALUE rb_doc = Qnil;
284
291
  nokogiriTuplePtr tuple = (nokogiriTuplePtr)malloc(sizeof(nokogiriTuple));
285
292
 
286
- rb_doc = Data_Wrap_Struct(
293
+ VALUE rb_doc = Data_Wrap_Struct(
287
294
  klass ? klass : cNokogiriXmlDocument,
288
295
  0,
289
296
  dealloc,
290
297
  doc
291
298
  );
292
299
  rb_iv_set(rb_doc, "@decorators", Qnil);
300
+ rb_iv_set(rb_doc, "@node_cache", rb_ary_new());
301
+ rb_funcall(rb_doc, rb_intern("initialize"), 0);
293
302
 
294
303
  tuple->doc = (void *)rb_doc;
295
304
  tuple->unlinkedNodes = xmlXPathNodeSetCreate(NULL);
@@ -1,7 +1,7 @@
1
1
  #ifndef NOKOGIRI_XML_DOCUMENT
2
2
  #define NOKOGIRI_XML_DOCUMENT
3
3
 
4
- #include <native.h>
4
+ #include <nokogiri.h>
5
5
 
6
6
  struct _nokogiriTuple {
7
7
  xmlDocPtr doc;
@@ -6,16 +6,24 @@
6
6
  *
7
7
  * Create a new DocumentFragment element on the +document+
8
8
  */
9
- static VALUE new(VALUE klass, VALUE doc)
9
+ static VALUE new(int argc, VALUE *argv, VALUE klass)
10
10
  {
11
11
  xmlDocPtr xml_doc;
12
- Data_Get_Struct(doc, xmlDoc, xml_doc);
12
+ VALUE document;
13
+ VALUE rest;
14
+
15
+ rb_scan_args(argc, argv, "1*", &document, &rest);
16
+
17
+ Data_Get_Struct(document, xmlDoc, xml_doc);
13
18
 
14
19
  xmlNodePtr node = xmlNewDocFragment(xml_doc->doc);
15
20
  if(node->doc->children)
16
21
  node->ns = node->doc->children->ns;
17
22
 
18
- VALUE rb_node = Nokogiri_wrap_xml_node(node);
23
+ NOKOGIRI_ROOT_NODE(node);
24
+
25
+ VALUE rb_node = Nokogiri_wrap_xml_node(klass, node);
26
+ rb_funcall2(rb_node, rb_intern("initialize"), argc, argv);
19
27
 
20
28
  if(rb_block_given_p()) rb_yield(rb_node);
21
29
 
@@ -36,5 +44,5 @@ void init_xml_document_fragment()
36
44
 
37
45
  cNokogiriXmlDocumentFragment = klass;
38
46
 
39
- rb_define_singleton_method(klass, "new", new, 1);
47
+ rb_define_singleton_method(klass, "new", new, -1);
40
48
  }