nokogiri 1.11.0.rc4-arm64-darwin
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.
- checksums.yaml +7 -0
- data/LICENSE-DEPENDENCIES.md +1682 -0
- data/LICENSE.md +9 -0
- data/README.md +200 -0
- data/bin/nokogiri +118 -0
- data/dependencies.yml +74 -0
- data/ext/nokogiri/depend +477 -0
- data/ext/nokogiri/extconf.rb +819 -0
- data/ext/nokogiri/html_document.c +171 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +279 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +32 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser_context.c +116 -0
- data/ext/nokogiri/html_sax_parser_context.h +11 -0
- data/ext/nokogiri/html_sax_push_parser.c +87 -0
- data/ext/nokogiri/html_sax_push_parser.h +9 -0
- data/ext/nokogiri/include/libexslt/exslt.h +102 -0
- data/ext/nokogiri/include/libexslt/exsltconfig.h +70 -0
- data/ext/nokogiri/include/libexslt/exsltexports.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/DOCBparser.h +96 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLparser.h +306 -0
- data/ext/nokogiri/include/libxml2/libxml/HTMLtree.h +147 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX.h +173 -0
- data/ext/nokogiri/include/libxml2/libxml/SAX2.h +178 -0
- data/ext/nokogiri/include/libxml2/libxml/c14n.h +126 -0
- data/ext/nokogiri/include/libxml2/libxml/catalog.h +182 -0
- data/ext/nokogiri/include/libxml2/libxml/chvalid.h +230 -0
- data/ext/nokogiri/include/libxml2/libxml/debugXML.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/dict.h +79 -0
- data/ext/nokogiri/include/libxml2/libxml/encoding.h +245 -0
- data/ext/nokogiri/include/libxml2/libxml/entities.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/globals.h +508 -0
- data/ext/nokogiri/include/libxml2/libxml/hash.h +236 -0
- data/ext/nokogiri/include/libxml2/libxml/list.h +137 -0
- data/ext/nokogiri/include/libxml2/libxml/nanoftp.h +163 -0
- data/ext/nokogiri/include/libxml2/libxml/nanohttp.h +81 -0
- data/ext/nokogiri/include/libxml2/libxml/parser.h +1241 -0
- data/ext/nokogiri/include/libxml2/libxml/parserInternals.h +644 -0
- data/ext/nokogiri/include/libxml2/libxml/pattern.h +100 -0
- data/ext/nokogiri/include/libxml2/libxml/relaxng.h +217 -0
- data/ext/nokogiri/include/libxml2/libxml/schemasInternals.h +958 -0
- data/ext/nokogiri/include/libxml2/libxml/schematron.h +142 -0
- data/ext/nokogiri/include/libxml2/libxml/threads.h +89 -0
- data/ext/nokogiri/include/libxml2/libxml/tree.h +1311 -0
- data/ext/nokogiri/include/libxml2/libxml/uri.h +94 -0
- data/ext/nokogiri/include/libxml2/libxml/valid.h +458 -0
- data/ext/nokogiri/include/libxml2/libxml/xinclude.h +129 -0
- data/ext/nokogiri/include/libxml2/libxml/xlink.h +189 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlIO.h +366 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlautomata.h +146 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlerror.h +945 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlexports.h +153 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmemory.h +224 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlmodule.h +57 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlreader.h +428 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlregexp.h +222 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlsave.h +88 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemas.h +246 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlschemastypes.h +151 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlstring.h +140 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlunicode.h +202 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlversion.h +485 -0
- data/ext/nokogiri/include/libxml2/libxml/xmlwriter.h +488 -0
- data/ext/nokogiri/include/libxml2/libxml/xpath.h +566 -0
- data/ext/nokogiri/include/libxml2/libxml/xpathInternals.h +632 -0
- data/ext/nokogiri/include/libxml2/libxml/xpointer.h +114 -0
- data/ext/nokogiri/include/libxslt/attributes.h +38 -0
- data/ext/nokogiri/include/libxslt/documents.h +93 -0
- data/ext/nokogiri/include/libxslt/extensions.h +262 -0
- data/ext/nokogiri/include/libxslt/extra.h +72 -0
- data/ext/nokogiri/include/libxslt/functions.h +78 -0
- data/ext/nokogiri/include/libxslt/imports.h +75 -0
- data/ext/nokogiri/include/libxslt/keys.h +53 -0
- data/ext/nokogiri/include/libxslt/namespaces.h +68 -0
- data/ext/nokogiri/include/libxslt/numbersInternals.h +73 -0
- data/ext/nokogiri/include/libxslt/pattern.h +84 -0
- data/ext/nokogiri/include/libxslt/preproc.h +43 -0
- data/ext/nokogiri/include/libxslt/security.h +104 -0
- data/ext/nokogiri/include/libxslt/templates.h +77 -0
- data/ext/nokogiri/include/libxslt/transform.h +207 -0
- data/ext/nokogiri/include/libxslt/variables.h +118 -0
- data/ext/nokogiri/include/libxslt/xslt.h +110 -0
- data/ext/nokogiri/include/libxslt/xsltInternals.h +1978 -0
- data/ext/nokogiri/include/libxslt/xsltconfig.h +180 -0
- data/ext/nokogiri/include/libxslt/xsltexports.h +142 -0
- data/ext/nokogiri/include/libxslt/xsltlocale.h +76 -0
- data/ext/nokogiri/include/libxslt/xsltutils.h +313 -0
- data/ext/nokogiri/nokogiri.c +135 -0
- data/ext/nokogiri/nokogiri.h +130 -0
- data/ext/nokogiri/xml_attr.c +103 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_attribute_decl.c +70 -0
- data/ext/nokogiri/xml_attribute_decl.h +9 -0
- data/ext/nokogiri/xml_cdata.c +62 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +69 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +622 -0
- data/ext/nokogiri/xml_document.h +23 -0
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +202 -0
- data/ext/nokogiri/xml_dtd.h +10 -0
- data/ext/nokogiri/xml_element_content.c +123 -0
- data/ext/nokogiri/xml_element_content.h +10 -0
- data/ext/nokogiri/xml_element_decl.c +69 -0
- data/ext/nokogiri/xml_element_decl.h +9 -0
- data/ext/nokogiri/xml_encoding_handler.c +79 -0
- data/ext/nokogiri/xml_encoding_handler.h +8 -0
- data/ext/nokogiri/xml_entity_decl.c +110 -0
- data/ext/nokogiri/xml_entity_decl.h +10 -0
- data/ext/nokogiri/xml_entity_reference.c +52 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +63 -0
- data/ext/nokogiri/xml_io.h +11 -0
- data/ext/nokogiri/xml_libxml2_hacks.c +112 -0
- data/ext/nokogiri/xml_libxml2_hacks.h +12 -0
- data/ext/nokogiri/xml_namespace.c +111 -0
- data/ext/nokogiri/xml_namespace.h +14 -0
- data/ext/nokogiri/xml_node.c +1773 -0
- data/ext/nokogiri/xml_node.h +13 -0
- data/ext/nokogiri/xml_node_set.c +486 -0
- data/ext/nokogiri/xml_node_set.h +12 -0
- data/ext/nokogiri/xml_processing_instruction.c +56 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +657 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +179 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +305 -0
- data/ext/nokogiri/xml_sax_parser.h +39 -0
- data/ext/nokogiri/xml_sax_parser_context.c +262 -0
- data/ext/nokogiri/xml_sax_parser_context.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +159 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +276 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +64 -0
- data/ext/nokogiri/xml_syntax_error.h +13 -0
- data/ext/nokogiri/xml_text.c +52 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath_context.c +374 -0
- data/ext/nokogiri/xml_xpath_context.h +10 -0
- data/ext/nokogiri/xslt_stylesheet.c +263 -0
- data/ext/nokogiri/xslt_stylesheet.h +14 -0
- data/lib/nokogiri.rb +127 -0
- data/lib/nokogiri/2.5/nokogiri.bundle +0 -0
- data/lib/nokogiri/2.6/nokogiri.bundle +0 -0
- data/lib/nokogiri/2.7/nokogiri.bundle +0 -0
- data/lib/nokogiri/3.0/nokogiri.bundle +0 -0
- data/lib/nokogiri/css.rb +28 -0
- data/lib/nokogiri/css/node.rb +53 -0
- data/lib/nokogiri/css/parser.rb +751 -0
- data/lib/nokogiri/css/parser.y +272 -0
- data/lib/nokogiri/css/parser_extras.rb +94 -0
- data/lib/nokogiri/css/syntax_error.rb +8 -0
- data/lib/nokogiri/css/tokenizer.rb +154 -0
- data/lib/nokogiri/css/tokenizer.rex +55 -0
- data/lib/nokogiri/css/xpath_visitor.rb +260 -0
- data/lib/nokogiri/decorators/slop.rb +43 -0
- data/lib/nokogiri/html.rb +38 -0
- data/lib/nokogiri/html/builder.rb +36 -0
- data/lib/nokogiri/html/document.rb +322 -0
- data/lib/nokogiri/html/document_fragment.rb +50 -0
- data/lib/nokogiri/html/element_description.rb +24 -0
- data/lib/nokogiri/html/element_description_defaults.rb +672 -0
- data/lib/nokogiri/html/entity_lookup.rb +14 -0
- data/lib/nokogiri/html/sax/parser.rb +63 -0
- data/lib/nokogiri/html/sax/parser_context.rb +17 -0
- data/lib/nokogiri/html/sax/push_parser.rb +37 -0
- data/lib/nokogiri/jruby/dependencies.rb +20 -0
- data/lib/nokogiri/syntax_error.rb +5 -0
- data/lib/nokogiri/version.rb +3 -0
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +182 -0
- data/lib/nokogiri/xml.rb +76 -0
- data/lib/nokogiri/xml/attr.rb +15 -0
- data/lib/nokogiri/xml/attribute_decl.rb +19 -0
- data/lib/nokogiri/xml/builder.rb +447 -0
- data/lib/nokogiri/xml/cdata.rb +12 -0
- data/lib/nokogiri/xml/character_data.rb +8 -0
- data/lib/nokogiri/xml/document.rb +290 -0
- data/lib/nokogiri/xml/document_fragment.rb +159 -0
- data/lib/nokogiri/xml/dtd.rb +33 -0
- data/lib/nokogiri/xml/element_content.rb +37 -0
- data/lib/nokogiri/xml/element_decl.rb +14 -0
- data/lib/nokogiri/xml/entity_decl.rb +20 -0
- data/lib/nokogiri/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/xml/namespace.rb +14 -0
- data/lib/nokogiri/xml/node.rb +1240 -0
- data/lib/nokogiri/xml/node/save_options.rb +62 -0
- data/lib/nokogiri/xml/node_set.rb +372 -0
- data/lib/nokogiri/xml/notation.rb +7 -0
- data/lib/nokogiri/xml/parse_options.rb +127 -0
- data/lib/nokogiri/xml/pp.rb +3 -0
- data/lib/nokogiri/xml/pp/character_data.rb +19 -0
- data/lib/nokogiri/xml/pp/node.rb +57 -0
- data/lib/nokogiri/xml/processing_instruction.rb +9 -0
- data/lib/nokogiri/xml/reader.rb +116 -0
- data/lib/nokogiri/xml/relax_ng.rb +37 -0
- data/lib/nokogiri/xml/sax.rb +5 -0
- data/lib/nokogiri/xml/sax/document.rb +172 -0
- data/lib/nokogiri/xml/sax/parser.rb +123 -0
- data/lib/nokogiri/xml/sax/parser_context.rb +17 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +61 -0
- data/lib/nokogiri/xml/schema.rb +72 -0
- data/lib/nokogiri/xml/searchable.rb +239 -0
- data/lib/nokogiri/xml/syntax_error.rb +71 -0
- data/lib/nokogiri/xml/text.rb +10 -0
- data/lib/nokogiri/xml/xpath.rb +11 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +12 -0
- data/lib/nokogiri/xml/xpath_context.rb +17 -0
- data/lib/nokogiri/xslt.rb +57 -0
- data/lib/nokogiri/xslt/stylesheet.rb +26 -0
- data/lib/xsd/xmlparser/nokogiri.rb +103 -0
- metadata +565 -0
@@ -0,0 +1,62 @@
|
|
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
|
+
* If +content+ cannot be implicitly converted to a string, this method will
|
10
|
+
* raise a TypeError exception.
|
11
|
+
*/
|
12
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
13
|
+
{
|
14
|
+
xmlDocPtr xml_doc;
|
15
|
+
xmlNodePtr node;
|
16
|
+
VALUE doc;
|
17
|
+
VALUE content;
|
18
|
+
VALUE rest;
|
19
|
+
VALUE rb_node;
|
20
|
+
xmlChar *content_str = NULL;
|
21
|
+
int content_str_len = 0;
|
22
|
+
|
23
|
+
rb_scan_args(argc, argv, "2*", &doc, &content, &rest);
|
24
|
+
|
25
|
+
Data_Get_Struct(doc, xmlDoc, xml_doc);
|
26
|
+
|
27
|
+
if (!NIL_P(content)) {
|
28
|
+
content_str = (xmlChar *)StringValuePtr(content);
|
29
|
+
content_str_len = RSTRING_LEN(content);
|
30
|
+
}
|
31
|
+
|
32
|
+
node = xmlNewCDataBlock(xml_doc->doc, content_str, content_str_len);
|
33
|
+
|
34
|
+
nokogiri_root_node(node);
|
35
|
+
|
36
|
+
rb_node = Nokogiri_wrap_xml_node(klass, node);
|
37
|
+
rb_obj_call_init(rb_node, argc, argv);
|
38
|
+
|
39
|
+
if(rb_block_given_p()) { rb_yield(rb_node); }
|
40
|
+
|
41
|
+
return rb_node;
|
42
|
+
}
|
43
|
+
|
44
|
+
VALUE cNokogiriXmlCData;
|
45
|
+
void init_xml_cdata()
|
46
|
+
{
|
47
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
48
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
49
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
50
|
+
VALUE char_data = rb_define_class_under(xml, "CharacterData", node);
|
51
|
+
VALUE text = rb_define_class_under(xml, "Text", char_data);
|
52
|
+
|
53
|
+
/*
|
54
|
+
* CData represents a CData node in an xml document.
|
55
|
+
*/
|
56
|
+
VALUE klass = rb_define_class_under(xml, "CDATA", text);
|
57
|
+
|
58
|
+
|
59
|
+
cNokogiriXmlCData = klass;
|
60
|
+
|
61
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
62
|
+
}
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#include <xml_comment.h>
|
2
|
+
|
3
|
+
static ID document_id ;
|
4
|
+
|
5
|
+
/*
|
6
|
+
* call-seq:
|
7
|
+
* new(document_or_node, content)
|
8
|
+
*
|
9
|
+
* Create a new Comment element on the +document+ with +content+.
|
10
|
+
* Alternatively, if a +node+ is passed, the +node+'s document is used.
|
11
|
+
*/
|
12
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
13
|
+
{
|
14
|
+
xmlDocPtr xml_doc;
|
15
|
+
xmlNodePtr node;
|
16
|
+
VALUE document;
|
17
|
+
VALUE content;
|
18
|
+
VALUE rest;
|
19
|
+
VALUE rb_node;
|
20
|
+
|
21
|
+
rb_scan_args(argc, argv, "2*", &document, &content, &rest);
|
22
|
+
|
23
|
+
if (rb_obj_is_kind_of(document, cNokogiriXmlNode))
|
24
|
+
{
|
25
|
+
document = rb_funcall(document, document_id, 0);
|
26
|
+
}
|
27
|
+
else if ( !rb_obj_is_kind_of(document, cNokogiriXmlDocument)
|
28
|
+
&& !rb_obj_is_kind_of(document, cNokogiriXmlDocumentFragment))
|
29
|
+
{
|
30
|
+
rb_raise(rb_eArgError, "first argument must be a XML::Document or XML::Node");
|
31
|
+
}
|
32
|
+
|
33
|
+
Data_Get_Struct(document, xmlDoc, xml_doc);
|
34
|
+
|
35
|
+
node = xmlNewDocComment(
|
36
|
+
xml_doc,
|
37
|
+
(const xmlChar *)StringValueCStr(content)
|
38
|
+
);
|
39
|
+
|
40
|
+
rb_node = Nokogiri_wrap_xml_node(klass, node);
|
41
|
+
rb_obj_call_init(rb_node, argc, argv);
|
42
|
+
|
43
|
+
nokogiri_root_node(node);
|
44
|
+
|
45
|
+
if(rb_block_given_p()) rb_yield(rb_node);
|
46
|
+
|
47
|
+
return rb_node;
|
48
|
+
}
|
49
|
+
|
50
|
+
VALUE cNokogiriXmlComment;
|
51
|
+
void init_xml_comment()
|
52
|
+
{
|
53
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
54
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
55
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
56
|
+
VALUE char_data = rb_define_class_under(xml, "CharacterData", node);
|
57
|
+
|
58
|
+
/*
|
59
|
+
* Comment represents a comment node in an xml document.
|
60
|
+
*/
|
61
|
+
VALUE klass = rb_define_class_under(xml, "Comment", char_data);
|
62
|
+
|
63
|
+
|
64
|
+
cNokogiriXmlComment = klass;
|
65
|
+
|
66
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
67
|
+
|
68
|
+
document_id = rb_intern("document");
|
69
|
+
}
|
@@ -0,0 +1,622 @@
|
|
1
|
+
#include <xml_document.h>
|
2
|
+
|
3
|
+
static int dealloc_node_i2(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
|
4
|
+
{
|
5
|
+
switch(node->type) {
|
6
|
+
case XML_ATTRIBUTE_NODE:
|
7
|
+
xmlFreePropList((xmlAttrPtr)node);
|
8
|
+
break;
|
9
|
+
case XML_NAMESPACE_DECL:
|
10
|
+
xmlFreeNs((xmlNsPtr)node);
|
11
|
+
break;
|
12
|
+
case XML_DTD_NODE:
|
13
|
+
xmlFreeDtd((xmlDtdPtr)node);
|
14
|
+
break;
|
15
|
+
default:
|
16
|
+
if(node->parent == NULL) {
|
17
|
+
xmlAddChild((xmlNodePtr)doc, node);
|
18
|
+
}
|
19
|
+
}
|
20
|
+
return ST_CONTINUE;
|
21
|
+
}
|
22
|
+
|
23
|
+
static int dealloc_node_i(st_data_t key, st_data_t node, st_data_t doc)
|
24
|
+
{
|
25
|
+
return dealloc_node_i2((xmlNodePtr)key, (xmlNodePtr)node, (xmlDocPtr)doc);
|
26
|
+
}
|
27
|
+
|
28
|
+
static void remove_private(xmlNodePtr node)
|
29
|
+
{
|
30
|
+
xmlNodePtr child;
|
31
|
+
|
32
|
+
for (child = node->children; child; child = child->next)
|
33
|
+
remove_private(child);
|
34
|
+
|
35
|
+
if ((node->type == XML_ELEMENT_NODE ||
|
36
|
+
node->type == XML_XINCLUDE_START ||
|
37
|
+
node->type == XML_XINCLUDE_END) &&
|
38
|
+
node->properties) {
|
39
|
+
for (child = (xmlNodePtr)node->properties; child; child = child->next)
|
40
|
+
remove_private(child);
|
41
|
+
}
|
42
|
+
|
43
|
+
node->_private = NULL;
|
44
|
+
}
|
45
|
+
|
46
|
+
static void mark(xmlDocPtr doc)
|
47
|
+
{
|
48
|
+
nokogiriTuplePtr tuple = (nokogiriTuplePtr)doc->_private;
|
49
|
+
if(tuple) {
|
50
|
+
rb_gc_mark(tuple->doc);
|
51
|
+
rb_gc_mark(tuple->node_cache);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
static void dealloc(xmlDocPtr doc)
|
56
|
+
{
|
57
|
+
st_table *node_hash;
|
58
|
+
|
59
|
+
NOKOGIRI_DEBUG_START(doc);
|
60
|
+
|
61
|
+
node_hash = DOC_UNLINKED_NODE_HASH(doc);
|
62
|
+
|
63
|
+
st_foreach(node_hash, dealloc_node_i, (st_data_t)doc);
|
64
|
+
st_free_table(node_hash);
|
65
|
+
|
66
|
+
free(doc->_private);
|
67
|
+
|
68
|
+
/* When both Nokogiri and libxml-ruby are loaded, make sure that all nodes
|
69
|
+
* have their _private pointers cleared. This is to avoid libxml-ruby's
|
70
|
+
* xmlDeregisterNode callback from accessing VALUE pointers from ruby's GC
|
71
|
+
* free context, which can result in segfaults.
|
72
|
+
*/
|
73
|
+
if (xmlDeregisterNodeDefaultValue)
|
74
|
+
remove_private((xmlNodePtr)doc);
|
75
|
+
|
76
|
+
xmlFreeDoc(doc);
|
77
|
+
|
78
|
+
NOKOGIRI_DEBUG_END(doc);
|
79
|
+
}
|
80
|
+
|
81
|
+
static void recursively_remove_namespaces_from_node(xmlNodePtr node)
|
82
|
+
{
|
83
|
+
xmlNodePtr child ;
|
84
|
+
xmlAttrPtr property ;
|
85
|
+
|
86
|
+
xmlSetNs(node, NULL);
|
87
|
+
|
88
|
+
for (child = node->children ; child ; child = child->next)
|
89
|
+
recursively_remove_namespaces_from_node(child);
|
90
|
+
|
91
|
+
if (((node->type == XML_ELEMENT_NODE) ||
|
92
|
+
(node->type == XML_XINCLUDE_START) ||
|
93
|
+
(node->type == XML_XINCLUDE_END)) &&
|
94
|
+
node->nsDef) {
|
95
|
+
xmlFreeNsList(node->nsDef);
|
96
|
+
node->nsDef = NULL;
|
97
|
+
}
|
98
|
+
|
99
|
+
if (node->type == XML_ELEMENT_NODE && node->properties != NULL) {
|
100
|
+
property = node->properties ;
|
101
|
+
while (property != NULL) {
|
102
|
+
if (property->ns) property->ns = NULL ;
|
103
|
+
property = property->next ;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
/*
|
109
|
+
* call-seq:
|
110
|
+
* url
|
111
|
+
*
|
112
|
+
* Get the url name for this document.
|
113
|
+
*/
|
114
|
+
static VALUE url(VALUE self)
|
115
|
+
{
|
116
|
+
xmlDocPtr doc;
|
117
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
118
|
+
|
119
|
+
if(doc->URL) return NOKOGIRI_STR_NEW2(doc->URL);
|
120
|
+
|
121
|
+
return Qnil;
|
122
|
+
}
|
123
|
+
|
124
|
+
/*
|
125
|
+
* call-seq:
|
126
|
+
* root=
|
127
|
+
*
|
128
|
+
* Set the root element on this document
|
129
|
+
*/
|
130
|
+
static VALUE set_root(VALUE self, VALUE root)
|
131
|
+
{
|
132
|
+
xmlDocPtr doc;
|
133
|
+
xmlNodePtr new_root;
|
134
|
+
xmlNodePtr old_root;
|
135
|
+
|
136
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
137
|
+
|
138
|
+
old_root = NULL;
|
139
|
+
|
140
|
+
if(NIL_P(root)) {
|
141
|
+
old_root = xmlDocGetRootElement(doc);
|
142
|
+
|
143
|
+
if(old_root) {
|
144
|
+
xmlUnlinkNode(old_root);
|
145
|
+
nokogiri_root_node(old_root);
|
146
|
+
}
|
147
|
+
|
148
|
+
return root;
|
149
|
+
}
|
150
|
+
|
151
|
+
Data_Get_Struct(root, xmlNode, new_root);
|
152
|
+
|
153
|
+
|
154
|
+
/* If the new root's document is not the same as the current document,
|
155
|
+
* then we need to dup the node in to this document. */
|
156
|
+
if(new_root->doc != doc) {
|
157
|
+
old_root = xmlDocGetRootElement(doc);
|
158
|
+
if (!(new_root = xmlDocCopyNode(new_root, doc, 1))) {
|
159
|
+
rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
|
160
|
+
}
|
161
|
+
}
|
162
|
+
|
163
|
+
xmlDocSetRootElement(doc, new_root);
|
164
|
+
if(old_root) nokogiri_root_node(old_root);
|
165
|
+
return root;
|
166
|
+
}
|
167
|
+
|
168
|
+
/*
|
169
|
+
* call-seq:
|
170
|
+
* root
|
171
|
+
*
|
172
|
+
* Get the root node for this document.
|
173
|
+
*/
|
174
|
+
static VALUE root(VALUE self)
|
175
|
+
{
|
176
|
+
xmlDocPtr doc;
|
177
|
+
xmlNodePtr root;
|
178
|
+
|
179
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
180
|
+
|
181
|
+
root = xmlDocGetRootElement(doc);
|
182
|
+
|
183
|
+
if(!root) return Qnil;
|
184
|
+
return Nokogiri_wrap_xml_node(Qnil, root) ;
|
185
|
+
}
|
186
|
+
|
187
|
+
/*
|
188
|
+
* call-seq:
|
189
|
+
* encoding= encoding
|
190
|
+
*
|
191
|
+
* Set the encoding string for this Document
|
192
|
+
*/
|
193
|
+
static VALUE set_encoding(VALUE self, VALUE encoding)
|
194
|
+
{
|
195
|
+
xmlDocPtr doc;
|
196
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
197
|
+
|
198
|
+
if (doc->encoding)
|
199
|
+
free((char *)(uintptr_t) doc->encoding); /* avoid gcc cast warning */
|
200
|
+
|
201
|
+
doc->encoding = xmlStrdup((xmlChar *)StringValueCStr(encoding));
|
202
|
+
|
203
|
+
return encoding;
|
204
|
+
}
|
205
|
+
|
206
|
+
/*
|
207
|
+
* call-seq:
|
208
|
+
* encoding
|
209
|
+
*
|
210
|
+
* Get the encoding for this Document
|
211
|
+
*/
|
212
|
+
static VALUE encoding(VALUE self)
|
213
|
+
{
|
214
|
+
xmlDocPtr doc;
|
215
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
216
|
+
|
217
|
+
if(!doc->encoding) return Qnil;
|
218
|
+
return NOKOGIRI_STR_NEW2(doc->encoding);
|
219
|
+
}
|
220
|
+
|
221
|
+
/*
|
222
|
+
* call-seq:
|
223
|
+
* version
|
224
|
+
*
|
225
|
+
* Get the XML version for this Document
|
226
|
+
*/
|
227
|
+
static VALUE version(VALUE self)
|
228
|
+
{
|
229
|
+
xmlDocPtr doc;
|
230
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
231
|
+
|
232
|
+
if(!doc->version) return Qnil;
|
233
|
+
return NOKOGIRI_STR_NEW2(doc->version);
|
234
|
+
}
|
235
|
+
|
236
|
+
/*
|
237
|
+
* call-seq:
|
238
|
+
* read_io(io, url, encoding, options)
|
239
|
+
*
|
240
|
+
* Create a new document from an IO object
|
241
|
+
*/
|
242
|
+
static VALUE read_io( VALUE klass,
|
243
|
+
VALUE io,
|
244
|
+
VALUE url,
|
245
|
+
VALUE encoding,
|
246
|
+
VALUE options )
|
247
|
+
{
|
248
|
+
const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
|
249
|
+
const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
|
250
|
+
VALUE error_list = rb_ary_new();
|
251
|
+
VALUE document;
|
252
|
+
xmlDocPtr doc;
|
253
|
+
|
254
|
+
xmlResetLastError();
|
255
|
+
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
256
|
+
|
257
|
+
doc = xmlReadIO(
|
258
|
+
(xmlInputReadCallback)io_read_callback,
|
259
|
+
(xmlInputCloseCallback)io_close_callback,
|
260
|
+
(void *)io,
|
261
|
+
c_url,
|
262
|
+
c_enc,
|
263
|
+
(int)NUM2INT(options)
|
264
|
+
);
|
265
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
266
|
+
|
267
|
+
if(doc == NULL) {
|
268
|
+
xmlErrorPtr error;
|
269
|
+
|
270
|
+
xmlFreeDoc(doc);
|
271
|
+
|
272
|
+
error = xmlGetLastError();
|
273
|
+
if(error)
|
274
|
+
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
275
|
+
else
|
276
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
277
|
+
|
278
|
+
return Qnil;
|
279
|
+
}
|
280
|
+
|
281
|
+
document = Nokogiri_wrap_xml_document(klass, doc);
|
282
|
+
rb_iv_set(document, "@errors", error_list);
|
283
|
+
return document;
|
284
|
+
}
|
285
|
+
|
286
|
+
/*
|
287
|
+
* call-seq:
|
288
|
+
* read_memory(string, url, encoding, options)
|
289
|
+
*
|
290
|
+
* Create a new document from a String
|
291
|
+
*/
|
292
|
+
static VALUE read_memory( VALUE klass,
|
293
|
+
VALUE string,
|
294
|
+
VALUE url,
|
295
|
+
VALUE encoding,
|
296
|
+
VALUE options )
|
297
|
+
{
|
298
|
+
const char * c_buffer = StringValuePtr(string);
|
299
|
+
const char * c_url = NIL_P(url) ? NULL : StringValueCStr(url);
|
300
|
+
const char * c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
|
301
|
+
int len = (int)RSTRING_LEN(string);
|
302
|
+
VALUE error_list = rb_ary_new();
|
303
|
+
VALUE document;
|
304
|
+
xmlDocPtr doc;
|
305
|
+
|
306
|
+
xmlResetLastError();
|
307
|
+
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
308
|
+
doc = xmlReadMemory(c_buffer, len, c_url, c_enc, (int)NUM2INT(options));
|
309
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
310
|
+
|
311
|
+
if(doc == NULL) {
|
312
|
+
xmlErrorPtr error;
|
313
|
+
|
314
|
+
xmlFreeDoc(doc);
|
315
|
+
|
316
|
+
error = xmlGetLastError();
|
317
|
+
if(error)
|
318
|
+
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
319
|
+
else
|
320
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
321
|
+
|
322
|
+
return Qnil;
|
323
|
+
}
|
324
|
+
|
325
|
+
document = Nokogiri_wrap_xml_document(klass, doc);
|
326
|
+
rb_iv_set(document, "@errors", error_list);
|
327
|
+
return document;
|
328
|
+
}
|
329
|
+
|
330
|
+
/*
|
331
|
+
* call-seq:
|
332
|
+
* dup
|
333
|
+
*
|
334
|
+
* Copy this Document. An optional depth may be passed in, but it defaults
|
335
|
+
* to a deep copy. 0 is a shallow copy, 1 is a deep copy.
|
336
|
+
*/
|
337
|
+
static VALUE duplicate_document(int argc, VALUE *argv, VALUE self)
|
338
|
+
{
|
339
|
+
xmlDocPtr doc, dup;
|
340
|
+
VALUE copy;
|
341
|
+
VALUE level;
|
342
|
+
VALUE error_list;
|
343
|
+
|
344
|
+
if(rb_scan_args(argc, argv, "01", &level) == 0)
|
345
|
+
level = INT2NUM((long)1);
|
346
|
+
|
347
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
348
|
+
|
349
|
+
dup = xmlCopyDoc(doc, (int)NUM2INT(level));
|
350
|
+
|
351
|
+
if(dup == NULL) return Qnil;
|
352
|
+
|
353
|
+
dup->type = doc->type;
|
354
|
+
copy = Nokogiri_wrap_xml_document(rb_obj_class(self), dup);
|
355
|
+
error_list = rb_iv_get(self, "@errors");
|
356
|
+
rb_iv_set(copy, "@errors", error_list);
|
357
|
+
return copy ;
|
358
|
+
}
|
359
|
+
|
360
|
+
/*
|
361
|
+
* call-seq:
|
362
|
+
* new(version = default)
|
363
|
+
*
|
364
|
+
* Create a new document with +version+ (defaults to "1.0")
|
365
|
+
*/
|
366
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
367
|
+
{
|
368
|
+
xmlDocPtr doc;
|
369
|
+
VALUE version, rest, rb_doc ;
|
370
|
+
|
371
|
+
rb_scan_args(argc, argv, "0*", &rest);
|
372
|
+
version = rb_ary_entry(rest, (long)0);
|
373
|
+
if (NIL_P(version)) version = rb_str_new2("1.0");
|
374
|
+
|
375
|
+
doc = xmlNewDoc((xmlChar *)StringValueCStr(version));
|
376
|
+
rb_doc = Nokogiri_wrap_xml_document(klass, doc);
|
377
|
+
rb_obj_call_init(rb_doc, argc, argv);
|
378
|
+
return rb_doc ;
|
379
|
+
}
|
380
|
+
|
381
|
+
/*
|
382
|
+
* call-seq:
|
383
|
+
* remove_namespaces!
|
384
|
+
*
|
385
|
+
* Remove all namespaces from all nodes in the document.
|
386
|
+
*
|
387
|
+
* This could be useful for developers who either don't understand namespaces
|
388
|
+
* or don't care about them.
|
389
|
+
*
|
390
|
+
* The following example shows a use case, and you can decide for yourself
|
391
|
+
* whether this is a good thing or not:
|
392
|
+
*
|
393
|
+
* doc = Nokogiri::XML <<-EOXML
|
394
|
+
* <root>
|
395
|
+
* <car xmlns:part="http://general-motors.com/">
|
396
|
+
* <part:tire>Michelin Model XGV</part:tire>
|
397
|
+
* </car>
|
398
|
+
* <bicycle xmlns:part="http://schwinn.com/">
|
399
|
+
* <part:tire>I'm a bicycle tire!</part:tire>
|
400
|
+
* </bicycle>
|
401
|
+
* </root>
|
402
|
+
* EOXML
|
403
|
+
*
|
404
|
+
* doc.xpath("//tire").to_s # => ""
|
405
|
+
* doc.xpath("//part:tire", "part" => "http://general-motors.com/").to_s # => "<part:tire>Michelin Model XGV</part:tire>"
|
406
|
+
* doc.xpath("//part:tire", "part" => "http://schwinn.com/").to_s # => "<part:tire>I'm a bicycle tire!</part:tire>"
|
407
|
+
*
|
408
|
+
* doc.remove_namespaces!
|
409
|
+
*
|
410
|
+
* doc.xpath("//tire").to_s # => "<tire>Michelin Model XGV</tire><tire>I'm a bicycle tire!</tire>"
|
411
|
+
* doc.xpath("//part:tire", "part" => "http://general-motors.com/").to_s # => ""
|
412
|
+
* doc.xpath("//part:tire", "part" => "http://schwinn.com/").to_s # => ""
|
413
|
+
*
|
414
|
+
* For more information on why this probably is *not* a good thing in general,
|
415
|
+
* please direct your browser to
|
416
|
+
* http://tenderlovemaking.com/2009/04/23/namespaces-in-xml.html
|
417
|
+
*/
|
418
|
+
VALUE remove_namespaces_bang(VALUE self)
|
419
|
+
{
|
420
|
+
xmlDocPtr doc ;
|
421
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
422
|
+
|
423
|
+
recursively_remove_namespaces_from_node((xmlNodePtr)doc);
|
424
|
+
return self;
|
425
|
+
}
|
426
|
+
|
427
|
+
/* call-seq: doc.create_entity(name, type, external_id, system_id, content)
|
428
|
+
*
|
429
|
+
* Create a new entity named +name+.
|
430
|
+
*
|
431
|
+
* +type+ is an integer representing the type of entity to be created, and it
|
432
|
+
* defaults to Nokogiri::XML::EntityDecl::INTERNAL_GENERAL. See
|
433
|
+
* the constants on Nokogiri::XML::EntityDecl for more information.
|
434
|
+
*
|
435
|
+
* +external_id+, +system_id+, and +content+ set the External ID, System ID,
|
436
|
+
* and content respectively. All of these parameters are optional.
|
437
|
+
*/
|
438
|
+
static VALUE create_entity(int argc, VALUE *argv, VALUE self)
|
439
|
+
{
|
440
|
+
VALUE name;
|
441
|
+
VALUE type;
|
442
|
+
VALUE external_id;
|
443
|
+
VALUE system_id;
|
444
|
+
VALUE content;
|
445
|
+
xmlEntityPtr ptr;
|
446
|
+
xmlDocPtr doc ;
|
447
|
+
|
448
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
449
|
+
|
450
|
+
rb_scan_args(argc, argv, "14", &name, &type, &external_id, &system_id,
|
451
|
+
&content);
|
452
|
+
|
453
|
+
xmlResetLastError();
|
454
|
+
ptr = xmlAddDocEntity(
|
455
|
+
doc,
|
456
|
+
(xmlChar *)(NIL_P(name) ? NULL : StringValueCStr(name)),
|
457
|
+
(int) (NIL_P(type) ? XML_INTERNAL_GENERAL_ENTITY : NUM2INT(type)),
|
458
|
+
(xmlChar *)(NIL_P(external_id) ? NULL : StringValueCStr(external_id)),
|
459
|
+
(xmlChar *)(NIL_P(system_id) ? NULL : StringValueCStr(system_id)),
|
460
|
+
(xmlChar *)(NIL_P(content) ? NULL : StringValueCStr(content))
|
461
|
+
);
|
462
|
+
|
463
|
+
if(NULL == ptr) {
|
464
|
+
xmlErrorPtr error = xmlGetLastError();
|
465
|
+
if(error)
|
466
|
+
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
467
|
+
else
|
468
|
+
rb_raise(rb_eRuntimeError, "Could not create entity");
|
469
|
+
|
470
|
+
return Qnil;
|
471
|
+
}
|
472
|
+
|
473
|
+
return Nokogiri_wrap_xml_node(cNokogiriXmlEntityDecl, (xmlNodePtr)ptr);
|
474
|
+
}
|
475
|
+
|
476
|
+
static int block_caller(void * ctx, xmlNodePtr _node, xmlNodePtr _parent)
|
477
|
+
{
|
478
|
+
VALUE block;
|
479
|
+
VALUE node;
|
480
|
+
VALUE parent;
|
481
|
+
VALUE ret;
|
482
|
+
|
483
|
+
if(_node->type == XML_NAMESPACE_DECL){
|
484
|
+
node = Nokogiri_wrap_xml_namespace(_parent->doc, (xmlNsPtr) _node);
|
485
|
+
}
|
486
|
+
else{
|
487
|
+
node = Nokogiri_wrap_xml_node(Qnil, _node);
|
488
|
+
}
|
489
|
+
parent = _parent ? Nokogiri_wrap_xml_node(Qnil, _parent) : Qnil;
|
490
|
+
block = (VALUE)ctx;
|
491
|
+
|
492
|
+
ret = rb_funcall(block, rb_intern("call"), 2, node, parent);
|
493
|
+
|
494
|
+
if(Qfalse == ret || Qnil == ret) return 0;
|
495
|
+
|
496
|
+
return 1;
|
497
|
+
}
|
498
|
+
|
499
|
+
/* call-seq:
|
500
|
+
* doc.canonicalize(mode=XML_C14N_1_0,inclusive_namespaces=nil,with_comments=false)
|
501
|
+
* doc.canonicalize { |obj, parent| ... }
|
502
|
+
*
|
503
|
+
* Canonicalize a document and return the results. Takes an optional block
|
504
|
+
* that takes two parameters: the +obj+ and that node's +parent+.
|
505
|
+
* The +obj+ will be either a Nokogiri::XML::Node, or a Nokogiri::XML::Namespace
|
506
|
+
* The block must return a non-nil, non-false value if the +obj+ passed in
|
507
|
+
* should be included in the canonicalized document.
|
508
|
+
*/
|
509
|
+
static VALUE nokogiri_xml_document_canonicalize(int argc, VALUE* argv, VALUE self)
|
510
|
+
{
|
511
|
+
VALUE mode;
|
512
|
+
VALUE incl_ns;
|
513
|
+
VALUE with_comments;
|
514
|
+
xmlChar **ns;
|
515
|
+
long ns_len, i;
|
516
|
+
|
517
|
+
xmlDocPtr doc;
|
518
|
+
xmlOutputBufferPtr buf;
|
519
|
+
xmlC14NIsVisibleCallback cb = NULL;
|
520
|
+
void * ctx = NULL;
|
521
|
+
|
522
|
+
VALUE rb_cStringIO;
|
523
|
+
VALUE io;
|
524
|
+
|
525
|
+
rb_scan_args(argc, argv, "03", &mode, &incl_ns, &with_comments);
|
526
|
+
|
527
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
528
|
+
|
529
|
+
rb_cStringIO = rb_const_get_at(rb_cObject, rb_intern("StringIO"));
|
530
|
+
io = rb_class_new_instance(0, 0, rb_cStringIO);
|
531
|
+
buf = xmlAllocOutputBuffer(NULL);
|
532
|
+
|
533
|
+
buf->writecallback = (xmlOutputWriteCallback)io_write_callback;
|
534
|
+
buf->closecallback = (xmlOutputCloseCallback)io_close_callback;
|
535
|
+
buf->context = (void *)io;
|
536
|
+
|
537
|
+
if(rb_block_given_p()) {
|
538
|
+
cb = block_caller;
|
539
|
+
ctx = (void *)rb_block_proc();
|
540
|
+
}
|
541
|
+
|
542
|
+
if(NIL_P(incl_ns)){
|
543
|
+
ns = NULL;
|
544
|
+
}
|
545
|
+
else{
|
546
|
+
Check_Type(incl_ns, T_ARRAY);
|
547
|
+
ns_len = RARRAY_LEN(incl_ns);
|
548
|
+
ns = calloc((size_t)ns_len+1, sizeof(xmlChar *));
|
549
|
+
for (i = 0 ; i < ns_len ; i++) {
|
550
|
+
VALUE entry = rb_ary_entry(incl_ns, i);
|
551
|
+
ns[i] = (xmlChar*)StringValueCStr(entry);
|
552
|
+
}
|
553
|
+
}
|
554
|
+
|
555
|
+
|
556
|
+
xmlC14NExecute(doc, cb, ctx,
|
557
|
+
(int) (NIL_P(mode) ? 0 : NUM2INT(mode)),
|
558
|
+
ns,
|
559
|
+
(int) RTEST(with_comments),
|
560
|
+
buf);
|
561
|
+
|
562
|
+
xmlOutputBufferClose(buf);
|
563
|
+
|
564
|
+
return rb_funcall(io, rb_intern("string"), 0);
|
565
|
+
}
|
566
|
+
|
567
|
+
VALUE cNokogiriXmlDocument ;
|
568
|
+
void init_xml_document()
|
569
|
+
{
|
570
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
571
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
572
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
573
|
+
|
574
|
+
/*
|
575
|
+
* Nokogiri::XML::Document wraps an xml document.
|
576
|
+
*/
|
577
|
+
VALUE klass = rb_define_class_under(xml, "Document", node);
|
578
|
+
|
579
|
+
cNokogiriXmlDocument = klass;
|
580
|
+
|
581
|
+
rb_define_singleton_method(klass, "read_memory", read_memory, 4);
|
582
|
+
rb_define_singleton_method(klass, "read_io", read_io, 4);
|
583
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
584
|
+
|
585
|
+
rb_define_method(klass, "root", root, 0);
|
586
|
+
rb_define_method(klass, "root=", set_root, 1);
|
587
|
+
rb_define_method(klass, "encoding", encoding, 0);
|
588
|
+
rb_define_method(klass, "encoding=", set_encoding, 1);
|
589
|
+
rb_define_method(klass, "version", version, 0);
|
590
|
+
rb_define_method(klass, "canonicalize", nokogiri_xml_document_canonicalize, -1);
|
591
|
+
rb_define_method(klass, "dup", duplicate_document, -1);
|
592
|
+
rb_define_method(klass, "url", url, 0);
|
593
|
+
rb_define_method(klass, "create_entity", create_entity, -1);
|
594
|
+
rb_define_method(klass, "remove_namespaces!", remove_namespaces_bang, 0);
|
595
|
+
}
|
596
|
+
|
597
|
+
|
598
|
+
/* this takes klass as a param because it's used for HtmlDocument, too. */
|
599
|
+
VALUE Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc)
|
600
|
+
{
|
601
|
+
nokogiriTuplePtr tuple = (nokogiriTuplePtr)malloc(sizeof(nokogiriTuple));
|
602
|
+
|
603
|
+
VALUE rb_doc = Data_Wrap_Struct(
|
604
|
+
klass ? klass : cNokogiriXmlDocument,
|
605
|
+
mark,
|
606
|
+
dealloc,
|
607
|
+
doc
|
608
|
+
);
|
609
|
+
|
610
|
+
VALUE cache = rb_ary_new();
|
611
|
+
rb_iv_set(rb_doc, "@decorators", Qnil);
|
612
|
+
rb_iv_set(rb_doc, "@node_cache", cache);
|
613
|
+
|
614
|
+
tuple->doc = rb_doc;
|
615
|
+
tuple->unlinkedNodes = st_init_numtable_with_size(128);
|
616
|
+
tuple->node_cache = cache;
|
617
|
+
doc->_private = tuple ;
|
618
|
+
|
619
|
+
rb_obj_call_init(rb_doc, 0, NULL);
|
620
|
+
|
621
|
+
return rb_doc ;
|
622
|
+
}
|