tenderlove-nokogiri 0.0.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/History.txt +6 -0
  2. data/Manifest.txt +120 -0
  3. data/README.ja.txt +86 -0
  4. data/README.txt +87 -0
  5. data/Rakefile +264 -0
  6. data/ext/nokogiri/extconf.rb +59 -0
  7. data/ext/nokogiri/html_document.c +83 -0
  8. data/ext/nokogiri/html_document.h +10 -0
  9. data/ext/nokogiri/html_sax_parser.c +32 -0
  10. data/ext/nokogiri/html_sax_parser.h +11 -0
  11. data/ext/nokogiri/native.c +40 -0
  12. data/ext/nokogiri/native.h +51 -0
  13. data/ext/nokogiri/xml_cdata.c +52 -0
  14. data/ext/nokogiri/xml_cdata.h +9 -0
  15. data/ext/nokogiri/xml_document.c +159 -0
  16. data/ext/nokogiri/xml_document.h +10 -0
  17. data/ext/nokogiri/xml_dtd.c +117 -0
  18. data/ext/nokogiri/xml_dtd.h +8 -0
  19. data/ext/nokogiri/xml_node.c +709 -0
  20. data/ext/nokogiri/xml_node.h +15 -0
  21. data/ext/nokogiri/xml_node_set.c +124 -0
  22. data/ext/nokogiri/xml_node_set.h +9 -0
  23. data/ext/nokogiri/xml_reader.c +429 -0
  24. data/ext/nokogiri/xml_reader.h +10 -0
  25. data/ext/nokogiri/xml_sax_parser.c +174 -0
  26. data/ext/nokogiri/xml_sax_parser.h +10 -0
  27. data/ext/nokogiri/xml_syntax_error.c +194 -0
  28. data/ext/nokogiri/xml_syntax_error.h +11 -0
  29. data/ext/nokogiri/xml_text.c +29 -0
  30. data/ext/nokogiri/xml_text.h +9 -0
  31. data/ext/nokogiri/xml_xpath.c +46 -0
  32. data/ext/nokogiri/xml_xpath.h +11 -0
  33. data/ext/nokogiri/xml_xpath_context.c +81 -0
  34. data/ext/nokogiri/xml_xpath_context.h +9 -0
  35. data/ext/nokogiri/xslt_stylesheet.c +108 -0
  36. data/ext/nokogiri/xslt_stylesheet.h +9 -0
  37. data/lib/nokogiri/css/node.rb +95 -0
  38. data/lib/nokogiri/css/parser.rb +24 -0
  39. data/lib/nokogiri/css/parser.y +198 -0
  40. data/lib/nokogiri/css/tokenizer.rb +9 -0
  41. data/lib/nokogiri/css/tokenizer.rex +63 -0
  42. data/lib/nokogiri/css/xpath_visitor.rb +165 -0
  43. data/lib/nokogiri/css.rb +6 -0
  44. data/lib/nokogiri/decorators/hpricot/node.rb +58 -0
  45. data/lib/nokogiri/decorators/hpricot/node_set.rb +14 -0
  46. data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +17 -0
  47. data/lib/nokogiri/decorators/hpricot.rb +3 -0
  48. data/lib/nokogiri/decorators.rb +1 -0
  49. data/lib/nokogiri/hpricot.rb +47 -0
  50. data/lib/nokogiri/html/builder.rb +9 -0
  51. data/lib/nokogiri/html/document.rb +9 -0
  52. data/lib/nokogiri/html/sax/parser.rb +21 -0
  53. data/lib/nokogiri/html.rb +95 -0
  54. data/lib/nokogiri/version.rb +3 -0
  55. data/lib/nokogiri/xml/after_handler.rb +18 -0
  56. data/lib/nokogiri/xml/before_handler.rb +32 -0
  57. data/lib/nokogiri/xml/builder.rb +79 -0
  58. data/lib/nokogiri/xml/cdata.rb +9 -0
  59. data/lib/nokogiri/xml/document.rb +30 -0
  60. data/lib/nokogiri/xml/dtd.rb +6 -0
  61. data/lib/nokogiri/xml/node.rb +195 -0
  62. data/lib/nokogiri/xml/node_set.rb +183 -0
  63. data/lib/nokogiri/xml/notation.rb +6 -0
  64. data/lib/nokogiri/xml/reader.rb +14 -0
  65. data/lib/nokogiri/xml/sax/document.rb +59 -0
  66. data/lib/nokogiri/xml/sax/parser.rb +33 -0
  67. data/lib/nokogiri/xml/sax.rb +9 -0
  68. data/lib/nokogiri/xml/syntax_error.rb +21 -0
  69. data/lib/nokogiri/xml/text.rb +6 -0
  70. data/lib/nokogiri/xml/xpath.rb +6 -0
  71. data/lib/nokogiri/xml/xpath_context.rb +14 -0
  72. data/lib/nokogiri/xml.rb +67 -0
  73. data/lib/nokogiri/xslt/stylesheet.rb +6 -0
  74. data/lib/nokogiri/xslt.rb +11 -0
  75. data/lib/nokogiri.rb +51 -0
  76. data/nokogiri.gemspec +34 -0
  77. data/test/css/test_nthiness.rb +159 -0
  78. data/test/css/test_parser.rb +224 -0
  79. data/test/css/test_tokenizer.rb +162 -0
  80. data/test/css/test_xpath_visitor.rb +54 -0
  81. data/test/files/staff.xml +59 -0
  82. data/test/files/staff.xslt +32 -0
  83. data/test/files/tlm.html +850 -0
  84. data/test/helper.rb +70 -0
  85. data/test/hpricot/files/basic.xhtml +17 -0
  86. data/test/hpricot/files/boingboing.html +2266 -0
  87. data/test/hpricot/files/cy0.html +3653 -0
  88. data/test/hpricot/files/immob.html +400 -0
  89. data/test/hpricot/files/pace_application.html +1320 -0
  90. data/test/hpricot/files/tenderlove.html +16 -0
  91. data/test/hpricot/files/uswebgen.html +220 -0
  92. data/test/hpricot/files/utf8.html +1054 -0
  93. data/test/hpricot/files/week9.html +1723 -0
  94. data/test/hpricot/files/why.xml +19 -0
  95. data/test/hpricot/load_files.rb +7 -0
  96. data/test/hpricot/test_alter.rb +67 -0
  97. data/test/hpricot/test_builder.rb +27 -0
  98. data/test/hpricot/test_parser.rb +423 -0
  99. data/test/hpricot/test_paths.rb +15 -0
  100. data/test/hpricot/test_preserved.rb +78 -0
  101. data/test/hpricot/test_xml.rb +30 -0
  102. data/test/html/sax/test_parser.rb +27 -0
  103. data/test/html/test_builder.rb +78 -0
  104. data/test/html/test_document.rb +86 -0
  105. data/test/test_convert_xpath.rb +180 -0
  106. data/test/test_nokogiri.rb +36 -0
  107. data/test/test_reader.rb +222 -0
  108. data/test/test_xslt_transforms.rb +29 -0
  109. data/test/xml/sax/test_parser.rb +93 -0
  110. data/test/xml/test_builder.rb +16 -0
  111. data/test/xml/test_cdata.rb +18 -0
  112. data/test/xml/test_document.rb +171 -0
  113. data/test/xml/test_dtd.rb +43 -0
  114. data/test/xml/test_node.rb +223 -0
  115. data/test/xml/test_node_set.rb +116 -0
  116. data/test/xml/test_text.rb +13 -0
  117. metadata +214 -0
