nokogiri 1.2.1 → 1.2.2

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 (75) hide show
  1. data/.autotest +15 -0
  2. data/{History.ja.txt → CHANGELOG.ja.rdoc} +30 -2
  3. data/{History.txt → CHANGELOG.rdoc} +28 -2
  4. data/Manifest.txt +13 -7
  5. data/{README.ja.txt → README.ja.rdoc} +3 -1
  6. data/{README.txt → README.rdoc} +7 -1
  7. data/Rakefile +8 -25
  8. data/ext/nokogiri/extconf.rb +4 -4
  9. data/ext/nokogiri/html_entity_lookup.c +30 -0
  10. data/ext/nokogiri/html_entity_lookup.h +8 -0
  11. data/ext/nokogiri/native.c +22 -0
  12. data/ext/nokogiri/native.h +27 -4
  13. data/ext/nokogiri/xml_document.c +31 -4
  14. data/ext/nokogiri/xml_document.h +11 -0
  15. data/ext/nokogiri/xml_document_fragment.c +1 -1
  16. data/ext/nokogiri/xml_node.c +71 -58
  17. data/ext/nokogiri/xml_node_set.c +26 -0
  18. data/ext/nokogiri/xml_reader.c +4 -2
  19. data/ext/nokogiri/xml_sax_parser.c +0 -37
  20. data/ext/nokogiri/xml_sax_push_parser.c +2 -2
  21. data/ext/nokogiri/xml_xpath_context.c +34 -7
  22. data/lib/nokogiri.rb +25 -0
  23. data/lib/nokogiri/css/generated_tokenizer.rb +2 -2
  24. data/lib/nokogiri/css/node.rb +2 -0
  25. data/lib/nokogiri/css/parser.rb +3 -2
  26. data/lib/nokogiri/html.rb +9 -52
  27. data/lib/nokogiri/html/document.rb +2 -0
  28. data/lib/nokogiri/html/entity_lookup.rb +11 -0
  29. data/lib/nokogiri/version.rb +1 -1
  30. data/lib/nokogiri/xml.rb +1 -2
  31. data/lib/nokogiri/xml/builder.rb +18 -5
  32. data/lib/nokogiri/xml/document.rb +15 -1
  33. data/lib/nokogiri/xml/fragment_handler.rb +34 -0
  34. data/lib/nokogiri/xml/node.rb +104 -29
  35. data/lib/nokogiri/xml/node_set.rb +12 -10
  36. data/lib/nokogiri/xml/sax/parser.rb +3 -3
  37. data/lib/xsd/xmlparser/nokogiri.rb +53 -0
  38. data/tasks/test.rb +7 -5
  39. data/test/css/test_nthiness.rb +1 -0
  40. data/test/css/test_parser.rb +1 -0
  41. data/test/css/test_tokenizer.rb +1 -0
  42. data/test/css/test_xpath_visitor.rb +1 -0
  43. data/test/helper.rb +4 -0
  44. data/test/hpricot/test_alter.rb +1 -0
  45. data/test/html/sax/test_parser.rb +13 -0
  46. data/test/html/test_builder.rb +21 -0
  47. data/test/html/test_document.rb +36 -0
  48. data/test/html/test_document_encoding.rb +46 -0
  49. data/test/html/test_named_characters.rb +14 -0
  50. data/test/html/test_node.rb +80 -0
  51. data/test/test_convert_xpath.rb +1 -0
  52. data/test/test_css_cache.rb +1 -0
  53. data/test/test_nokogiri.rb +8 -0
  54. data/test/xml/sax/test_parser.rb +6 -0
  55. data/test/xml/sax/test_push_parser.rb +1 -0
  56. data/test/xml/test_builder.rb +9 -0
  57. data/test/xml/test_cdata.rb +1 -0
  58. data/test/xml/test_comment.rb +1 -0
  59. data/test/xml/test_document.rb +58 -0
  60. data/test/xml/test_document_encoding.rb +15 -14
  61. data/test/xml/test_document_fragment.rb +6 -0
  62. data/test/xml/test_dtd.rb +1 -0
  63. data/test/xml/test_dtd_encoding.rb +1 -0
  64. data/test/xml/test_entity_reference.rb +1 -0
  65. data/test/xml/test_node.rb +52 -4
  66. data/test/xml/test_node_encoding.rb +1 -0
  67. data/test/xml/test_node_set.rb +21 -1
  68. data/test/xml/test_processing_instruction.rb +1 -0
  69. data/test/xml/test_reader_encoding.rb +1 -0
  70. data/test/xml/test_unparented_node.rb +381 -0
  71. data/test/xml/test_xpath.rb +1 -0
  72. metadata +34 -16
  73. data/lib/nokogiri/xml/after_handler.rb +0 -18
  74. data/lib/nokogiri/xml/before_handler.rb +0 -33
  75. data/vendor/hoe.rb +0 -1020
