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.
- data/.autotest +14 -2
- data/CHANGELOG.ja.rdoc +38 -0
- data/CHANGELOG.rdoc +43 -0
- data/Manifest.txt +80 -5
- data/README.ja.rdoc +12 -11
- data/README.rdoc +4 -2
- data/Rakefile +103 -173
- data/bin/nokogiri +47 -0
- data/ext/nokogiri/extconf.rb +19 -13
- data/ext/nokogiri/html_document.c +39 -3
- data/ext/nokogiri/html_document.h +1 -1
- data/ext/nokogiri/html_element_description.c +272 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.h +1 -1
- data/ext/nokogiri/html_sax_parser.h +1 -1
- data/ext/nokogiri/{native.c → nokogiri.c} +11 -3
- data/ext/nokogiri/{native.h → nokogiri.h} +18 -4
- data/ext/nokogiri/xml_attr.c +14 -5
- data/ext/nokogiri/xml_attr.h +1 -1
- data/ext/nokogiri/xml_cdata.c +15 -6
- data/ext/nokogiri/xml_cdata.h +1 -1
- data/ext/nokogiri/xml_comment.c +13 -4
- data/ext/nokogiri/xml_comment.h +1 -1
- data/ext/nokogiri/xml_document.c +50 -41
- data/ext/nokogiri/xml_document.h +1 -1
- data/ext/nokogiri/xml_document_fragment.c +12 -4
- data/ext/nokogiri/xml_document_fragment.h +1 -1
- data/ext/nokogiri/xml_dtd.c +1 -1
- data/ext/nokogiri/xml_dtd.h +1 -1
- data/ext/nokogiri/xml_entity_reference.c +13 -4
- data/ext/nokogiri/xml_entity_reference.h +1 -1
- data/ext/nokogiri/xml_io.h +1 -1
- data/ext/nokogiri/xml_namespace.c +69 -0
- data/ext/nokogiri/xml_namespace.h +12 -0
- data/ext/nokogiri/xml_node.c +232 -124
- data/ext/nokogiri/xml_node.h +3 -4
- data/ext/nokogiri/xml_node_set.c +204 -17
- data/ext/nokogiri/xml_node_set.h +1 -1
- data/ext/nokogiri/xml_processing_instruction.c +14 -4
- data/ext/nokogiri/xml_processing_instruction.h +1 -1
- data/ext/nokogiri/xml_reader.c +87 -7
- data/ext/nokogiri/xml_reader.h +1 -1
- data/ext/nokogiri/xml_relax_ng.c +106 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +122 -2
- data/ext/nokogiri/xml_sax_parser.h +1 -1
- data/ext/nokogiri/xml_sax_push_parser.c +1 -0
- data/ext/nokogiri/xml_sax_push_parser.h +1 -1
- data/ext/nokogiri/xml_schema.c +107 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.h +1 -1
- data/ext/nokogiri/xml_text.c +10 -3
- data/ext/nokogiri/xml_text.h +1 -1
- data/ext/nokogiri/xml_xpath.h +1 -1
- data/ext/nokogiri/xml_xpath_context.h +1 -1
- data/ext/nokogiri/xslt_stylesheet.c +29 -16
- data/ext/nokogiri/xslt_stylesheet.h +1 -1
- data/lib/action-nokogiri.rb +7 -1
- data/lib/nokogiri.rb +21 -5
- data/lib/nokogiri/css/generated_parser.rb +49 -14
- data/lib/nokogiri/css/generated_tokenizer.rb +2 -2
- data/lib/nokogiri/css/node.rb +13 -3
- data/lib/nokogiri/css/parser.rb +8 -0
- data/lib/nokogiri/css/parser.y +7 -7
- data/lib/nokogiri/css/tokenizer.rb +2 -0
- data/lib/nokogiri/css/xpath_visitor.rb +10 -6
- data/lib/nokogiri/decorators/hpricot/node.rb +1 -1
- data/lib/nokogiri/decorators/hpricot/node_set.rb +2 -2
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +2 -0
- data/lib/nokogiri/decorators/slop.rb +3 -1
- data/lib/nokogiri/ffi/html/document.rb +37 -0
- data/lib/nokogiri/ffi/html/element_description.rb +85 -0
- data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
- data/lib/nokogiri/ffi/html/sax/parser.rb +21 -0
- data/lib/nokogiri/ffi/io_callbacks.rb +32 -0
- data/lib/nokogiri/ffi/libxml.rb +314 -0
- data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
- data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
- data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +26 -0
- data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
- data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
- data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
- data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
- data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
- data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
- data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
- data/lib/nokogiri/ffi/xml/attr.rb +41 -0
- data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
- data/lib/nokogiri/ffi/xml/comment.rb +18 -0
- data/lib/nokogiri/ffi/xml/document.rb +107 -0
- data/lib/nokogiri/ffi/xml/document_fragment.rb +26 -0
- data/lib/nokogiri/ffi/xml/dtd.rb +42 -0
- data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/ffi/xml/namespace.rb +38 -0
- data/lib/nokogiri/ffi/xml/node.rb +380 -0
- data/lib/nokogiri/ffi/xml/node_set.rb +130 -0
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
- data/lib/nokogiri/ffi/xml/reader.rb +217 -0
- data/lib/nokogiri/ffi/xml/relax_ng.rb +51 -0
- data/lib/nokogiri/ffi/xml/sax/parser.rb +148 -0
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +38 -0
- data/lib/nokogiri/ffi/xml/schema.rb +55 -0
- data/lib/nokogiri/ffi/xml/syntax_error.rb +76 -0
- data/lib/nokogiri/ffi/xml/text.rb +18 -0
- data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
- data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +47 -0
- data/lib/nokogiri/hpricot.rb +14 -3
- data/lib/nokogiri/html.rb +11 -46
- data/lib/nokogiri/html/builder.rb +27 -1
- data/lib/nokogiri/html/document.rb +62 -6
- data/lib/nokogiri/html/document_fragment.rb +15 -0
- data/lib/nokogiri/html/element_description.rb +23 -0
- data/lib/nokogiri/html/entity_lookup.rb +2 -0
- data/lib/nokogiri/html/sax/parser.rb +27 -1
- data/lib/nokogiri/version.rb +26 -1
- data/lib/nokogiri/version_warning.rb +11 -0
- data/lib/nokogiri/xml.rb +25 -51
- data/lib/nokogiri/xml/builder.rb +166 -10
- data/lib/nokogiri/xml/cdata.rb +3 -1
- data/lib/nokogiri/xml/document.rb +39 -6
- data/lib/nokogiri/xml/document_fragment.rb +41 -1
- data/lib/nokogiri/xml/dtd.rb +3 -1
- data/lib/nokogiri/xml/entity_declaration.rb +3 -1
- data/lib/nokogiri/xml/fragment_handler.rb +24 -3
- data/lib/nokogiri/xml/namespace.rb +7 -0
- data/lib/nokogiri/xml/node.rb +314 -65
- data/lib/nokogiri/xml/node/save_options.rb +12 -2
- data/lib/nokogiri/xml/node_set.rb +58 -8
- data/lib/nokogiri/xml/parse_options.rb +80 -0
- data/lib/nokogiri/xml/processing_instruction.rb +2 -0
- data/lib/nokogiri/xml/reader.rb +42 -3
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +0 -7
- data/lib/nokogiri/xml/sax/document.rb +84 -0
- data/lib/nokogiri/xml/sax/parser.rb +38 -2
- data/lib/nokogiri/xml/sax/push_parser.rb +12 -0
- data/lib/nokogiri/xml/schema.rb +65 -0
- data/lib/nokogiri/xml/syntax_error.rb +11 -0
- data/lib/nokogiri/xml/xpath.rb +1 -1
- data/lib/nokogiri/xml/xpath_context.rb +2 -0
- data/lib/nokogiri/xslt.rb +21 -1
- data/lib/nokogiri/xslt/stylesheet.rb +19 -0
- data/lib/xsd/xmlparser/nokogiri.rb +12 -2
- data/tasks/test.rb +42 -19
- data/test/css/test_parser.rb +29 -0
- data/test/ffi/test_document.rb +35 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/helper.rb +38 -8
- data/test/html/sax/test_parser.rb +12 -0
- data/test/html/test_builder.rb +25 -2
- data/test/html/test_document.rb +91 -20
- data/test/html/test_document_fragment.rb +97 -0
- data/test/html/test_element_description.rb +95 -0
- data/test/html/test_node.rb +66 -3
- data/test/test_convert_xpath.rb +1 -1
- data/test/test_memory_leak.rb +57 -18
- data/test/test_nokogiri.rb +24 -2
- data/test/test_reader.rb +77 -0
- data/test/test_xslt_transforms.rb +120 -82
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +9 -0
- data/test/xml/sax/test_push_parser.rb +24 -0
- data/test/xml/test_attr.rb +7 -0
- data/test/xml/test_builder.rb +48 -0
- data/test/xml/test_cdata.rb +19 -0
- data/test/xml/test_comment.rb +6 -0
- data/test/xml/test_document.rb +101 -2
- data/test/xml/test_document_fragment.rb +55 -3
- data/test/xml/test_entity_reference.rb +4 -0
- data/test/xml/test_namespace.rb +43 -0
- data/test/xml/test_node.rb +255 -8
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +9 -2
- data/test/xml/test_node_set.rb +197 -1
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +5 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +65 -0
- data/test/xml/test_text.rb +5 -0
- data/test/xml/test_unparented_node.rb +3 -3
- metadata +129 -13
- data/lib/nokogiri/xml/comment.rb +0 -6
- data/lib/nokogiri/xml/element.rb +0 -6
- data/lib/nokogiri/xml/text.rb +0 -6
@@ -1,4 +1,4 @@
|
|
1
|
-
#include <
|
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
|
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
|
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 ;
|
data/ext/nokogiri/xml_attr.c
CHANGED
@@ -42,14 +42,20 @@ static VALUE set_value(VALUE self, VALUE content)
|
|
42
42
|
|
43
43
|
/*
|
44
44
|
* call-seq:
|
45
|
-
* new(document,
|
45
|
+
* new(document, name)
|
46
46
|
*
|
47
47
|
* Create a new Attr element on the +document+ with +name+
|
48
48
|
*/
|
49
|
-
static VALUE new(
|
49
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
50
50
|
{
|
51
51
|
xmlDocPtr xml_doc;
|
52
|
-
|
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
|
-
|
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,
|
90
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
82
91
|
rb_define_method(klass, "value=", set_value, 1);
|
83
92
|
}
|
data/ext/nokogiri/xml_attr.h
CHANGED
data/ext/nokogiri/xml_cdata.c
CHANGED
@@ -6,18 +6,27 @@
|
|
6
6
|
*
|
7
7
|
* Create a new CData element on the +document+ with +content+
|
8
8
|
*/
|
9
|
-
static VALUE new(
|
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
|
-
|
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,
|
52
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
44
53
|
}
|
data/ext/nokogiri/xml_cdata.h
CHANGED
data/ext/nokogiri/xml_comment.c
CHANGED
@@ -6,17 +6,26 @@
|
|
6
6
|
*
|
7
7
|
* Create a new Comment element on the +document+ with +content+
|
8
8
|
*/
|
9
|
-
static VALUE new(
|
9
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
10
10
|
{
|
11
11
|
xmlDocPtr xml_doc;
|
12
|
-
|
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,
|
50
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
42
51
|
}
|
data/ext/nokogiri/xml_comment.h
CHANGED
data/ext/nokogiri/xml_document.c
CHANGED
@@ -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
|
-
|
11
|
-
|
12
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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);
|
data/ext/nokogiri/xml_document.h
CHANGED
@@ -6,16 +6,24 @@
|
|
6
6
|
*
|
7
7
|
* Create a new DocumentFragment element on the +document+
|
8
8
|
*/
|
9
|
-
static VALUE new(VALUE
|
9
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
10
10
|
{
|
11
11
|
xmlDocPtr xml_doc;
|
12
|
-
|
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
|
-
|
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
|
}
|