@@ -0,0 +1,83 @@
1
+ #include <html_document.h>
2
+
3
+ /*
4
+ * call-seq:
5
+ * serialize
6
+ *
7
+ * Serialize this document
8
+ */
9
+ static VALUE serialize(VALUE self)
10
+ {
11
+ xmlDocPtr doc;
12
+ xmlChar *buf;
13
+ int size;
14
+ Data_Get_Struct(self, xmlDoc, doc);
15
+
16
+ htmlDocDumpMemory(doc, &buf, &size);
17
+ VALUE rb_str = rb_str_new((char *)buf, (long)size);
18
+ free(buf);
19
+ return rb_str;
20
+ }
21
+
22
+ /*
23
+ * call-seq:
24
+ * read_memory(string, url, encoding, options)
25
+ *
26
+ * Read the HTML document contained in +string+ with given +url+, +encoding+,
27
+ * and +options+. See Nokogiri::HTML.parse
28
+ */
29
+ static VALUE read_memory( VALUE klass,
30
+ VALUE string,
31
+ VALUE url,
32
+ VALUE encoding,
33
+ VALUE options )
34
+ {
35
+ const char * c_buffer = StringValuePtr(string);
36
+ const char * c_url = (url == Qnil) ? NULL : StringValuePtr(url);
37
+ const char * c_enc = (encoding == Qnil) ? NULL : StringValuePtr(encoding);
38
+ int len = NUM2INT(rb_funcall(string, rb_intern("length"), 0));
39
+
40
+ htmlDocPtr doc = htmlReadMemory(c_buffer, len, c_url, c_enc, NUM2INT(options));
41
+
42
+ if(doc == NULL)
43
+ doc = htmlNewDoc((const xmlChar *)c_url, NULL);
44
+
45
+ return Nokogiri_wrap_xml_document(klass, doc);
46
+ }
47
+
48
+ /*
49
+ * call-seq:
50
+ * type
51
+ *
52
+ * The type for this document
53
+ */
54
+ static VALUE type(VALUE self)
55
+ {
56
+ htmlDocPtr doc;
57
+ Data_Get_Struct(self, xmlDoc, doc);
58
+ return INT2NUM((int)doc->type);
59
+ }
60
+
61
+ VALUE cNokogiriHtmlDocument ;
62
+ void init_html_document()
63
+ {
64
+ /*
65
+ * HACK. This is so that rdoc will work with this C file.
66
+ */
67
+ /*
68
+ VALUE nokogiri = rb_define_module("Nokogiri");
69
+ VALUE html = rb_define_module_under(nokogiri, "HTML");
70
+ VALUE xml = rb_define_module_under(nokogiri, "XML");
71
+ VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
72
+ VALUE xml_doc = rb_define_class_under(xml, "Document", node);
73
+ VALUE klass = rb_define_class_under(html, "Document", xml_doc);
74
+ */
75
+
76
+ VALUE klass ;
77
+ klass = cNokogiriHtmlDocument = rb_const_get(mNokogiriHtml, rb_intern("Document"));
78
+
79
+ rb_define_singleton_method(klass, "read_memory", read_memory, 4);
80
+
81
+ rb_define_method(klass, "type", type, 0);
82
+ rb_define_method(klass, "serialize", serialize, 0);
83
+ }
@@ -0,0 +1,10 @@
1
+ #ifndef NOKOGIRI_HTML_DOCUMENT
2
+ #define NOKOGIRI_HTML_DOCUMENT
3
+
4
+ #include <native.h>
5
+
6
+ void init_html_document();
7
+
8
+ extern VALUE cNokogiriHtmlDocument ;
9
+
10
+ #endif
@@ -0,0 +1,32 @@
1
+ #include <html_sax_parser.h>
2
+
3
+ static VALUE native_parse_file(VALUE self, VALUE data, VALUE encoding)
4
+ {
5
+ xmlSAXHandlerPtr handler;
6
+ Data_Get_Struct(self, xmlSAXHandler, handler);
7
+ htmlSAXParseFile( StringValuePtr(data),
8
+ (const char *)StringValuePtr(encoding),
9
+ (htmlSAXHandlerPtr)handler,
10
+ (void *)self );
11
+ return data;
12
+ }
13
+
14
+ static VALUE native_parse_memory(VALUE self, VALUE data, VALUE encoding)
15
+ {
16
+ xmlSAXHandlerPtr handler;
17
+ Data_Get_Struct(self, xmlSAXHandler, handler);
18
+ htmlSAXParseDoc( (xmlChar *)StringValuePtr(data),
19
+ (const char *)StringValuePtr(encoding),
20
+ (htmlSAXHandlerPtr)handler,
21
+ (void *)self );
22
+ return data;
23
+ }
24
+
25
+ VALUE cNokogiriHtmlSaxParser ;
26
+ void init_html_sax_parser()
27
+ {
28
+ VALUE klass = cNokogiriHtmlSaxParser =
29
+ rb_const_get(mNokogiriHtmlSax, rb_intern("Parser"));
30
+ rb_define_private_method(klass, "native_parse_memory", native_parse_memory, 2);
31
+ rb_define_private_method(klass, "native_parse_file", native_parse_file, 2);
32
+ }
@@ -0,0 +1,11 @@
1
+ #ifndef NOKOGIRI_HTML_SAX_PARSER
2
+ #define NOKOGIRI_HTML_SAX_PARSER
3
+
4
+ #include <native.h>
5
+
6
+ void init_html_sax_parser();
7
+
8
+ extern VALUE cNokogiriHtmlSaxParser ;
9
+ #endif
10
+
11
+
@@ -0,0 +1,40 @@
1
+ #include <native.h>
2
+
3
+ VALUE mNokogiri ;
4
+ VALUE mNokogiriXml ;
5
+ VALUE mNokogiriHtml ;
6
+ VALUE mNokogiriXslt ;
7
+ VALUE mNokogiriXmlSax ;
8
+ VALUE mNokogiriHtmlSax ;
9
+
10
+ void Init_native()
11
+ {
12
+ mNokogiri = rb_const_get(rb_cObject, rb_intern("Nokogiri"));
13
+ mNokogiriXml = rb_const_get(mNokogiri, rb_intern("XML"));
14
+ mNokogiriHtml = rb_const_get(mNokogiri, rb_intern("HTML"));
15
+ mNokogiriXslt = rb_const_get(mNokogiri, rb_intern("XSLT"));
16
+ mNokogiriXmlSax = rb_const_get(mNokogiriXml, rb_intern("SAX"));
17
+ mNokogiriHtmlSax = rb_const_get(mNokogiriHtml, rb_intern("SAX"));
18
+
19
+ rb_const_set( mNokogiri,
20
+ rb_intern("LIBXML_VERSION"),
21
+ rb_str_new2(LIBXML_DOTTED_VERSION)
22
+ );
23
+
24
+ xmlSetStructuredErrorFunc(NULL, Nokogiri_error_handler);
25
+
26
+ init_xml_document();
27
+ init_html_document();
28
+ init_xml_node();
29
+ init_xml_text();
30
+ init_xml_cdata();
31
+ init_xml_node_set();
32
+ init_xml_xpath_context();
33
+ init_xml_xpath();
34
+ init_xml_sax_parser();
35
+ init_xml_reader();
36
+ init_xml_dtd();
37
+ init_html_sax_parser();
38
+ init_xslt_stylesheet();
39
+ init_xml_syntax_error();
40
+ }
@@ -0,0 +1,51 @@
1
+ #ifndef NOKOGIRI_NATIVE
2
+ #define NOKOGIRI_NATIVE
3
+
4
+ #include <stdlib.h>
5
+ #include <ruby.h>
6
+ #include <libxml/parser.h>
7
+ #include <libxml/xpath.h>
8
+ #include <libxml/xpathInternals.h>
9
+ #include <libxml/xmlreader.h>
10
+ #include <libxml/HTMLparser.h>
11
+ #include <libxml/HTMLtree.h>
12
+
13
+ #include <xml_document.h>
14
+ #include <html_document.h>
15
+ #include <xml_node.h>
16
+ #include <xml_text.h>
17
+ #include <xml_cdata.h>
18
+ #include <xml_node_set.h>
19
+ #include <xml_xpath.h>
20
+ #include <xml_dtd.h>
21
+ #include <xml_xpath_context.h>
22
+ #include <xml_sax_parser.h>
23
+ #include <xml_reader.h>
24
+ #include <html_sax_parser.h>
25
+ #include <xslt_stylesheet.h>
26
+ #include <xml_syntax_error.h>
27
+
28
+ extern VALUE mNokogiri ;
29
+ extern VALUE mNokogiriXml ;
30
+ extern VALUE mNokogiriXmlSax ;
31
+ extern VALUE mNokogiriHtml ;
32
+ extern VALUE mNokogiriHtmlSax ;
33
+ extern VALUE mNokogiriXslt ;
34
+
35
+ #ifdef DEBUG
36
+
37
+ #define NOKOGIRI_DEBUG_START_NODE(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"\nnokogiri: %s:%d %p start node (%p %x %p/%s)\n", __FILE__, __LINE__, p, p->_private, p->type, p->name, p->name);
38
+ #define NOKOGIRI_DEBUG_START_TEXT(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"\nnokogiri: %s:%d %p start node (%p %x %p/%s) '%s'\n", __FILE__, __LINE__, p, p->_private, p->type, p->name, p->name, p->content);
39
+ #define NOKOGIRI_DEBUG_START(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p start\n", __FILE__, __LINE__, p);
40
+ #define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
41
+
42
+ #else
43
+
44
+ #define NOKOGIRI_DEBUG_START_NODE(p)
45
+ #define NOKOGIRI_DEBUG_START_TEXT(p)
46
+ #define NOKOGIRI_DEBUG_START(p)
47
+ #define NOKOGIRI_DEBUG_END(p)
48
+
49
+ #endif
50
+
51
+ #endif
@@ -0,0 +1,52 @@
1
+ #include <xml_cdata.h>
2
+
3
+ static void dealloc(xmlNodePtr node)
4
+ {
5
+ if (node->doc == NULL) {
6
+ NOKOGIRI_DEBUG_START_NODE(node);
7
+ xmlFreeNode(node);
8
+ NOKOGIRI_DEBUG_END(node);
9
+ }
10
+ }
11
+
12
+ /*
13
+ * call-seq:
14
+ * new(document, content)
15
+ *
16
+ * Create a new CData element on the +document+ with +content+
17
+ */
18
+ static VALUE new(VALUE klass, VALUE doc, VALUE content)
19
+ {
20
+ xmlDocPtr xml_doc;
21
+ Data_Get_Struct(doc, xmlDoc, xml_doc);
22
+
23
+ xmlNodePtr node = xmlNewCDataBlock(
24
+ xml_doc,
25
+ (const xmlChar *)StringValuePtr(content),
26
+ NUM2INT(rb_funcall(content, rb_intern("length"), 0))
27
+ );
28
+
29
+ VALUE rb_node = Data_Wrap_Struct(klass, NULL, dealloc, node);
30
+ node->_private = (void *)rb_node;
31
+
32
+ if(rb_block_given_p()) rb_yield(rb_node);
33
+
34
+ return rb_node;
35
+ }
36
+
37
+ VALUE cNokogiriXmlCData;
38
+ void init_xml_cdata()
39
+ {
40
+ VALUE nokogiri = rb_define_module("Nokogiri");
41
+ VALUE xml = rb_define_module_under(nokogiri, "XML");
42
+
43
+ /*
44
+ * CData represents a CData node in an xml document.
45
+ */
46
+ VALUE klass = rb_define_class_under(xml, "CData", cNokogiriXmlNode);
47
+
48
+
49
+ cNokogiriXmlCData = klass;
50
+
51
+ rb_define_singleton_method(klass, "new", new, 2);
52
+ }
@@ -0,0 +1,9 @@
1
+ #ifndef NOKOGIRI_XML_CDATA
2
+ #define NOKOGIRI_XML_CDATA
3
+
4
+ #include <native.h>
5
+
6
+ void init_xml_cdata();
7
+
8
+ extern VALUE cNokogiriXmlCData;
9
+ #endif
@@ -0,0 +1,159 @@
1
+ #include <xml_document.h>
2
+
3
+ /*
4
+ * note that xmlDocPtr is being cast as an xmlNodePtr, which is legal for the
5
+ * "common part" struct header which contains only node pointers.
6
+ */
7
+ static void gc_mark(xmlNodePtr node)
8
+ {
9
+ xmlNodePtr child ;
10
+ /* mark children nodes */
11
+ for (child = node->children ; child ; child = child->next) {
12
+ if (child->_private)
13
+ rb_gc_mark((VALUE)child->_private);
14
+ }
15
+ }
16
+
17
+ static void dealloc(xmlDocPtr doc)
18
+ {
19
+ NOKOGIRI_DEBUG_START(doc);
20
+ xmlFreeDoc(doc);
21
+ NOKOGIRI_DEBUG_END(doc);
22
+ }
23
+
24
+ /*
25
+ * call-seq:
26
+ * serialize
27
+ *
28
+ * Serialize this document
29
+ */
30
+ static VALUE serialize(VALUE self)
31
+ {
32
+ xmlDocPtr doc;
33
+ xmlChar *buf;
34
+ int size;
35
+ Data_Get_Struct(self, xmlDoc, doc);
36
+
37
+ xmlDocDumpMemory(doc, &buf, &size);
38
+ VALUE rb_str = rb_str_new((char *)buf, (long)size);
39
+ free(buf);
40
+ return rb_str;
41
+ }
42
+
43
+ /*
44
+ * call-seq:
45
+ * root=
46
+ *
47
+ * Set the root element on this document
48
+ */
49
+ static VALUE set_root(VALUE self, VALUE root)
50
+ {
51
+ xmlDocPtr doc;
52
+ xmlNodePtr new_root;
53
+
54
+ Data_Get_Struct(self, xmlDoc, doc);
55
+ Data_Get_Struct(root, xmlNode, new_root);
56
+
57
+ xmlDocSetRootElement(doc, new_root);
58
+ Nokogiri_xml_node_owned_set(new_root);
59
+ return root;
60
+ }
61
+
62
+ /*
63
+ * call-seq:
64
+ * root
65
+ *
66
+ * Get the root node for this document.
67
+ */
68
+ static VALUE root(VALUE self)
69
+ {
70
+ xmlDocPtr doc;
71
+ Data_Get_Struct(self, xmlDoc, doc);
72
+
73
+ xmlNodePtr root = xmlDocGetRootElement(doc);
74
+
75
+ if(!root) return Qnil;
76
+ return Nokogiri_wrap_xml_node(root) ;
77
+ }
78
+
79
+ static VALUE read_memory( VALUE klass,
80
+ VALUE string,
81
+ VALUE url,
82
+ VALUE encoding,
83
+ VALUE options )
84
+ {
85
+ const char * c_buffer = StringValuePtr(string);
86
+ const char * c_url = (url == Qnil) ? NULL : StringValuePtr(url);
87
+ const char * c_enc = (encoding == Qnil) ? NULL : StringValuePtr(encoding);
88
+ int len = NUM2INT(rb_funcall(string, rb_intern("length"), 0));
89
+
90
+ xmlInitParser();
91
+ xmlDocPtr doc = xmlReadMemory(c_buffer, len, c_url, c_enc, NUM2INT(options));
92
+
93
+ if(doc == NULL) {
94
+ xmlFreeDoc(doc);
95
+ rb_raise(rb_eRuntimeError, "Couldn't create a document");
96
+ }
97
+
98
+ return Nokogiri_wrap_xml_document(klass, doc);
99
+ }
100
+
101
+ static VALUE new(int argc, VALUE *argv, VALUE klass)
102
+ {
103
+ VALUE version;
104
+ if(rb_scan_args(argc, argv, "01", &version) == 0)
105
+ version = rb_str_new2("1.0");
106
+
107
+ xmlDocPtr doc = xmlNewDoc((xmlChar *)StringValuePtr(version));
108
+ return Nokogiri_wrap_xml_document(klass, doc);
109
+ }
110
+
111
+ /*
112
+ * call-seq:
113
+ * substitute_entities_set bool)
114
+ *
115
+ * Set the global XML default for substitute entities.
116
+ */
117
+ static VALUE substitute_entities_set(VALUE klass, VALUE value)
118
+ {
119
+ xmlSubstituteEntitiesDefault(NUM2INT(value));
120
+ return Qnil ;
121
+ }
122
+
123
+ /*
124
+ * call-seq:
125
+ * substitute_entities_set bool)
126
+ *
127
+ * Set the global XML default for load external subsets.
128
+ */
129
+ static VALUE load_external_subsets_set(VALUE klass, VALUE value)
130
+ {
131
+ xmlLoadExtDtdDefaultValue = NUM2INT(value);
132
+ return Qnil ;
133
+ }
134
+
135
+ VALUE cNokogiriXmlDocument ;
136
+ void init_xml_document()
137
+ {
138
+ VALUE klass = cNokogiriXmlDocument = rb_const_get(mNokogiriXml, rb_intern("Document"));
139
+
140
+ rb_define_singleton_method(klass, "read_memory", read_memory, 4);
141
+ rb_define_singleton_method(klass, "new", new, -1);
142
+ rb_define_singleton_method(klass, "substitute_entities=", substitute_entities_set, 1);
143
+ rb_define_singleton_method(klass, "load_external_subsets=", load_external_subsets_set, 1);
144
+
145
+ rb_define_method(klass, "root", root, 0);
146
+ rb_define_method(klass, "root=", set_root, 1);
147
+ rb_define_method(klass, "serialize", serialize, 0);
148
+ }
149
+
150
+
151
+ /* this takes klass as a param because it's used for HtmlDocument, too. */
152
+ VALUE Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc)
153
+ {
154
+ if (doc->_private)
155
+ return (VALUE)doc->_private ;
156
+ VALUE rb_doc = Data_Wrap_Struct(klass ? klass : cNokogiriXmlDocument, gc_mark, dealloc, doc) ;
157
+ doc->_private = (void*)rb_doc ;
158
+ return rb_doc ;
159
+ }
@@ -0,0 +1,10 @@
1
+ #ifndef NOKOGIRI_XML_DOCUMENT
2
+ #define NOKOGIRI_XML_DOCUMENT
3
+
4
+ #include <native.h>
5
+
6
+ void init_xml_document();
7
+ VALUE Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc);
8
+
9
+ extern VALUE cNokogiriXmlDocument ;
10
+ #endif
@@ -0,0 +1,117 @@
1
+ #include <xml_dtd.h>
2
+
3
+ static void notation_copier(void *payload, void *data, xmlChar *name)
4
+ {
5
+ VALUE hash = (VALUE)data;
6
+ VALUE klass = rb_const_get(mNokogiriXml, rb_intern("Notation"));
7
+
8
+ xmlNotationPtr c_notation = (xmlNotationPtr)payload;
9
+
10
+ VALUE notation = rb_funcall(klass, rb_intern("new"), 3,
11
+ c_notation->name ? rb_str_new2((const char *)c_notation->name) : Qnil,
12
+ c_notation->PublicID ? rb_str_new2((const char *)c_notation->PublicID) : Qnil,
13
+ c_notation->SystemID ? rb_str_new2((const char *)c_notation->SystemID) : Qnil);
14
+
15
+ rb_hash_aset(hash, rb_str_new2((const char *)name), notation);
16
+ }
17
+
18
+ static void element_copier(void *payload, void *data, xmlChar *name)
19
+ {
20
+ VALUE hash = (VALUE)data;
21
+
22
+ VALUE element = Nokogiri_wrap_xml_node((xmlNodePtr)payload);
23
+
24
+ rb_hash_aset(hash, rb_str_new2((const char *)name), element);
25
+ }
26
+
27
+ /*
28
+ * call-seq:
29
+ * entities
30
+ *
31
+ * Get a hash of the elements for this DTD.
32
+ */
33
+ static VALUE entities(VALUE self)
34
+ {
35
+ xmlDtdPtr dtd;
36
+ Data_Get_Struct(self, xmlDtd, dtd);
37
+
38
+ if(!dtd->entities) return Qnil;
39
+
40
+ VALUE hash = rb_hash_new();
41
+
42
+ xmlHashScan((xmlHashTablePtr)dtd->entities, element_copier, (void *)hash);
43
+
44
+ return hash;
45
+ }
46
+
47
+ /*
48
+ * call-seq:
49
+ * attributes
50
+ *
51
+ * Get a hash of the attributes for this DTD.
52
+ */
53
+ static VALUE attributes(VALUE self)
54
+ {
55
+ xmlDtdPtr dtd;
56
+ Data_Get_Struct(self, xmlDtd, dtd);
57
+
58
+ if(!dtd->attributes) return Qnil;
59
+
60
+ VALUE hash = rb_hash_new();
61
+
62
+ xmlHashScan((xmlHashTablePtr)dtd->attributes, element_copier, (void *)hash);
63
+
64
+ return hash;
65
+ }
66
+
67
+ /*
68
+ * call-seq:
69
+ * notations
70
+ *
71
+ * Get a hash of the notations for this DTD.
72
+ */
73
+ static VALUE notations(VALUE self)
74
+ {
75
+ xmlDtdPtr dtd;
76
+ Data_Get_Struct(self, xmlDtd, dtd);
77
+
78
+ if(!dtd->notations) return Qnil;
79
+
80
+ VALUE hash = rb_hash_new();
81
+
82
+ xmlHashScan((xmlHashTablePtr)dtd->notations, notation_copier, (void *)hash);
83
+
84
+ return hash;
85
+ }
86
+
87
+ /*
88
+ * call-seq:
89
+ * elements
90
+ *
91
+ * Get a hash of the elements for this DTD.
92
+ */
93
+ static VALUE elements(VALUE self)
94
+ {
95
+ xmlDtdPtr dtd;
96
+ Data_Get_Struct(self, xmlDtd, dtd);
97
+
98
+ if(!dtd->elements) return Qnil;
99
+
100
+ VALUE hash = rb_hash_new();
101
+
102
+ xmlHashScan((xmlHashTablePtr)dtd->elements, element_copier, (void *)hash);
103
+
104
+ return hash;
105
+ }
106
+
107
+ void init_xml_dtd()
108
+ {
109
+ VALUE nokogiri = rb_define_module("Nokogiri");
110
+ VALUE xml = rb_define_module_under(nokogiri, "XML");
111
+ VALUE klass = rb_define_class_under(xml, "DTD", cNokogiriXmlNode);
112
+
113
+ rb_define_method(klass, "notations", notations, 0);
114
+ rb_define_method(klass, "elements", elements, 0);
115
+ rb_define_method(klass, "attributes", attributes, 0);
116
+ rb_define_method(klass, "entities", entities, 0);
117
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef NOKOGIRI_XML_DTD
2
+ #define NOKOGIRI_XML_DTD
3
+
4
+ #include <native.h>
5
+
6
+ void init_xml_dtd();
7
+
8
+ #endif