@@ -0,0 +1,15 @@
1
+ # -*- ruby -*-
2
+
3
+ Autotest.add_hook :run_command do |at|
4
+ if ENV['ONENINE']
5
+ system "rake1.9 build"
6
+ else
7
+ system "rake build"
8
+ end
9
+ end
10
+
11
+ class Autotest
12
+ def ruby
13
+ 'ruby1.9'
14
+ end
15
+ end if ENV['ONENINE']
@@ -1,11 +1,39 @@
1
- === 1.2.1 / 2008年2月23日
1
+ === 1.2.2 / 2009年3月14日
2
+
3
+ * 新しい機能
4
+
5
+ * Nokogiri は soap4r と一緒に使う事が可能。(XSD::XMLParser::Nokogiri 参照)
6
+ * Nokogiri::XML::Node#inner_html= はノードの中のHTMLをセット出来る
7
+ * Nokogiriのビルダーのインタフェースの改良
8
+ * Nokogiri::XML::Node#swap は、現在のノードに新しいhtmlを交換する事が出来る
9
+
10
+
11
+ * バグの修正
12
+
13
+ * ビルダーAPIのタグのネスティングを修正 (LH #41)
14
+ * Nokogiri::HTML.fragment はテキストだけのノードを適切に扱う事が出来る(LH #43)
15
+ * Nokogiri::XML::Node#before はテキストノードのはじめに挿入する事が出来る (LH #44)
16
+ * Nokogiri::XML::Node#after はテキストノードの文末に挿入する事が出来る
17
+ * Nokogiri::XML::Node#search 名前空間が自動的に登録されるようになった(LH#42)
18
+ * Nokogiri::XML::NodeSet#search 名前空間が自動的に登録されるようになった
19
+ * Nokogiri::HTML::NamedCharacters はlibxml2に委任
20
+ * Nokogiri::XML::Node#[] はSymbolを使う (LH #48)
21
+ * vasprintf にwindowsを修正 (Geffroy Couprie ありがとう!)
22
+ * Nokogiri::XML::Node#[]= はentityを符号化しない (LH #55)
23
+ * 名前空間はreparentedのノードに模写する (LH #56)
24
+ * StringのエンコードはRuby 1.9での初期設定を使用する
25
+ * Document#dup は新しいドキュメントに同じタイプを作る (LH #59)
26
+ * Document#parent は存在しない (LH #64)
27
+
28
+
29
+ === 1.2.1 / 2009年2月23日
2
30
 
3
31
  * 修正
4
32
 
5
33
  * CSS のセレクターのスペースを修正
6
34
  * Ruby 1.9 のStringのエンコードを修正 (角谷さんに感謝!)
7
35
 
8
- === 1.2.0 / 2008年2月22日
36
+ === 1.2.0 / 2009年2月22日
9
37
 
10
38
  * 新しい機能
11
39
  * CSSサーチが CSS3 名前空間クエリをサポートするようになった
@@ -1,11 +1,37 @@
1
- === 1.2.1 / 2008-02-23
1
+ === 1.2.2 / 2009-03-14
2
+
3
+ * New features
4
+
5
+ * Nokogiri may be used with soap4r. See XSD::XMLParser::Nokogiri
6
+ * Nokogiri::XML::Node#inner_html= to set the inner html for a node
7
+ * Nokogiri builder interface improvements
8
+ * Nokogiri::XML::Node#swap swaps html for current node (LH #50)
9
+
10
+ * Bugfixes
11
+
12
+ * Fixed a tag nesting problem in the Builder API (LH #41)
13
+ * Nokogiri::HTML.fragment will properly handle text only nodes (LH #43)
14
+ * Nokogiri::XML::Node#before will prepend text nodes (LH #44)
15
+ * Nokogiri::XML::Node#after will append text nodes
16
+ * Nokogiri::XML::Node#search automatically registers root namepsaces (LH #42)
17
+ * Nokogiri::XML::NodeSet#search automatically registers namespaces
18
+ * Nokogiri::HTML::NamedCharacters delegates to libxml2
19
+ * Nokogiri::XML::Node#[] can take a symbol (LH #48)
20
+ * vasprintf for windows updated. Thanks Geoffroy Couprie!
21
+ * Nokogiri::XML::Node#[]= should not encode entities (LH #55)
22
+ * Namespaces should be copied to reparented nodes (LH #56)
23
+ * Nokogiri uses encoding set on the string for default in Ruby 1.9
24
+ * Document#dup should create a new document of the same type (LH #59)
25
+ * Document should not have a parent method (LH #64)
26
+
27
+ === 1.2.1 / 2009-02-23
2
28
 
3
29
  * Bugfixes
4
30
 
5
31
  * Fixed a CSS selector space bug
6
32
  * Fixed Ruby 1.9 String Encoding (Thanks 角谷さん!)
7
33
 
8
- === 1.2.0 / 2008-02-22
34
+ === 1.2.0 / 2009-02-22
9
35
 
10
36
  * New features
11
37
 
@@ -1,12 +1,15 @@
1
- History.ja.txt
2
- History.txt
1
+ .autotest
2
+ CHANGELOG.ja.rdoc
3
+ CHANGELOG.rdoc
3
4
  Manifest.txt
4
- README.ja.txt
5
- README.txt
5
+ README.ja.rdoc
6
+ README.rdoc
6
7
  Rakefile
7
8
  ext/nokogiri/extconf.rb
8
9
  ext/nokogiri/html_document.c
9
10
  ext/nokogiri/html_document.h
11
+ ext/nokogiri/html_entity_lookup.c
12
+ ext/nokogiri/html_entity_lookup.h
10
13
  ext/nokogiri/html_sax_parser.c
11
14
  ext/nokogiri/html_sax_parser.h
12
15
  ext/nokogiri/native.c
@@ -71,13 +74,12 @@ lib/nokogiri/hpricot.rb
71
74
  lib/nokogiri/html.rb
72
75
  lib/nokogiri/html/builder.rb
73
76
  lib/nokogiri/html/document.rb
77
+ lib/nokogiri/html/entity_lookup.rb
74
78
  lib/nokogiri/html/sax/parser.rb
75
79
  lib/nokogiri/syntax_error.rb
76
80
  lib/nokogiri/version.rb
77
81
  lib/nokogiri/xml.rb
78
- lib/nokogiri/xml/after_handler.rb
79
82
  lib/nokogiri/xml/attr.rb
80
- lib/nokogiri/xml/before_handler.rb
81
83
  lib/nokogiri/xml/builder.rb
82
84
  lib/nokogiri/xml/cdata.rb
83
85
  lib/nokogiri/xml/comment.rb
@@ -86,6 +88,7 @@ lib/nokogiri/xml/document_fragment.rb
86
88
  lib/nokogiri/xml/dtd.rb
87
89
  lib/nokogiri/xml/element.rb
88
90
  lib/nokogiri/xml/entity_declaration.rb
91
+ lib/nokogiri/xml/fragment_handler.rb
89
92
  lib/nokogiri/xml/node.rb
90
93
  lib/nokogiri/xml/node/save_options.rb
91
94
  lib/nokogiri/xml/node_set.rb
@@ -103,6 +106,7 @@ lib/nokogiri/xml/xpath/syntax_error.rb
103
106
  lib/nokogiri/xml/xpath_context.rb
104
107
  lib/nokogiri/xslt.rb
105
108
  lib/nokogiri/xslt/stylesheet.rb
109
+ lib/xsd/xmlparser/nokogiri.rb
106
110
  tasks/test.rb
107
111
  test/css/test_nthiness.rb
108
112
  test/css/test_parser.rb
@@ -135,6 +139,8 @@ test/hpricot/test_xml.rb
135
139
  test/html/sax/test_parser.rb
136
140
  test/html/test_builder.rb
137
141
  test/html/test_document.rb
142
+ test/html/test_document_encoding.rb
143
+ test/html/test_named_characters.rb
138
144
  test/html/test_node.rb
139
145
  test/test_convert_xpath.rb
140
146
  test/test_css_cache.rb
@@ -162,5 +168,5 @@ test/xml/test_node_set.rb
162
168
  test/xml/test_processing_instruction.rb
163
169
  test/xml/test_reader_encoding.rb
164
170
  test/xml/test_text.rb
171
+ test/xml/test_unparented_node.rb
165
172
  test/xml/test_xpath.rb
166
- vendor/hoe.rb
@@ -64,8 +64,10 @@ NokogiriはHpricotの代わりに使用出来る。
64
64
  == REQUIREMENTS:
65
65
 
66
66
  * ruby 1.8 or 1.9
67
- * libxml
67
+ * libxml2
68
+ * libxml2-dev
68
69
  * libxslt
70
+ * libxslt-dev
69
71
 
70
72
  == INSTALL:
71
73
 
@@ -42,8 +42,12 @@ The bug tracker is available here:
42
42
  require 'nokogiri'
43
43
  require 'open-uri'
44
44
 
45
+ # Get a Nokogiri::HTML:Document for the page we’re interested in...
46
+
45
47
  doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
46
48
 
49
+ # Do funky things with it using Nokogiri::XML::Node methods...
50
+
47
51
  ####
48
52
  # Search for nodes by css
49
53
  doc.css('h3.r a.l').each do |link|
@@ -66,8 +70,10 @@ The bug tracker is available here:
66
70
  == REQUIREMENTS:
67
71
 
68
72
  * ruby 1.8 or 1.9
69
- * libxml
73
+ * libxml2
74
+ * libxml2-dev
70
75
  * libxslt
76
+ * libxslt-dev
71
77
 
72
78
  == INSTALL:
73
79
 
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'rake'
5
+ require 'hoe'
5
6
 
6
7
 
7
8
  kind = Config::CONFIG['DLEXT']
@@ -10,8 +11,6 @@ windows = RUBY_PLATFORM =~ /mswin/i ? true : false
10
11
  LIB_DIR = File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
11
12
  $LOAD_PATH << LIB_DIR
12
13
 
13
- require 'vendor/hoe'
14
-
15
14
  GENERATED_PARSER = "lib/nokogiri/css/generated_parser.rb"
16
15
  GENERATED_TOKENIZER = "lib/nokogiri/css/generated_tokenizer.rb"
17
16
 
@@ -22,6 +21,9 @@ require 'nokogiri/version'
22
21
  HOE = Hoe.new('nokogiri', Nokogiri::VERSION) do |p|
23
22
  p.developer('Aaron Patterson', 'aaronp@rubyforge.org')
24
23
  p.developer('Mike Dalessio', 'mike.dalessio@gmail.com')
24
+ p.readme_file = ['README', ENV['HLANG'], 'rdoc'].compact.join('.')
25
+ p.history_file = ['CHANGELOG', ENV['HLANG'], 'rdoc'].compact.join('.')
26
+ p.extra_rdoc_files = FileList['*.rdoc']
25
27
  p.clean_globs = [
26
28
  'ext/nokogiri/Makefile',
27
29
  'ext/nokogiri/*.{o,so,bundle,a,log,dll}',
@@ -102,7 +104,7 @@ file GENERATED_TOKENIZER => "lib/nokogiri/css/tokenizer.rex" do |t|
102
104
  begin
103
105
  sh "frex --independent -o #{t.name} #{t.prerequisites.first}"
104
106
  rescue
105
- abort "need frex, sudo gem install aaronp-frex -s http://gems.github.com"
107
+ abort "need frex, sudo gem install tenderlove-frex -s http://gems.github.com"
106
108
  end
107
109
  end
108
110
 
@@ -254,31 +256,12 @@ namespace :install do
254
256
  desc "Install frex and racc for development"
255
257
  task :deps => %w(frex racc)
256
258
 
257
- directory "stash"
258
-
259
- file "stash/racc-1.4.5-all.tar.gz" => "stash" do |t|
260
- puts "Downloading racc to #{t.name}..."
261
-
262
- Dir.chdir File.dirname(t.name) do
263
- url = "http://i.loveruby.net/archive/racc/racc-1.4.5-all.tar.gz"
264
- system "wget #{url} || curl -O #{url}"
265
- end
266
- end
267
-
268
- task :racc => "stash/racc-1.4.5-all.tar.gz" do |t|
269
- sh "tar xvf #{t.prerequisites.first} -C stash"
270
-
271
- Dir.chdir "stash/#{File.basename(t.prerequisites.first, ".tar.gz")}" do
272
- sh "ruby setup.rb config"
273
- sh "ruby setup.rb setup"
274
- sh "sudo ruby setup.rb install"
275
- end
276
-
277
- puts "The racc binary is likely in #{::Config::CONFIG["bindir"]}."
259
+ task :racc do |t|
260
+ sh "sudo gem install racc"
278
261
  end
279
262
 
280
263
  task :frex do
281
- sh "sudo gem install aaronp-frex -s http://gems.github.com"
264
+ sh "sudo gem install tenderlove-frex -s http://gems.github.com"
282
265
  end
283
266
  end
284
267
 
@@ -57,10 +57,10 @@ unless find_header('libxml/parser.h', *HEADER_DIRS)
57
57
  end
58
58
 
59
59
  unless find_header('libxslt/xslt.h', *HEADER_DIRS)
60
- abort "libxslt is missing. try 'port install libxslt' or 'yum install libxslt'"
60
+ abort "libxslt is missing. try 'port install libxslt' or 'yum install libxslt-devel'"
61
61
  end
62
62
  unless find_header('libexslt/exslt.h', *HEADER_DIRS)
63
- abort "libxslt is missing. try 'port install libxslt' or 'yum install libxslt'"
63
+ abort "libxslt is missing. try 'port install libxslt' or 'yum install libxslt-devel'"
64
64
  end
65
65
 
66
66
  unless find_library('xml2', 'xmlParseDoc', *LIB_DIRS)
@@ -68,11 +68,11 @@ unless find_library('xml2', 'xmlParseDoc', *LIB_DIRS)
68
68
  end
69
69
 
70
70
  unless find_library('xslt', 'xsltParseStylesheetDoc', *LIB_DIRS)
71
- abort "libxslt is missing. try 'port install libxslt' or 'yum install libxslt'"
71
+ abort "libxslt is missing. try 'port install libxslt' or 'yum install libxslt-devel'"
72
72
  end
73
73
 
74
74
  unless find_library('exslt', 'exsltFuncRegister', *LIB_DIRS)
75
- abort "libxslt is missing. try 'port install libxslt' or 'yum install libxslt'"
75
+ abort "libxslt is missing. try 'port install libxslt' or 'yum install libxslt-devel'"
76
76
  end
77
77
 
78
78
  create_makefile('nokogiri/native')
@@ -0,0 +1,30 @@
1
+ #include <html_entity_lookup.h>
2
+
3
+ /*
4
+ * call-seq:
5
+ * get(key)
6
+ *
7
+ * Get the HTML::EntityDescription for +key+
8
+ */
9
+ static VALUE get(VALUE self, VALUE key)
10
+ {
11
+ const htmlEntityDesc * desc =
12
+ htmlEntityLookup((const xmlChar *)StringValuePtr(key));
13
+
14
+ if(NULL == desc) return Qnil;
15
+ VALUE klass = rb_const_get(mNokogiriHtml, rb_intern("EntityDescription"));
16
+
17
+ return rb_funcall(klass, rb_intern("new"), 3,
18
+ INT2NUM((int)desc->value),
19
+ NOKOGIRI_STR_NEW2(desc->name, "UTF-8"),
20
+ NOKOGIRI_STR_NEW2(desc->desc, "UTF-8"));
21
+ }
22
+
23
+ void init_html_entity_lookup()
24
+ {
25
+ VALUE nokogiri = rb_define_module("Nokogiri");
26
+ VALUE html = rb_define_module_under(nokogiri, "HTML");
27
+ VALUE klass = rb_define_class_under(html, "EntityLookup", rb_cObject);
28
+
29
+ rb_define_method(klass, "get", get, 1);
30
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef NOKOGIRI_HTML_ENTITY_LOOKUP
2
+ #define NOKOGIRI_HTML_ENTITY_LOOKUP
3
+
4
+ #include <native.h>
5
+
6
+ void init_html_entity_lookup();
7
+
8
+ #endif
@@ -7,6 +7,23 @@ VALUE mNokogiriXslt ;
7
7
  VALUE mNokogiriXmlSax ;
8
8
  VALUE mNokogiriHtmlSax ;
9
9
 
10
+ #ifdef XP_WIN
11
+ /*
12
+ * I srsly hate windows. it doesn't have vasprintf.
13
+ * Thank you Geoffroy Couprie for this implementation of vasprintf!
14
+ */
15
+ int vasprintf (char **strp, const char *fmt, va_list ap)
16
+ {
17
+ int len = vsnprintf (NULL, 0, fmt, ap) + 1;
18
+ char *res = (char *)malloc((unsigned int)len);
19
+ if (res == NULL)
20
+ return -1;
21
+ *strp = res;
22
+ return vsnprintf(res, (unsigned int)len, fmt, ap);
23
+ }
24
+ #endif
25
+
26
+
10
27
  void Init_native()
11
28
  {
12
29
  xmlMemSetup(
@@ -27,6 +44,10 @@ void Init_native()
27
44
  rb_intern("LIBXML_VERSION"),
28
45
  NOKOGIRI_STR_NEW2(LIBXML_DOTTED_VERSION, "UTF-8")
29
46
  );
47
+ rb_const_set( mNokogiri,
48
+ rb_intern("LIBXML_PARSER_VERSION"),
49
+ NOKOGIRI_STR_NEW2(xmlParserVersion, "UTF-8")
50
+ );
30
51
 
31
52
  init_xml_document();
32
53
  init_html_document();
@@ -48,4 +69,5 @@ void Init_native()
48
69
  init_html_sax_parser();
49
70
  init_xslt_stylesheet();
50
71
  init_xml_syntax_error();
72
+ init_html_entity_lookup();
51
73
  }
@@ -30,16 +30,26 @@
30
30
  #define NOKOGIRI_STR_NEW2(str, encoding) \
31
31
  ({ \
32
32
  VALUE _string = rb_str_new2((const char *)str); \
33
- if(NULL != encoding) \
34
- rb_enc_associate_index(_string, rb_enc_find_index(encoding)); \
33
+ if(NULL != encoding) { \
34
+ int _enc = rb_enc_find_index(encoding); \
35
+ if(_enc == -1) \
36
+ rb_enc_associate_index(_string, rb_enc_find_index("ASCII")); \
37
+ else \
38
+ rb_enc_associate_index(_string, _enc); \
39
+ } \
35
40
  _string; \
36
41
  })
37
42
 
38
43
  #define NOKOGIRI_STR_NEW(str, len, encoding) \
39
44
  ({ \
40
45
  VALUE _string = rb_str_new((const char *)str, (long)len); \
41
- if(NULL != encoding) \
42
- rb_enc_associate_index(_string, rb_enc_find_index(encoding)); \
46
+ if(NULL != encoding) { \
47
+ int _enc = rb_enc_find_index(encoding); \
48
+ if(_enc == -1) \
49
+ rb_enc_associate_index(_string, rb_enc_find_index("ASCII")); \
50
+ else \
51
+ rb_enc_associate_index(_string, _enc); \
52
+ } \
43
53
  _string; \
44
54
  })
45
55
 
@@ -52,8 +62,13 @@
52
62
  rb_str_new((const char *)str, (long)len)
53
63
  #endif
54
64
 
65
+ #ifdef XP_WIN
66
+ int vasprintf (char **strp, const char *fmt, va_list ap);
67
+ #endif
68
+
55
69
  #include <xml_io.h>
56
70
  #include <xml_document.h>
71
+ #include <html_entity_lookup.h>
57
72
  #include <html_document.h>
58
73
  #include <xml_node.h>
59
74
  #include <xml_text.h>
@@ -81,6 +96,14 @@ extern VALUE mNokogiriHtml ;
81
96
  extern VALUE mNokogiriHtmlSax ;
82
97
  extern VALUE mNokogiriXslt ;
83
98
 
99
+ #define NOKOGIRI_ROOT_NODE(_node) \
100
+ ({ \
101
+ nokogiriTuplePtr tuple = (nokogiriTuplePtr)(_node->doc->_private); \
102
+ xmlNodeSetPtr node_set = (xmlNodeSetPtr)(tuple->unlinkedNodes); \
103
+ xmlXPathNodeSetAdd(node_set, _node); \
104
+ _node; \
105
+ })
106
+
84
107
  #ifdef DEBUG
85
108
 
86
109
  #define NOKOGIRI_DEBUG_START(p) if (getenv("NOKOGIRI_NO_FREE")) return ; if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p start\n", __FILE__, __LINE__, p);
@@ -3,8 +3,23 @@
3
3
  static void dealloc(xmlDocPtr doc)
4
4
  {
5
5
  NOKOGIRI_DEBUG_START(doc);
6
+
7
+ nokogiriTuplePtr tuple = doc->_private;
8
+ xmlNodeSetPtr node_set = tuple->unlinkedNodes;
9
+
10
+ int i;
11
+ for(i = 0; i < node_set->nodeNr; i++) {
12
+ xmlAddChild((xmlNodePtr)doc, node_set->nodeTab[i]);
13
+ }
14
+
15
+ if (node_set->nodeTab != NULL)
16
+ xmlFree(node_set->nodeTab);
17
+ xmlFree(node_set);
18
+
19
+ free(doc->_private);
6
20
  doc->_private = NULL;
7
21
  xmlFreeDoc(doc);
22
+
8
23
  NOKOGIRI_DEBUG_END(doc);
9
24
  }
10
25
 
@@ -187,7 +202,11 @@ static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
187
202
  dup = xmlCopyDoc(doc, NUM2INT(level));
188
203
  if(dup == NULL) return Qnil;
189
204
 
190
- return Nokogiri_wrap_xml_document(cNokogiriXmlDocument, dup);
205
+ 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);
191
210
  }
192
211
 
193
212
  /*
@@ -255,7 +274,6 @@ void init_xml_document()
255
274
  rb_define_method(klass, "encoding", encoding, 0);
256
275
  rb_define_method(klass, "dup", duplicate_node, -1);
257
276
  rb_define_method(klass, "url", url, 0);
258
- rb_undef_method(klass, "parent");
259
277
  }
260
278
 
261
279
 
@@ -263,10 +281,19 @@ void init_xml_document()
263
281
  VALUE Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc)
264
282
  {
265
283
  VALUE rb_doc = Qnil;
284
+ nokogiriTuplePtr tuple = (nokogiriTuplePtr)malloc(sizeof(nokogiriTuple));
266
285
 
267
- rb_doc = Data_Wrap_Struct(klass ? klass : cNokogiriXmlDocument, 0, dealloc, doc) ;
286
+ rb_doc = Data_Wrap_Struct(
287
+ klass ? klass : cNokogiriXmlDocument,
288
+ 0,
289
+ dealloc,
290
+ doc
291
+ );
268
292
  rb_iv_set(rb_doc, "@decorators", Qnil);
269
- doc->_private = (void *)rb_doc;
293
+
294
+ tuple->doc = (void *)rb_doc;
295
+ tuple->unlinkedNodes = xmlXPathNodeSetCreate(NULL);
296
+ doc->_private = tuple ;
270
297
 
271
298
  return rb_doc ;
272
299
  }