nokogiri 1.1.1-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.
- data/History.ja.txt +99 -0
- data/History.txt +99 -0
- data/Manifest.txt +141 -0
- data/README.ja.txt +100 -0
- data/README.txt +109 -0
- data/Rakefile +354 -0
- data/ext/nokogiri/extconf.rb +93 -0
- data/ext/nokogiri/html_document.c +86 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_sax_parser.c +36 -0
- data/ext/nokogiri/html_sax_parser.h +11 -0
- data/ext/nokogiri/native.c +41 -0
- data/ext/nokogiri/native.h +50 -0
- data/ext/nokogiri/xml_cdata.c +44 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +42 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +206 -0
- data/ext/nokogiri/xml_document.h +10 -0
- data/ext/nokogiri/xml_dtd.c +121 -0
- data/ext/nokogiri/xml_dtd.h +8 -0
- data/ext/nokogiri/xml_io.c +17 -0
- data/ext/nokogiri/xml_io.h +9 -0
- data/ext/nokogiri/xml_node.c +727 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +118 -0
- data/ext/nokogiri/xml_node_set.h +9 -0
- data/ext/nokogiri/xml_reader.c +465 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_sax_parser.c +201 -0
- data/ext/nokogiri/xml_sax_parser.h +10 -0
- data/ext/nokogiri/xml_syntax_error.c +199 -0
- data/ext/nokogiri/xml_syntax_error.h +11 -0
- data/ext/nokogiri/xml_text.c +40 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath.c +53 -0
- data/ext/nokogiri/xml_xpath.h +11 -0
- data/ext/nokogiri/xml_xpath_context.c +214 -0
- data/ext/nokogiri/xml_xpath_context.h +9 -0
- data/ext/nokogiri/xslt_stylesheet.c +123 -0
- data/ext/nokogiri/xslt_stylesheet.h +9 -0
- data/lib/action-nokogiri.rb +30 -0
- data/lib/nokogiri.rb +72 -0
- data/lib/nokogiri/css.rb +25 -0
- data/lib/nokogiri/css/generated_parser.rb +721 -0
- data/lib/nokogiri/css/generated_tokenizer.rb +159 -0
- data/lib/nokogiri/css/node.rb +97 -0
- data/lib/nokogiri/css/parser.rb +64 -0
- data/lib/nokogiri/css/parser.y +216 -0
- data/lib/nokogiri/css/syntax_error.rb +6 -0
- data/lib/nokogiri/css/tokenizer.rb +9 -0
- data/lib/nokogiri/css/tokenizer.rex +63 -0
- data/lib/nokogiri/css/xpath_visitor.rb +168 -0
- data/lib/nokogiri/decorators.rb +2 -0
- data/lib/nokogiri/decorators/hpricot.rb +3 -0
- data/lib/nokogiri/decorators/hpricot/node.rb +56 -0
- data/lib/nokogiri/decorators/hpricot/node_set.rb +54 -0
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +28 -0
- data/lib/nokogiri/decorators/slop.rb +31 -0
- data/lib/nokogiri/hpricot.rb +51 -0
- data/lib/nokogiri/html.rb +105 -0
- data/lib/nokogiri/html/builder.rb +9 -0
- data/lib/nokogiri/html/document.rb +9 -0
- data/lib/nokogiri/html/sax/parser.rb +21 -0
- data/lib/nokogiri/version.rb +3 -0
- data/lib/nokogiri/xml.rb +83 -0
- data/lib/nokogiri/xml/after_handler.rb +18 -0
- data/lib/nokogiri/xml/attr.rb +10 -0
- data/lib/nokogiri/xml/before_handler.rb +33 -0
- data/lib/nokogiri/xml/builder.rb +84 -0
- data/lib/nokogiri/xml/cdata.rb +9 -0
- data/lib/nokogiri/xml/comment.rb +6 -0
- data/lib/nokogiri/xml/document.rb +55 -0
- data/lib/nokogiri/xml/dtd.rb +6 -0
- data/lib/nokogiri/xml/element.rb +6 -0
- data/lib/nokogiri/xml/entity_declaration.rb +9 -0
- data/lib/nokogiri/xml/node.rb +333 -0
- data/lib/nokogiri/xml/node_set.rb +197 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/reader.rb +20 -0
- data/lib/nokogiri/xml/sax.rb +9 -0
- data/lib/nokogiri/xml/sax/document.rb +59 -0
- data/lib/nokogiri/xml/sax/parser.rb +37 -0
- data/lib/nokogiri/xml/syntax_error.rb +21 -0
- data/lib/nokogiri/xml/text.rb +6 -0
- data/lib/nokogiri/xml/xpath.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +8 -0
- data/lib/nokogiri/xml/xpath_context.rb +14 -0
- data/lib/nokogiri/xslt.rb +28 -0
- data/lib/nokogiri/xslt/stylesheet.rb +6 -0
- data/test/css/test_nthiness.rb +159 -0
- data/test/css/test_parser.rb +237 -0
- data/test/css/test_tokenizer.rb +162 -0
- data/test/css/test_xpath_visitor.rb +64 -0
- data/test/files/dont_hurt_em_why.xml +422 -0
- data/test/files/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -0
- data/test/files/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/helper.rb +78 -0
- data/test/hpricot/files/basic.xhtml +17 -0
- data/test/hpricot/files/boingboing.html +2266 -0
- data/test/hpricot/files/cy0.html +3653 -0
- data/test/hpricot/files/immob.html +400 -0
- data/test/hpricot/files/pace_application.html +1320 -0
- data/test/hpricot/files/tenderlove.html +16 -0
- data/test/hpricot/files/uswebgen.html +220 -0
- data/test/hpricot/files/utf8.html +1054 -0
- data/test/hpricot/files/week9.html +1723 -0
- data/test/hpricot/files/why.xml +19 -0
- data/test/hpricot/load_files.rb +11 -0
- data/test/hpricot/test_alter.rb +67 -0
- data/test/hpricot/test_builder.rb +27 -0
- data/test/hpricot/test_parser.rb +426 -0
- data/test/hpricot/test_paths.rb +15 -0
- data/test/hpricot/test_preserved.rb +77 -0
- data/test/hpricot/test_xml.rb +30 -0
- data/test/html/sax/test_parser.rb +27 -0
- data/test/html/test_builder.rb +89 -0
- data/test/html/test_document.rb +150 -0
- data/test/html/test_node.rb +21 -0
- data/test/test_convert_xpath.rb +185 -0
- data/test/test_css_cache.rb +57 -0
- data/test/test_gc.rb +15 -0
- data/test/test_memory_leak.rb +38 -0
- data/test/test_nokogiri.rb +97 -0
- data/test/test_reader.rb +222 -0
- data/test/test_xslt_transforms.rb +93 -0
- data/test/xml/sax/test_parser.rb +95 -0
- data/test/xml/test_attr.rb +15 -0
- data/test/xml/test_builder.rb +16 -0
- data/test/xml/test_cdata.rb +18 -0
- data/test/xml/test_comment.rb +16 -0
- data/test/xml/test_document.rb +195 -0
- data/test/xml/test_dtd.rb +43 -0
- data/test/xml/test_node.rb +394 -0
- data/test/xml/test_node_set.rb +143 -0
- data/test/xml/test_text.rb +13 -0
- data/test/xml/test_xpath.rb +105 -0
- data/vendor/hoe.rb +1020 -0
- metadata +233 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
#include <html_sax_parser.h>
|
2
|
+
|
3
|
+
static VALUE native_parse_file(VALUE self, VALUE data, VALUE encoding)
|
4
|
+
{
|
5
|
+
xmlSAXHandlerPtr handler;
|
6
|
+
htmlDocPtr hdoc ;
|
7
|
+
Data_Get_Struct(self, xmlSAXHandler, handler);
|
8
|
+
hdoc = htmlSAXParseFile( StringValuePtr(data),
|
9
|
+
(const char *)StringValuePtr(encoding),
|
10
|
+
(htmlSAXHandlerPtr)handler,
|
11
|
+
(void *)self );
|
12
|
+
xmlFreeDoc(hdoc);
|
13
|
+
return data;
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE native_parse_memory(VALUE self, VALUE data, VALUE encoding)
|
17
|
+
{
|
18
|
+
xmlSAXHandlerPtr handler;
|
19
|
+
htmlDocPtr hdoc ;
|
20
|
+
Data_Get_Struct(self, xmlSAXHandler, handler);
|
21
|
+
hdoc = htmlSAXParseDoc( (xmlChar *)StringValuePtr(data),
|
22
|
+
(const char *)StringValuePtr(encoding),
|
23
|
+
(htmlSAXHandlerPtr)handler,
|
24
|
+
(void *)self );
|
25
|
+
xmlFreeDoc(hdoc);
|
26
|
+
return data;
|
27
|
+
}
|
28
|
+
|
29
|
+
VALUE cNokogiriHtmlSaxParser ;
|
30
|
+
void init_html_sax_parser()
|
31
|
+
{
|
32
|
+
VALUE klass = cNokogiriHtmlSaxParser =
|
33
|
+
rb_const_get(mNokogiriHtmlSax, rb_intern("Parser"));
|
34
|
+
rb_define_private_method(klass, "native_parse_memory", native_parse_memory, 2);
|
35
|
+
rb_define_private_method(klass, "native_parse_file", native_parse_file, 2);
|
36
|
+
}
|
@@ -0,0 +1,41 @@
|
|
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_comment();
|
32
|
+
init_xml_node_set();
|
33
|
+
init_xml_xpath_context();
|
34
|
+
init_xml_xpath();
|
35
|
+
init_xml_sax_parser();
|
36
|
+
init_xml_reader();
|
37
|
+
init_xml_dtd();
|
38
|
+
init_html_sax_parser();
|
39
|
+
init_xslt_stylesheet();
|
40
|
+
init_xml_syntax_error();
|
41
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#ifndef NOKOGIRI_NATIVE
|
2
|
+
#define NOKOGIRI_NATIVE
|
3
|
+
|
4
|
+
#include <stdlib.h>
|
5
|
+
#include <assert.h>
|
6
|
+
#include <ruby.h>
|
7
|
+
#include <libxml/parser.h>
|
8
|
+
#include <libxml/xpath.h>
|
9
|
+
#include <libxml/xpathInternals.h>
|
10
|
+
#include <libxml/xmlreader.h>
|
11
|
+
#include <libxml/HTMLparser.h>
|
12
|
+
#include <libxml/HTMLtree.h>
|
13
|
+
|
14
|
+
#include <xml_io.h>
|
15
|
+
#include <xml_document.h>
|
16
|
+
#include <html_document.h>
|
17
|
+
#include <xml_node.h>
|
18
|
+
#include <xml_text.h>
|
19
|
+
#include <xml_cdata.h>
|
20
|
+
#include <xml_comment.h>
|
21
|
+
#include <xml_node_set.h>
|
22
|
+
#include <xml_xpath.h>
|
23
|
+
#include <xml_dtd.h>
|
24
|
+
#include <xml_xpath_context.h>
|
25
|
+
#include <xml_sax_parser.h>
|
26
|
+
#include <xml_reader.h>
|
27
|
+
#include <html_sax_parser.h>
|
28
|
+
#include <xslt_stylesheet.h>
|
29
|
+
#include <xml_syntax_error.h>
|
30
|
+
|
31
|
+
extern VALUE mNokogiri ;
|
32
|
+
extern VALUE mNokogiriXml ;
|
33
|
+
extern VALUE mNokogiriXmlSax ;
|
34
|
+
extern VALUE mNokogiriHtml ;
|
35
|
+
extern VALUE mNokogiriHtmlSax ;
|
36
|
+
extern VALUE mNokogiriXslt ;
|
37
|
+
|
38
|
+
#ifdef DEBUG
|
39
|
+
|
40
|
+
#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);
|
41
|
+
#define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
|
42
|
+
|
43
|
+
#else
|
44
|
+
|
45
|
+
#define NOKOGIRI_DEBUG_START(p)
|
46
|
+
#define NOKOGIRI_DEBUG_END(p)
|
47
|
+
|
48
|
+
#endif
|
49
|
+
|
50
|
+
#endif
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#include <xml_cdata.h>
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* new(document, content)
|
6
|
+
*
|
7
|
+
* Create a new CData element on the +document+ with +content+
|
8
|
+
*/
|
9
|
+
static VALUE new(VALUE klass, VALUE doc, VALUE content)
|
10
|
+
{
|
11
|
+
xmlDocPtr xml_doc;
|
12
|
+
Data_Get_Struct(doc, xmlDoc, xml_doc);
|
13
|
+
|
14
|
+
xmlNodePtr node = xmlNewCDataBlock(
|
15
|
+
xml_doc,
|
16
|
+
(const xmlChar *)StringValuePtr(content),
|
17
|
+
NUM2INT(rb_funcall(content, rb_intern("length"), 0))
|
18
|
+
);
|
19
|
+
|
20
|
+
VALUE rb_node = Nokogiri_wrap_xml_node(node);
|
21
|
+
|
22
|
+
if(rb_block_given_p()) rb_yield(rb_node);
|
23
|
+
|
24
|
+
return rb_node;
|
25
|
+
}
|
26
|
+
|
27
|
+
VALUE cNokogiriXmlCData;
|
28
|
+
void init_xml_cdata()
|
29
|
+
{
|
30
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
31
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
32
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
33
|
+
VALUE text = rb_define_class_under(xml, "Text", node);
|
34
|
+
|
35
|
+
/*
|
36
|
+
* CData represents a CData node in an xml document.
|
37
|
+
*/
|
38
|
+
VALUE klass = rb_define_class_under(xml, "CDATA", text);
|
39
|
+
|
40
|
+
|
41
|
+
cNokogiriXmlCData = klass;
|
42
|
+
|
43
|
+
rb_define_singleton_method(klass, "new", new, 2);
|
44
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#include <xml_comment.h>
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* new(document, content)
|
6
|
+
*
|
7
|
+
* Create a new Comment element on the +document+ with +content+
|
8
|
+
*/
|
9
|
+
static VALUE new(VALUE klass, VALUE doc, VALUE content)
|
10
|
+
{
|
11
|
+
xmlDocPtr xml_doc;
|
12
|
+
Data_Get_Struct(doc, xmlDoc, xml_doc);
|
13
|
+
|
14
|
+
xmlNodePtr node = xmlNewDocComment(
|
15
|
+
xml_doc,
|
16
|
+
(const xmlChar *)StringValuePtr(content)
|
17
|
+
);
|
18
|
+
|
19
|
+
VALUE rb_node = Nokogiri_wrap_xml_node(node);
|
20
|
+
|
21
|
+
if(rb_block_given_p()) rb_yield(rb_node);
|
22
|
+
|
23
|
+
return rb_node;
|
24
|
+
}
|
25
|
+
|
26
|
+
VALUE cNokogiriXmlComment;
|
27
|
+
void init_xml_comment()
|
28
|
+
{
|
29
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
30
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
31
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
32
|
+
|
33
|
+
/*
|
34
|
+
* Comment represents a comment node in an xml document.
|
35
|
+
*/
|
36
|
+
VALUE klass = rb_define_class_under(xml, "Comment", node);
|
37
|
+
|
38
|
+
|
39
|
+
cNokogiriXmlComment = klass;
|
40
|
+
|
41
|
+
rb_define_singleton_method(klass, "new", new, 2);
|
42
|
+
}
|
@@ -0,0 +1,206 @@
|
|
1
|
+
#include <xml_document.h>
|
2
|
+
|
3
|
+
static void dealloc(xmlDocPtr doc)
|
4
|
+
{
|
5
|
+
NOKOGIRI_DEBUG_START(doc);
|
6
|
+
doc->_private = NULL;
|
7
|
+
xmlFreeDoc(doc);
|
8
|
+
NOKOGIRI_DEBUG_END(doc);
|
9
|
+
}
|
10
|
+
|
11
|
+
/*
|
12
|
+
* call-seq:
|
13
|
+
* serialize
|
14
|
+
*
|
15
|
+
* Serialize this document
|
16
|
+
*/
|
17
|
+
static VALUE serialize(VALUE self)
|
18
|
+
{
|
19
|
+
xmlDocPtr doc;
|
20
|
+
xmlChar *buf;
|
21
|
+
int size;
|
22
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
23
|
+
|
24
|
+
xmlDocDumpMemory(doc, &buf, &size);
|
25
|
+
VALUE rb_str = rb_str_new((char *)buf, (long)size);
|
26
|
+
xmlFree(buf);
|
27
|
+
return rb_str;
|
28
|
+
}
|
29
|
+
|
30
|
+
/*
|
31
|
+
* call-seq:
|
32
|
+
* root=
|
33
|
+
*
|
34
|
+
* Set the root element on this document
|
35
|
+
*/
|
36
|
+
static VALUE set_root(VALUE self, VALUE root)
|
37
|
+
{
|
38
|
+
xmlDocPtr doc;
|
39
|
+
xmlNodePtr new_root;
|
40
|
+
|
41
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
42
|
+
Data_Get_Struct(root, xmlNode, new_root);
|
43
|
+
|
44
|
+
xmlDocSetRootElement(doc, new_root);
|
45
|
+
return root;
|
46
|
+
}
|
47
|
+
|
48
|
+
/*
|
49
|
+
* call-seq:
|
50
|
+
* root
|
51
|
+
*
|
52
|
+
* Get the root node for this document.
|
53
|
+
*/
|
54
|
+
static VALUE root(VALUE self)
|
55
|
+
{
|
56
|
+
xmlDocPtr doc;
|
57
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
58
|
+
|
59
|
+
xmlNodePtr root = xmlDocGetRootElement(doc);
|
60
|
+
|
61
|
+
if(!root) return Qnil;
|
62
|
+
return Nokogiri_wrap_xml_node(root) ;
|
63
|
+
}
|
64
|
+
|
65
|
+
/*
|
66
|
+
* call-seq:
|
67
|
+
* read_io(io, url, encoding, options)
|
68
|
+
*
|
69
|
+
* Create a new document from an IO object
|
70
|
+
*/
|
71
|
+
static VALUE read_io( VALUE klass,
|
72
|
+
VALUE io,
|
73
|
+
VALUE url,
|
74
|
+
VALUE encoding,
|
75
|
+
VALUE options )
|
76
|
+
{
|
77
|
+
const char * c_url = (url == Qnil) ? NULL : StringValuePtr(url);
|
78
|
+
const char * c_enc = (encoding == Qnil) ? NULL : StringValuePtr(encoding);
|
79
|
+
|
80
|
+
xmlInitParser();
|
81
|
+
|
82
|
+
xmlDocPtr doc = xmlReadIO(
|
83
|
+
(xmlInputReadCallback)io_read_callback,
|
84
|
+
(xmlInputCloseCallback)io_close_callback,
|
85
|
+
(void *)io,
|
86
|
+
c_url,
|
87
|
+
c_enc,
|
88
|
+
NUM2INT(options)
|
89
|
+
);
|
90
|
+
|
91
|
+
if(doc == NULL) {
|
92
|
+
xmlFreeDoc(doc);
|
93
|
+
rb_raise(rb_eRuntimeError, "Couldn't create a document");
|
94
|
+
return Qnil;
|
95
|
+
}
|
96
|
+
|
97
|
+
return Nokogiri_wrap_xml_document(klass, doc);
|
98
|
+
}
|
99
|
+
|
100
|
+
/*
|
101
|
+
* call-seq:
|
102
|
+
* read_memory(string, url, encoding, options)
|
103
|
+
*
|
104
|
+
* Create a new document from a String
|
105
|
+
*/
|
106
|
+
static VALUE read_memory( VALUE klass,
|
107
|
+
VALUE string,
|
108
|
+
VALUE url,
|
109
|
+
VALUE encoding,
|
110
|
+
VALUE options )
|
111
|
+
{
|
112
|
+
const char * c_buffer = StringValuePtr(string);
|
113
|
+
const char * c_url = (url == Qnil) ? NULL : StringValuePtr(url);
|
114
|
+
const char * c_enc = (encoding == Qnil) ? NULL : StringValuePtr(encoding);
|
115
|
+
int len = NUM2INT(rb_funcall(string, rb_intern("length"), 0));
|
116
|
+
|
117
|
+
xmlInitParser();
|
118
|
+
xmlDocPtr doc = xmlReadMemory(c_buffer, len, c_url, c_enc, NUM2INT(options));
|
119
|
+
|
120
|
+
if(doc == NULL) {
|
121
|
+
xmlFreeDoc(doc);
|
122
|
+
rb_raise(rb_eRuntimeError, "Couldn't create a document");
|
123
|
+
return Qnil;
|
124
|
+
}
|
125
|
+
|
126
|
+
return Nokogiri_wrap_xml_document(klass, doc);
|
127
|
+
}
|
128
|
+
|
129
|
+
/*
|
130
|
+
* call-seq:
|
131
|
+
* new
|
132
|
+
*
|
133
|
+
* Create a new document
|
134
|
+
*/
|
135
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
136
|
+
{
|
137
|
+
VALUE version;
|
138
|
+
if(rb_scan_args(argc, argv, "01", &version) == 0)
|
139
|
+
version = rb_str_new2("1.0");
|
140
|
+
|
141
|
+
xmlDocPtr doc = xmlNewDoc((xmlChar *)StringValuePtr(version));
|
142
|
+
return Nokogiri_wrap_xml_document(klass, doc);
|
143
|
+
}
|
144
|
+
|
145
|
+
/*
|
146
|
+
* call-seq:
|
147
|
+
* substitute_entities=(boolean)
|
148
|
+
*
|
149
|
+
* Set the global XML default for substitute entities.
|
150
|
+
*/
|
151
|
+
static VALUE substitute_entities_set(VALUE klass, VALUE value)
|
152
|
+
{
|
153
|
+
xmlSubstituteEntitiesDefault(NUM2INT(value));
|
154
|
+
return Qnil ;
|
155
|
+
}
|
156
|
+
|
157
|
+
/*
|
158
|
+
* call-seq:
|
159
|
+
* load_external_subsets=(boolean)
|
160
|
+
*
|
161
|
+
* Set the global XML default for load external subsets.
|
162
|
+
*/
|
163
|
+
static VALUE load_external_subsets_set(VALUE klass, VALUE value)
|
164
|
+
{
|
165
|
+
xmlLoadExtDtdDefaultValue = NUM2INT(value);
|
166
|
+
return Qnil ;
|
167
|
+
}
|
168
|
+
|
169
|
+
VALUE cNokogiriXmlDocument ;
|
170
|
+
void init_xml_document()
|
171
|
+
{
|
172
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
173
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
174
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
175
|
+
|
176
|
+
/*
|
177
|
+
* Nokogiri::XML::Document wraps an xml document.
|
178
|
+
*/
|
179
|
+
VALUE klass = rb_define_class_under(xml, "Document", node);
|
180
|
+
|
181
|
+
cNokogiriXmlDocument = klass;
|
182
|
+
|
183
|
+
rb_define_singleton_method(klass, "read_memory", read_memory, 4);
|
184
|
+
rb_define_singleton_method(klass, "read_io", read_io, 4);
|
185
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
186
|
+
rb_define_singleton_method(klass, "substitute_entities=", substitute_entities_set, 1);
|
187
|
+
rb_define_singleton_method(klass, "load_external_subsets=", load_external_subsets_set, 1);
|
188
|
+
|
189
|
+
rb_define_method(klass, "root", root, 0);
|
190
|
+
rb_define_method(klass, "root=", set_root, 1);
|
191
|
+
rb_define_method(klass, "serialize", serialize, 0);
|
192
|
+
rb_undef_method(klass, "parent");
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
/* this takes klass as a param because it's used for HtmlDocument, too. */
|
197
|
+
VALUE Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc)
|
198
|
+
{
|
199
|
+
VALUE rb_doc = Qnil;
|
200
|
+
|
201
|
+
rb_doc = Data_Wrap_Struct(klass ? klass : cNokogiriXmlDocument, 0, dealloc, doc) ;
|
202
|
+
rb_iv_set(rb_doc, "@decorators", Qnil);
|
203
|
+
doc->_private = (void *)rb_doc;
|
204
|
+
|
205
|
+
return rb_doc ;
|
206
|
+
}
|