nokogiri 1.11.1-x86-mingw32 → 1.11.2-x86-mingw32
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 +4 -4
- data/LICENSE-DEPENDENCIES.md +12 -12
- data/LICENSE.md +1 -1
- data/README.md +20 -15
- data/ext/nokogiri/depend +34 -474
- data/ext/nokogiri/extconf.rb +253 -183
- data/ext/nokogiri/html_document.c +10 -15
- data/ext/nokogiri/html_element_description.c +84 -71
- data/ext/nokogiri/html_entity_lookup.c +21 -16
- data/ext/nokogiri/html_sax_parser_context.c +66 -65
- data/ext/nokogiri/html_sax_push_parser.c +29 -27
- data/ext/nokogiri/include/libxslt/xsltconfig.h +1 -1
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +171 -63
- data/ext/nokogiri/nokogiri.h +158 -75
- data/ext/nokogiri/test_global_handlers.c +3 -4
- data/ext/nokogiri/xml_attr.c +15 -15
- data/ext/nokogiri/xml_attribute_decl.c +18 -18
- data/ext/nokogiri/xml_cdata.c +13 -18
- data/ext/nokogiri/xml_comment.c +19 -26
- data/ext/nokogiri/xml_document.c +221 -164
- data/ext/nokogiri/xml_document_fragment.c +13 -15
- data/ext/nokogiri/xml_dtd.c +54 -48
- data/ext/nokogiri/xml_element_content.c +30 -27
- data/ext/nokogiri/xml_element_decl.c +22 -22
- data/ext/nokogiri/xml_encoding_handler.c +17 -11
- data/ext/nokogiri/xml_entity_decl.c +32 -30
- data/ext/nokogiri/xml_entity_reference.c +16 -18
- data/ext/nokogiri/xml_namespace.c +56 -49
- data/ext/nokogiri/xml_node.c +338 -286
- data/ext/nokogiri/xml_node_set.c +168 -156
- data/ext/nokogiri/xml_processing_instruction.c +17 -19
- data/ext/nokogiri/xml_reader.c +191 -157
- data/ext/nokogiri/xml_relax_ng.c +29 -23
- data/ext/nokogiri/xml_sax_parser.c +117 -112
- data/ext/nokogiri/xml_sax_parser_context.c +100 -85
- data/ext/nokogiri/xml_sax_push_parser.c +34 -27
- data/ext/nokogiri/xml_schema.c +48 -42
- data/ext/nokogiri/xml_syntax_error.c +21 -23
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +134 -127
- data/ext/nokogiri/xslt_stylesheet.c +157 -157
- data/lib/nokogiri.rb +1 -22
- data/lib/nokogiri/2.5/nokogiri.so +0 -0
- data/lib/nokogiri/2.6/nokogiri.so +0 -0
- data/lib/nokogiri/2.7/nokogiri.so +0 -0
- data/lib/nokogiri/3.0/nokogiri.so +0 -0
- data/lib/nokogiri/css/parser.rb +1 -1
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/document_fragment.rb +15 -15
- data/lib/nokogiri/version/constant.rb +1 -1
- data/lib/nokogiri/version/info.rb +31 -8
- data/lib/nokogiri/xml/document.rb +31 -11
- data/lib/nokogiri/xml/node.rb +38 -42
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/xpath.rb +1 -3
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- metadata +7 -41
- data/ext/nokogiri/html_document.h +0 -10
- data/ext/nokogiri/html_element_description.h +0 -10
- data/ext/nokogiri/html_entity_lookup.h +0 -8
- data/ext/nokogiri/html_sax_parser_context.h +0 -11
- data/ext/nokogiri/html_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_attr.h +0 -9
- data/ext/nokogiri/xml_attribute_decl.h +0 -9
- data/ext/nokogiri/xml_cdata.h +0 -9
- data/ext/nokogiri/xml_comment.h +0 -9
- data/ext/nokogiri/xml_document.h +0 -23
- data/ext/nokogiri/xml_document_fragment.h +0 -10
- data/ext/nokogiri/xml_dtd.h +0 -10
- data/ext/nokogiri/xml_element_content.h +0 -10
- data/ext/nokogiri/xml_element_decl.h +0 -9
- data/ext/nokogiri/xml_encoding_handler.h +0 -8
- data/ext/nokogiri/xml_entity_decl.h +0 -10
- data/ext/nokogiri/xml_entity_reference.h +0 -9
- data/ext/nokogiri/xml_io.c +0 -63
- data/ext/nokogiri/xml_io.h +0 -11
- data/ext/nokogiri/xml_libxml2_hacks.c +0 -112
- data/ext/nokogiri/xml_libxml2_hacks.h +0 -12
- data/ext/nokogiri/xml_namespace.h +0 -14
- data/ext/nokogiri/xml_node.h +0 -13
- data/ext/nokogiri/xml_node_set.h +0 -12
- data/ext/nokogiri/xml_processing_instruction.h +0 -9
- data/ext/nokogiri/xml_reader.h +0 -10
- data/ext/nokogiri/xml_relax_ng.h +0 -9
- data/ext/nokogiri/xml_sax_parser.h +0 -39
- data/ext/nokogiri/xml_sax_parser_context.h +0 -10
- data/ext/nokogiri/xml_sax_push_parser.h +0 -9
- data/ext/nokogiri/xml_schema.h +0 -9
- data/ext/nokogiri/xml_syntax_error.h +0 -25
- data/ext/nokogiri/xml_text.h +0 -9
- data/ext/nokogiri/xml_xpath_context.h +0 -10
- data/ext/nokogiri/xslt_stylesheet.h +0 -14
@@ -1,17 +1,19 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
2
|
|
3
3
|
/*
|
4
4
|
* call-seq: Nokogiri::EncodingHandler.[](name)
|
5
5
|
*
|
6
6
|
* Get the encoding handler for +name+
|
7
7
|
*/
|
8
|
-
static VALUE
|
8
|
+
static VALUE
|
9
|
+
get(VALUE klass, VALUE key)
|
9
10
|
{
|
10
11
|
xmlCharEncodingHandlerPtr handler;
|
11
12
|
|
12
13
|
handler = xmlFindCharEncodingHandler(StringValueCStr(key));
|
13
|
-
if(handler)
|
14
|
+
if (handler) {
|
14
15
|
return Data_Wrap_Struct(klass, NULL, NULL, handler);
|
16
|
+
}
|
15
17
|
|
16
18
|
return Qnil;
|
17
19
|
}
|
@@ -21,9 +23,10 @@ static VALUE get(VALUE klass, VALUE key)
|
|
21
23
|
*
|
22
24
|
* Delete the encoding alias named +name+
|
23
25
|
*/
|
24
|
-
static VALUE
|
26
|
+
static VALUE
|
27
|
+
delete (VALUE klass, VALUE name)
|
25
28
|
{
|
26
|
-
if(xmlDelEncodingAlias(StringValueCStr(name))) return Qnil;
|
29
|
+
if (xmlDelEncodingAlias(StringValueCStr(name))) { return Qnil; }
|
27
30
|
|
28
31
|
return Qtrue;
|
29
32
|
}
|
@@ -33,7 +36,8 @@ static VALUE delete(VALUE klass, VALUE name)
|
|
33
36
|
*
|
34
37
|
* Alias encoding handler with name +from+ to name +to+
|
35
38
|
*/
|
36
|
-
static VALUE
|
39
|
+
static VALUE
|
40
|
+
alias(VALUE klass, VALUE from, VALUE to)
|
37
41
|
{
|
38
42
|
xmlAddEncodingAlias(StringValueCStr(from), StringValueCStr(to));
|
39
43
|
|
@@ -45,7 +49,8 @@ static VALUE alias(VALUE klass, VALUE from, VALUE to)
|
|
45
49
|
*
|
46
50
|
* Remove all encoding aliases.
|
47
51
|
*/
|
48
|
-
static VALUE
|
52
|
+
static VALUE
|
53
|
+
clear_aliases(VALUE klass)
|
49
54
|
{
|
50
55
|
xmlCleanupEncodingAliases();
|
51
56
|
|
@@ -57,7 +62,8 @@ static VALUE clear_aliases(VALUE klass)
|
|
57
62
|
*
|
58
63
|
* Get the name of this EncodingHandler
|
59
64
|
*/
|
60
|
-
static VALUE
|
65
|
+
static VALUE
|
66
|
+
name(VALUE self)
|
61
67
|
{
|
62
68
|
xmlCharEncodingHandlerPtr handler;
|
63
69
|
|
@@ -66,10 +72,10 @@ static VALUE name(VALUE self)
|
|
66
72
|
return NOKOGIRI_STR_NEW2(handler->name);
|
67
73
|
}
|
68
74
|
|
69
|
-
void
|
75
|
+
void
|
76
|
+
noko_init_xml_encoding_handler()
|
70
77
|
{
|
71
|
-
VALUE
|
72
|
-
VALUE klass = rb_define_class_under(nokogiri, "EncodingHandler", rb_cObject);
|
78
|
+
VALUE klass = rb_define_class_under(mNokogiri, "EncodingHandler", rb_cObject);
|
73
79
|
|
74
80
|
rb_define_singleton_method(klass, "[]", get, 1);
|
75
81
|
rb_define_singleton_method(klass, "delete", delete, 1);
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlEntityDecl;
|
2
4
|
|
3
5
|
/*
|
4
6
|
* call-seq:
|
@@ -6,12 +8,13 @@
|
|
6
8
|
*
|
7
9
|
* Get the original_content before ref substitution
|
8
10
|
*/
|
9
|
-
static VALUE
|
11
|
+
static VALUE
|
12
|
+
original_content(VALUE self)
|
10
13
|
{
|
11
14
|
xmlEntityPtr node;
|
12
15
|
Data_Get_Struct(self, xmlEntity, node);
|
13
16
|
|
14
|
-
if(!node->orig) return Qnil;
|
17
|
+
if (!node->orig) { return Qnil; }
|
15
18
|
|
16
19
|
return NOKOGIRI_STR_NEW2(node->orig);
|
17
20
|
}
|
@@ -22,12 +25,13 @@ static VALUE original_content(VALUE self)
|
|
22
25
|
*
|
23
26
|
* Get the content
|
24
27
|
*/
|
25
|
-
static VALUE
|
28
|
+
static VALUE
|
29
|
+
get_content(VALUE self)
|
26
30
|
{
|
27
31
|
xmlEntityPtr node;
|
28
32
|
Data_Get_Struct(self, xmlEntity, node);
|
29
33
|
|
30
|
-
if(!node->content) return Qnil;
|
34
|
+
if (!node->content) { return Qnil; }
|
31
35
|
|
32
36
|
return NOKOGIRI_STR_NEW(node->content, node->length);
|
33
37
|
}
|
@@ -38,7 +42,8 @@ static VALUE get_content(VALUE self)
|
|
38
42
|
*
|
39
43
|
* Get the entity type
|
40
44
|
*/
|
41
|
-
static VALUE
|
45
|
+
static VALUE
|
46
|
+
entity_type(VALUE self)
|
42
47
|
{
|
43
48
|
xmlEntityPtr node;
|
44
49
|
Data_Get_Struct(self, xmlEntity, node);
|
@@ -52,12 +57,13 @@ static VALUE entity_type(VALUE self)
|
|
52
57
|
*
|
53
58
|
* Get the external identifier for PUBLIC
|
54
59
|
*/
|
55
|
-
static VALUE
|
60
|
+
static VALUE
|
61
|
+
external_id(VALUE self)
|
56
62
|
{
|
57
63
|
xmlEntityPtr node;
|
58
64
|
Data_Get_Struct(self, xmlEntity, node);
|
59
65
|
|
60
|
-
if(!node->ExternalID) return Qnil;
|
66
|
+
if (!node->ExternalID) { return Qnil; }
|
61
67
|
|
62
68
|
return NOKOGIRI_STR_NEW2(node->ExternalID);
|
63
69
|
}
|
@@ -68,43 +74,39 @@ static VALUE external_id(VALUE self)
|
|
68
74
|
*
|
69
75
|
* Get the URI for a SYSTEM or PUBLIC Entity
|
70
76
|
*/
|
71
|
-
static VALUE
|
77
|
+
static VALUE
|
78
|
+
system_id(VALUE self)
|
72
79
|
{
|
73
80
|
xmlEntityPtr node;
|
74
81
|
Data_Get_Struct(self, xmlEntity, node);
|
75
82
|
|
76
|
-
if(!node->SystemID) return Qnil;
|
83
|
+
if (!node->SystemID) { return Qnil; }
|
77
84
|
|
78
85
|
return NOKOGIRI_STR_NEW2(node->SystemID);
|
79
86
|
}
|
80
87
|
|
81
|
-
|
82
|
-
|
83
|
-
void init_xml_entity_decl()
|
88
|
+
void
|
89
|
+
noko_init_xml_entity_decl()
|
84
90
|
{
|
85
|
-
|
86
|
-
|
87
|
-
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
88
|
-
VALUE klass = rb_define_class_under(xml, "EntityDecl", node);
|
89
|
-
|
90
|
-
cNokogiriXmlEntityDecl = klass;
|
91
|
+
assert(cNokogiriXmlNode);
|
92
|
+
cNokogiriXmlEntityDecl = rb_define_class_under(mNokogiriXml, "EntityDecl", cNokogiriXmlNode);
|
91
93
|
|
92
|
-
rb_define_method(
|
93
|
-
rb_define_method(
|
94
|
-
rb_define_method(
|
95
|
-
rb_define_method(
|
96
|
-
rb_define_method(
|
94
|
+
rb_define_method(cNokogiriXmlEntityDecl, "original_content", original_content, 0);
|
95
|
+
rb_define_method(cNokogiriXmlEntityDecl, "content", get_content, 0);
|
96
|
+
rb_define_method(cNokogiriXmlEntityDecl, "entity_type", entity_type, 0);
|
97
|
+
rb_define_method(cNokogiriXmlEntityDecl, "external_id", external_id, 0);
|
98
|
+
rb_define_method(cNokogiriXmlEntityDecl, "system_id", system_id, 0);
|
97
99
|
|
98
100
|
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("INTERNAL_GENERAL"),
|
99
|
-
|
101
|
+
INT2NUM(XML_INTERNAL_GENERAL_ENTITY));
|
100
102
|
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("EXTERNAL_GENERAL_PARSED"),
|
101
|
-
|
103
|
+
INT2NUM(XML_EXTERNAL_GENERAL_PARSED_ENTITY));
|
102
104
|
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("EXTERNAL_GENERAL_UNPARSED"),
|
103
|
-
|
105
|
+
INT2NUM(XML_EXTERNAL_GENERAL_UNPARSED_ENTITY));
|
104
106
|
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("INTERNAL_PARAMETER"),
|
105
|
-
|
107
|
+
INT2NUM(XML_INTERNAL_PARAMETER_ENTITY));
|
106
108
|
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("EXTERNAL_PARAMETER"),
|
107
|
-
|
109
|
+
INT2NUM(XML_EXTERNAL_PARAMETER_ENTITY));
|
108
110
|
rb_const_set(cNokogiriXmlEntityDecl, rb_intern("INTERNAL_PREDEFINED"),
|
109
|
-
|
111
|
+
INT2NUM(XML_INTERNAL_PREDEFINED_ENTITY));
|
110
112
|
}
|
@@ -1,4 +1,6 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlEntityReference;
|
2
4
|
|
3
5
|
/*
|
4
6
|
* call-seq:
|
@@ -6,7 +8,8 @@
|
|
6
8
|
*
|
7
9
|
* Create a new EntityReference element on the +document+ with +name+
|
8
10
|
*/
|
9
|
-
static VALUE
|
11
|
+
static VALUE
|
12
|
+
new (int argc, VALUE *argv, VALUE klass)
|
10
13
|
{
|
11
14
|
xmlDocPtr xml_doc;
|
12
15
|
xmlNodePtr node;
|
@@ -20,33 +23,28 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
|
|
20
23
|
Data_Get_Struct(document, xmlDoc, xml_doc);
|
21
24
|
|
22
25
|
node = xmlNewReference(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
xml_doc,
|
27
|
+
(const xmlChar *)StringValueCStr(name)
|
28
|
+
);
|
26
29
|
|
27
|
-
|
30
|
+
noko_xml_document_pin_node(node);
|
28
31
|
|
29
|
-
rb_node =
|
32
|
+
rb_node = noko_xml_node_wrap(klass, node);
|
30
33
|
rb_obj_call_init(rb_node, argc, argv);
|
31
34
|
|
32
|
-
if(rb_block_given_p()) rb_yield(rb_node);
|
35
|
+
if (rb_block_given_p()) { rb_yield(rb_node); }
|
33
36
|
|
34
37
|
return rb_node;
|
35
38
|
}
|
36
39
|
|
37
|
-
|
38
|
-
|
40
|
+
void
|
41
|
+
noko_init_xml_entity_reference()
|
39
42
|
{
|
40
|
-
|
41
|
-
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
42
|
-
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
43
|
-
|
43
|
+
assert(cNokogiriXmlNode);
|
44
44
|
/*
|
45
45
|
* EntityReference represents an EntityReference node in an xml document.
|
46
46
|
*/
|
47
|
-
|
48
|
-
|
49
|
-
cNokogiriXmlEntityReference = klass;
|
47
|
+
cNokogiriXmlEntityReference = rb_define_class_under(mNokogiriXml, "EntityReference", cNokogiriXmlNode);
|
50
48
|
|
51
|
-
rb_define_singleton_method(
|
49
|
+
rb_define_singleton_method(cNokogiriXmlEntityReference, "new", new, -1);
|
52
50
|
}
|
@@ -1,16 +1,35 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
/*
|
4
|
+
* The lifecycle of a Namespace node is more complicated than other Nodes, for two reasons:
|
5
|
+
*
|
6
|
+
* 1. the underlying C structure has a different layout than all the other node structs, with the
|
7
|
+
* `_private` member where we store a pointer to Ruby object data not being in first position.
|
8
|
+
* 2. xmlNs structures returned in an xmlNodeset from an XPath query are copies of the document's
|
9
|
+
* namespaces, and so do not share the same memory lifecycle as everything else in a document.
|
10
|
+
*
|
11
|
+
* As a result of 1, you may see special handling of XML_NAMESPACE_DECL node types throughout the
|
12
|
+
* Nokogiri C code, though I intend to wrap up that logic in ruby_object_{get,set} functions
|
13
|
+
* shortly.
|
14
|
+
*
|
15
|
+
* As a result of 2, you will see we have special handling in this file and in xml_node_set.c to
|
16
|
+
* carefully manage the memory lifecycle of xmlNs structs to match the Ruby object's GC
|
17
|
+
* lifecycle. In xml_node_set.c we have local versions of xmlXPathNodeSetDel() and
|
18
|
+
* xmlXPathFreeNodeSet() that avoid freeing xmlNs structs in the node set. In this file, we decide
|
19
|
+
* whether or not to call dealloc_namespace() depending on whether the xmlNs struct appears to be
|
20
|
+
* in an xmlNodeSet (and thus the result of an XPath query) or not.
|
21
|
+
*
|
22
|
+
* Yes, this is madness.
|
23
|
+
*/
|
2
24
|
|
3
25
|
VALUE cNokogiriXmlNamespace ;
|
4
26
|
|
5
|
-
static void
|
27
|
+
static void
|
28
|
+
dealloc_namespace(xmlNsPtr ns)
|
6
29
|
{
|
7
30
|
/*
|
8
|
-
*
|
9
31
|
* this deallocator is only used for namespace nodes that are part of an xpath
|
10
|
-
* node set.
|
11
|
-
*
|
12
|
-
* see Nokogiri_wrap_xml_namespace() for more details.
|
13
|
-
*
|
32
|
+
* node set. see noko_xml_namespace_wrap().
|
14
33
|
*/
|
15
34
|
NOKOGIRI_DEBUG_START(ns) ;
|
16
35
|
if (ns->href) {
|
@@ -30,12 +49,13 @@ static void dealloc_namespace(xmlNsPtr ns)
|
|
30
49
|
*
|
31
50
|
* Get the prefix for this namespace. Returns +nil+ if there is no prefix.
|
32
51
|
*/
|
33
|
-
static VALUE
|
52
|
+
static VALUE
|
53
|
+
prefix(VALUE self)
|
34
54
|
{
|
35
55
|
xmlNsPtr ns;
|
36
56
|
|
37
57
|
Data_Get_Struct(self, xmlNs, ns);
|
38
|
-
if(!ns->prefix) return Qnil;
|
58
|
+
if (!ns->prefix) { return Qnil; }
|
39
59
|
|
40
60
|
return NOKOGIRI_STR_NEW2(ns->prefix);
|
41
61
|
}
|
@@ -46,66 +66,53 @@ static VALUE prefix(VALUE self)
|
|
46
66
|
*
|
47
67
|
* Get the href for this namespace
|
48
68
|
*/
|
49
|
-
static VALUE
|
69
|
+
static VALUE
|
70
|
+
href(VALUE self)
|
50
71
|
{
|
51
72
|
xmlNsPtr ns;
|
52
73
|
|
53
74
|
Data_Get_Struct(self, xmlNs, ns);
|
54
|
-
if(!ns->href) return Qnil;
|
75
|
+
if (!ns->href) { return Qnil; }
|
55
76
|
|
56
77
|
return NOKOGIRI_STR_NEW2(ns->href);
|
57
78
|
}
|
58
79
|
|
59
|
-
|
60
|
-
|
61
|
-
return (node->next && ! NOKOGIRI_NAMESPACE_EH(node->next));
|
62
|
-
}
|
63
|
-
|
64
|
-
VALUE Nokogiri_wrap_xml_namespace(xmlDocPtr doc, xmlNsPtr node)
|
80
|
+
VALUE
|
81
|
+
noko_xml_namespace_wrap(xmlNsPtr c_namespace, xmlDocPtr c_document)
|
65
82
|
{
|
66
|
-
VALUE
|
67
|
-
|
68
|
-
assert(doc->type == XML_DOCUMENT_NODE || doc->type == XML_HTML_DOCUMENT_NODE);
|
69
|
-
|
70
|
-
if (node->_private) return (VALUE)node->_private;
|
83
|
+
VALUE rb_namespace;
|
71
84
|
|
72
|
-
if (
|
85
|
+
if (c_namespace->_private) {
|
86
|
+
return (VALUE)c_namespace->_private;
|
87
|
+
}
|
73
88
|
|
74
|
-
if (
|
75
|
-
|
89
|
+
if (c_document) {
|
90
|
+
rb_namespace = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, c_namespace);
|
76
91
|
|
77
|
-
if (
|
78
|
-
|
79
|
-
|
80
|
-
* we need to make sure we manage this memory.
|
81
|
-
*
|
82
|
-
* see comments in xml_node_set.c for more details.
|
83
|
-
*/
|
84
|
-
ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, dealloc_namespace, node);
|
85
|
-
} else {
|
86
|
-
ns = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, 0, node);
|
87
|
-
node_cache = rb_iv_get(document, "@node_cache");
|
88
|
-
rb_ary_push(node_cache, ns);
|
92
|
+
if (DOC_RUBY_OBJECT_TEST(c_document)) {
|
93
|
+
rb_iv_set(rb_namespace, "@document", DOC_RUBY_OBJECT(c_document));
|
94
|
+
rb_ary_push(DOC_NODE_CACHE(c_document), rb_namespace);
|
89
95
|
}
|
90
|
-
|
91
|
-
rb_iv_set(ns, "@document", document);
|
92
96
|
} else {
|
93
|
-
|
97
|
+
rb_namespace = Data_Wrap_Struct(cNokogiriXmlNamespace, 0, dealloc_namespace, c_namespace);
|
94
98
|
}
|
95
99
|
|
96
|
-
|
100
|
+
c_namespace->_private = (void *)rb_namespace;
|
97
101
|
|
98
|
-
return
|
102
|
+
return rb_namespace;
|
99
103
|
}
|
100
104
|
|
101
|
-
|
105
|
+
VALUE
|
106
|
+
noko_xml_namespace_wrap_xpath_copy(xmlNsPtr c_namespace)
|
102
107
|
{
|
103
|
-
|
104
|
-
|
105
|
-
VALUE klass = rb_define_class_under(xml, "Namespace", rb_cObject);
|
108
|
+
return noko_xml_namespace_wrap(c_namespace, NULL);
|
109
|
+
}
|
106
110
|
|
107
|
-
|
111
|
+
void
|
112
|
+
noko_init_xml_namespace()
|
113
|
+
{
|
114
|
+
cNokogiriXmlNamespace = rb_define_class_under(mNokogiriXml, "Namespace", rb_cObject);
|
108
115
|
|
109
|
-
rb_define_method(
|
110
|
-
rb_define_method(
|
116
|
+
rb_define_method(cNokogiriXmlNamespace, "prefix", prefix, 0);
|
117
|
+
rb_define_method(cNokogiriXmlNamespace, "href", href, 0);
|
111
118
|
}
|
data/ext/nokogiri/xml_node.c
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
#include <
|
1
|
+
#include <nokogiri.h>
|
2
|
+
|
3
|
+
VALUE cNokogiriXmlNode ;
|
2
4
|
|
3
5
|
static ID decorate, decorate_bang;
|
4
6
|
|
5
7
|
#ifdef DEBUG
|
6
|
-
static void
|
8
|
+
static void
|
9
|
+
debug_node_dealloc(xmlNodePtr x)
|
7
10
|
{
|
8
11
|
NOKOGIRI_DEBUG_START(x)
|
9
12
|
NOKOGIRI_DEBUG_END(x)
|
@@ -12,23 +15,25 @@ static void debug_node_dealloc(xmlNodePtr x)
|
|
12
15
|
# define debug_node_dealloc 0
|
13
16
|
#endif
|
14
17
|
|
15
|
-
static void
|
18
|
+
static void
|
19
|
+
mark(xmlNodePtr node)
|
16
20
|
{
|
17
21
|
xmlDocPtr doc = node->doc;
|
18
|
-
if(doc->type == XML_DOCUMENT_NODE || doc->type == XML_HTML_DOCUMENT_NODE) {
|
19
|
-
if(DOC_RUBY_OBJECT_TEST(doc)) {
|
22
|
+
if (doc->type == XML_DOCUMENT_NODE || doc->type == XML_HTML_DOCUMENT_NODE) {
|
23
|
+
if (DOC_RUBY_OBJECT_TEST(doc)) {
|
20
24
|
rb_gc_mark(DOC_RUBY_OBJECT(doc));
|
21
25
|
}
|
22
|
-
} else if(node->doc->_private) {
|
26
|
+
} else if (node->doc->_private) {
|
23
27
|
rb_gc_mark((VALUE)doc->_private);
|
24
28
|
}
|
25
29
|
}
|
26
30
|
|
27
31
|
/* :nodoc: */
|
28
|
-
typedef xmlNodePtr
|
32
|
+
typedef xmlNodePtr(*pivot_reparentee_func)(xmlNodePtr, xmlNodePtr);
|
29
33
|
|
30
34
|
/* :nodoc: */
|
31
|
-
static void
|
35
|
+
static void
|
36
|
+
relink_namespace(xmlNodePtr reparented)
|
32
37
|
{
|
33
38
|
xmlNodePtr child;
|
34
39
|
|
@@ -42,7 +47,7 @@ static void relink_namespace(xmlNodePtr reparented)
|
|
42
47
|
name = xmlSplitQName2(reparented->name, &prefix);
|
43
48
|
|
44
49
|
if (reparented->type == XML_ATTRIBUTE_NODE) {
|
45
|
-
if (prefix == NULL || strcmp((char*)prefix, XMLNS_PREFIX) == 0) {
|
50
|
+
if (prefix == NULL || strcmp((char *)prefix, XMLNS_PREFIX) == 0) {
|
46
51
|
xmlFree(name);
|
47
52
|
xmlFree(prefix);
|
48
53
|
return;
|
@@ -87,7 +92,7 @@ static void relink_namespace(xmlNodePtr reparented)
|
|
87
92
|
} else {
|
88
93
|
reparented->nsDef = curr->next;
|
89
94
|
}
|
90
|
-
|
95
|
+
noko_xml_document_pin_namespace(curr, reparented->doc);
|
91
96
|
} else {
|
92
97
|
prev = curr;
|
93
98
|
}
|
@@ -128,7 +133,7 @@ static void relink_namespace(xmlNodePtr reparented)
|
|
128
133
|
|
129
134
|
if (reparented->type == XML_ELEMENT_NODE) {
|
130
135
|
child = (xmlNodePtr)((xmlElementPtr)reparented)->attributes;
|
131
|
-
while(NULL != child) {
|
136
|
+
while (NULL != child) {
|
132
137
|
relink_namespace(child);
|
133
138
|
child = child->next;
|
134
139
|
}
|
@@ -136,7 +141,8 @@ static void relink_namespace(xmlNodePtr reparented)
|
|
136
141
|
}
|
137
142
|
|
138
143
|
/* :nodoc: */
|
139
|
-
static xmlNodePtr
|
144
|
+
static xmlNodePtr
|
145
|
+
xmlReplaceNodeWrapper(xmlNodePtr pivot, xmlNodePtr new_node)
|
140
146
|
{
|
141
147
|
xmlNodePtr retval ;
|
142
148
|
|
@@ -160,16 +166,17 @@ static xmlNodePtr xmlReplaceNodeWrapper(xmlNodePtr pivot, xmlNodePtr new_node)
|
|
160
166
|
}
|
161
167
|
|
162
168
|
/* :nodoc: */
|
163
|
-
static VALUE
|
169
|
+
static VALUE
|
170
|
+
reparent_node_with(VALUE pivot_obj, VALUE reparentee_obj, pivot_reparentee_func prf)
|
164
171
|
{
|
165
172
|
VALUE reparented_obj ;
|
166
173
|
xmlNodePtr reparentee, pivot, reparented, next_text, new_next_text, parent ;
|
167
174
|
int original_ns_prefix_is_default = 0 ;
|
168
175
|
|
169
|
-
if(!rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlNode)) {
|
176
|
+
if (!rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlNode)) {
|
170
177
|
rb_raise(rb_eArgError, "node must be a Nokogiri::XML::Node");
|
171
178
|
}
|
172
|
-
if(rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlDocument)) {
|
179
|
+
if (rb_obj_is_kind_of(reparentee_obj, cNokogiriXmlDocument)) {
|
173
180
|
rb_raise(rb_eArgError, "node must be a Nokogiri::XML::Node");
|
174
181
|
}
|
175
182
|
|
@@ -290,7 +297,7 @@ ok:
|
|
290
297
|
original_ns_prefix_is_default = 1;
|
291
298
|
}
|
292
299
|
|
293
|
-
|
300
|
+
noko_xml_document_pin_node(reparentee);
|
294
301
|
|
295
302
|
if (!(reparentee = xmlDocCopyNode(reparentee, pivot->doc, 1))) {
|
296
303
|
rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
|
@@ -301,7 +308,7 @@ ok:
|
|
301
308
|
* issue #391, where new node's prefix may become the string "default"
|
302
309
|
* see libxml2 tree.c xmlNewReconciliedNs which implements this behavior.
|
303
310
|
*/
|
304
|
-
xmlFree((xmlChar*)reparentee->ns->prefix);
|
311
|
+
xmlFree((xmlChar *)reparentee->ns->prefix);
|
305
312
|
reparentee->ns->prefix = NULL;
|
306
313
|
}
|
307
314
|
}
|
@@ -330,12 +337,12 @@ ok:
|
|
330
337
|
new_next_text = xmlDocCopyNode(next_text, pivot->doc, 1) ;
|
331
338
|
|
332
339
|
xmlUnlinkNode(next_text);
|
333
|
-
|
340
|
+
noko_xml_document_pin_node(next_text);
|
334
341
|
|
335
342
|
xmlAddNextSibling(pivot, new_next_text);
|
336
343
|
}
|
337
344
|
|
338
|
-
if(!(reparented = (*prf)(pivot, reparentee))) {
|
345
|
+
if (!(reparented = (*prf)(pivot, reparentee))) {
|
339
346
|
rb_raise(rb_eRuntimeError, "Could not reparent node");
|
340
347
|
}
|
341
348
|
|
@@ -348,7 +355,7 @@ ok:
|
|
348
355
|
|
349
356
|
relink_namespace(reparented);
|
350
357
|
|
351
|
-
reparented_obj =
|
358
|
+
reparented_obj = noko_xml_node_wrap(Qnil, reparented);
|
352
359
|
|
353
360
|
rb_funcall(reparented_obj, decorate_bang, 0);
|
354
361
|
|
@@ -362,7 +369,8 @@ ok:
|
|
362
369
|
*
|
363
370
|
* Get the document for this Node
|
364
371
|
*/
|
365
|
-
static VALUE
|
372
|
+
static VALUE
|
373
|
+
document(VALUE self)
|
366
374
|
{
|
367
375
|
xmlNodePtr node;
|
368
376
|
Data_Get_Struct(self, xmlNode, node);
|
@@ -375,7 +383,8 @@ static VALUE document(VALUE self)
|
|
375
383
|
*
|
376
384
|
* Get the internal pointer number
|
377
385
|
*/
|
378
|
-
static VALUE
|
386
|
+
static VALUE
|
387
|
+
pointer_id(VALUE self)
|
379
388
|
{
|
380
389
|
xmlNodePtr node;
|
381
390
|
Data_Get_Struct(self, xmlNode, node);
|
@@ -389,7 +398,8 @@ static VALUE pointer_id(VALUE self)
|
|
389
398
|
*
|
390
399
|
* Encode any special characters in +string+
|
391
400
|
*/
|
392
|
-
static VALUE
|
401
|
+
static VALUE
|
402
|
+
encode_special_chars(VALUE self, VALUE string)
|
393
403
|
{
|
394
404
|
xmlNodePtr node;
|
395
405
|
xmlChar *encoded;
|
@@ -419,7 +429,8 @@ static VALUE encode_special_chars(VALUE self, VALUE string)
|
|
419
429
|
* doc.create_internal_subset("chapter", nil, "chapter.dtd")
|
420
430
|
* # => <!DOCTYPE chapter SYSTEM "chapter.dtd">
|
421
431
|
*/
|
422
|
-
static VALUE
|
432
|
+
static VALUE
|
433
|
+
create_internal_subset(VALUE self, VALUE name, VALUE external_id, VALUE system_id)
|
423
434
|
{
|
424
435
|
xmlNodePtr node;
|
425
436
|
xmlDocPtr doc;
|
@@ -429,7 +440,7 @@ static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, V
|
|
429
440
|
|
430
441
|
doc = node->doc;
|
431
442
|
|
432
|
-
if(xmlGetIntSubset(doc)) {
|
443
|
+
if (xmlGetIntSubset(doc)) {
|
433
444
|
rb_raise(rb_eRuntimeError, "Document already has an internal subset");
|
434
445
|
}
|
435
446
|
|
@@ -440,9 +451,9 @@ static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, V
|
|
440
451
|
NIL_P(system_id) ? NULL : (const xmlChar *)StringValueCStr(system_id)
|
441
452
|
);
|
442
453
|
|
443
|
-
if(!dtd) { return Qnil; }
|
454
|
+
if (!dtd) { return Qnil; }
|
444
455
|
|
445
|
-
return
|
456
|
+
return noko_xml_node_wrap(Qnil, (xmlNodePtr)dtd);
|
446
457
|
}
|
447
458
|
|
448
459
|
/*
|
@@ -451,7 +462,8 @@ static VALUE create_internal_subset(VALUE self, VALUE name, VALUE external_id, V
|
|
451
462
|
*
|
452
463
|
* Create an external subset
|
453
464
|
*/
|
454
|
-
static VALUE
|
465
|
+
static VALUE
|
466
|
+
create_external_subset(VALUE self, VALUE name, VALUE external_id, VALUE system_id)
|
455
467
|
{
|
456
468
|
xmlNodePtr node;
|
457
469
|
xmlDocPtr doc;
|
@@ -461,7 +473,7 @@ static VALUE create_external_subset(VALUE self, VALUE name, VALUE external_id, V
|
|
461
473
|
|
462
474
|
doc = node->doc;
|
463
475
|
|
464
|
-
if(doc->extSubset) {
|
476
|
+
if (doc->extSubset) {
|
465
477
|
rb_raise(rb_eRuntimeError, "Document already has an external subset");
|
466
478
|
}
|
467
479
|
|
@@ -472,9 +484,9 @@ static VALUE create_external_subset(VALUE self, VALUE name, VALUE external_id, V
|
|
472
484
|
NIL_P(system_id) ? NULL : (const xmlChar *)StringValueCStr(system_id)
|
473
485
|
);
|
474
486
|
|
475
|
-
if(!dtd) { return Qnil; }
|
487
|
+
if (!dtd) { return Qnil; }
|
476
488
|
|
477
|
-
return
|
489
|
+
return noko_xml_node_wrap(Qnil, (xmlNodePtr)dtd);
|
478
490
|
}
|
479
491
|
|
480
492
|
/*
|
@@ -483,7 +495,8 @@ static VALUE create_external_subset(VALUE self, VALUE name, VALUE external_id, V
|
|
483
495
|
*
|
484
496
|
* Get the external subset
|
485
497
|
*/
|
486
|
-
static VALUE
|
498
|
+
static VALUE
|
499
|
+
external_subset(VALUE self)
|
487
500
|
{
|
488
501
|
xmlNodePtr node;
|
489
502
|
xmlDocPtr doc;
|
@@ -491,14 +504,14 @@ static VALUE external_subset(VALUE self)
|
|
491
504
|
|
492
505
|
Data_Get_Struct(self, xmlNode, node);
|
493
506
|
|
494
|
-
if(!node->doc) { return Qnil; }
|
507
|
+
if (!node->doc) { return Qnil; }
|
495
508
|
|
496
509
|
doc = node->doc;
|
497
510
|
dtd = doc->extSubset;
|
498
511
|
|
499
|
-
if(!dtd) { return Qnil; }
|
512
|
+
if (!dtd) { return Qnil; }
|
500
513
|
|
501
|
-
return
|
514
|
+
return noko_xml_node_wrap(Qnil, (xmlNodePtr)dtd);
|
502
515
|
}
|
503
516
|
|
504
517
|
/*
|
@@ -507,7 +520,8 @@ static VALUE external_subset(VALUE self)
|
|
507
520
|
*
|
508
521
|
* Get the internal subset
|
509
522
|
*/
|
510
|
-
static VALUE
|
523
|
+
static VALUE
|
524
|
+
internal_subset(VALUE self)
|
511
525
|
{
|
512
526
|
xmlNodePtr node;
|
513
527
|
xmlDocPtr doc;
|
@@ -515,14 +529,14 @@ static VALUE internal_subset(VALUE self)
|
|
515
529
|
|
516
530
|
Data_Get_Struct(self, xmlNode, node);
|
517
531
|
|
518
|
-
if(!node->doc) { return Qnil; }
|
532
|
+
if (!node->doc) { return Qnil; }
|
519
533
|
|
520
534
|
doc = node->doc;
|
521
535
|
dtd = xmlGetIntSubset(doc);
|
522
536
|
|
523
|
-
if(!dtd) { return Qnil; }
|
537
|
+
if (!dtd) { return Qnil; }
|
524
538
|
|
525
|
-
return
|
539
|
+
return noko_xml_node_wrap(Qnil, (xmlNodePtr)dtd);
|
526
540
|
}
|
527
541
|
|
528
542
|
/*
|
@@ -537,7 +551,8 @@ static VALUE internal_subset(VALUE self)
|
|
537
551
|
* node's parent document. Defaults to the current node's document.
|
538
552
|
* current document.
|
539
553
|
*/
|
540
|
-
static VALUE
|
554
|
+
static VALUE
|
555
|
+
duplicate_node(int argc, VALUE *argv, VALUE self)
|
541
556
|
{
|
542
557
|
VALUE r_level, r_new_parent_doc;
|
543
558
|
int level;
|
@@ -561,11 +576,11 @@ static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
|
|
561
576
|
}
|
562
577
|
|
563
578
|
dup = xmlDocCopyNode(node, new_parent_doc, level);
|
564
|
-
if(dup == NULL) { return Qnil; }
|
579
|
+
if (dup == NULL) { return Qnil; }
|
565
580
|
|
566
|
-
|
581
|
+
noko_xml_document_pin_node(dup);
|
567
582
|
|
568
|
-
return
|
583
|
+
return noko_xml_node_wrap(rb_obj_class(self), dup);
|
569
584
|
}
|
570
585
|
|
571
586
|
/*
|
@@ -574,12 +589,13 @@ static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
|
|
574
589
|
*
|
575
590
|
* Unlink this node from its current context.
|
576
591
|
*/
|
577
|
-
static VALUE
|
592
|
+
static VALUE
|
593
|
+
unlink_node(VALUE self)
|
578
594
|
{
|
579
595
|
xmlNodePtr node;
|
580
596
|
Data_Get_Struct(self, xmlNode, node);
|
581
597
|
xmlUnlinkNode(node);
|
582
|
-
|
598
|
+
noko_xml_document_pin_node(node);
|
583
599
|
return self;
|
584
600
|
}
|
585
601
|
|
@@ -589,7 +605,8 @@ static VALUE unlink_node(VALUE self)
|
|
589
605
|
*
|
590
606
|
* Is this node blank?
|
591
607
|
*/
|
592
|
-
static VALUE
|
608
|
+
static VALUE
|
609
|
+
blank_eh(VALUE self)
|
593
610
|
{
|
594
611
|
xmlNodePtr node;
|
595
612
|
Data_Get_Struct(self, xmlNode, node);
|
@@ -602,15 +619,16 @@ static VALUE blank_eh(VALUE self)
|
|
602
619
|
*
|
603
620
|
* Returns the next sibling node
|
604
621
|
*/
|
605
|
-
static VALUE
|
622
|
+
static VALUE
|
623
|
+
next_sibling(VALUE self)
|
606
624
|
{
|
607
625
|
xmlNodePtr node, sibling;
|
608
626
|
Data_Get_Struct(self, xmlNode, node);
|
609
627
|
|
610
628
|
sibling = node->next;
|
611
|
-
if(!sibling) { return Qnil; }
|
629
|
+
if (!sibling) { return Qnil; }
|
612
630
|
|
613
|
-
return
|
631
|
+
return noko_xml_node_wrap(Qnil, sibling) ;
|
614
632
|
}
|
615
633
|
|
616
634
|
/*
|
@@ -619,15 +637,16 @@ static VALUE next_sibling(VALUE self)
|
|
619
637
|
*
|
620
638
|
* Returns the previous sibling node
|
621
639
|
*/
|
622
|
-
static VALUE
|
640
|
+
static VALUE
|
641
|
+
previous_sibling(VALUE self)
|
623
642
|
{
|
624
643
|
xmlNodePtr node, sibling;
|
625
644
|
Data_Get_Struct(self, xmlNode, node);
|
626
645
|
|
627
646
|
sibling = node->prev;
|
628
|
-
if(!sibling) { return Qnil; }
|
647
|
+
if (!sibling) { return Qnil; }
|
629
648
|
|
630
|
-
return
|
649
|
+
return noko_xml_node_wrap(Qnil, sibling);
|
631
650
|
}
|
632
651
|
|
633
652
|
/*
|
@@ -636,15 +655,16 @@ static VALUE previous_sibling(VALUE self)
|
|
636
655
|
*
|
637
656
|
* Returns the next Nokogiri::XML::Element type sibling node.
|
638
657
|
*/
|
639
|
-
static VALUE
|
658
|
+
static VALUE
|
659
|
+
next_element(VALUE self)
|
640
660
|
{
|
641
661
|
xmlNodePtr node, sibling;
|
642
662
|
Data_Get_Struct(self, xmlNode, node);
|
643
663
|
|
644
664
|
sibling = xmlNextElementSibling(node);
|
645
|
-
if(!sibling) { return Qnil; }
|
665
|
+
if (!sibling) { return Qnil; }
|
646
666
|
|
647
|
-
return
|
667
|
+
return noko_xml_node_wrap(Qnil, sibling);
|
648
668
|
}
|
649
669
|
|
650
670
|
/*
|
@@ -653,7 +673,8 @@ static VALUE next_element(VALUE self)
|
|
653
673
|
*
|
654
674
|
* Returns the previous Nokogiri::XML::Element type sibling node.
|
655
675
|
*/
|
656
|
-
static VALUE
|
676
|
+
static VALUE
|
677
|
+
previous_element(VALUE self)
|
657
678
|
{
|
658
679
|
xmlNodePtr node, sibling;
|
659
680
|
Data_Get_Struct(self, xmlNode, node);
|
@@ -662,23 +683,24 @@ static VALUE previous_element(VALUE self)
|
|
662
683
|
* note that we don't use xmlPreviousElementSibling here because it's buggy pre-2.7.7.
|
663
684
|
*/
|
664
685
|
sibling = node->prev;
|
665
|
-
if(!sibling) { return Qnil; }
|
686
|
+
if (!sibling) { return Qnil; }
|
666
687
|
|
667
|
-
while(sibling && sibling->type != XML_ELEMENT_NODE) {
|
688
|
+
while (sibling && sibling->type != XML_ELEMENT_NODE) {
|
668
689
|
sibling = sibling->prev;
|
669
690
|
}
|
670
691
|
|
671
|
-
return sibling ?
|
692
|
+
return sibling ? noko_xml_node_wrap(Qnil, sibling) : Qnil ;
|
672
693
|
}
|
673
694
|
|
674
695
|
/* :nodoc: */
|
675
|
-
static VALUE
|
696
|
+
static VALUE
|
697
|
+
replace(VALUE self, VALUE new_node)
|
676
698
|
{
|
677
699
|
VALUE reparent = reparent_node_with(self, new_node, xmlReplaceNodeWrapper);
|
678
700
|
|
679
701
|
xmlNodePtr pivot;
|
680
702
|
Data_Get_Struct(self, xmlNode, pivot);
|
681
|
-
|
703
|
+
noko_xml_document_pin_node(pivot);
|
682
704
|
|
683
705
|
return reparent;
|
684
706
|
}
|
@@ -689,7 +711,8 @@ static VALUE replace(VALUE self, VALUE new_node)
|
|
689
711
|
*
|
690
712
|
* Get the list of children for this node as a NodeSet
|
691
713
|
*/
|
692
|
-
static VALUE
|
714
|
+
static VALUE
|
715
|
+
children(VALUE self)
|
693
716
|
{
|
694
717
|
xmlNodePtr node;
|
695
718
|
xmlNodePtr child;
|
@@ -704,15 +727,15 @@ static VALUE children(VALUE self)
|
|
704
727
|
|
705
728
|
document = DOC_RUBY_OBJECT(node->doc);
|
706
729
|
|
707
|
-
if(!child) { return
|
730
|
+
if (!child) { return noko_xml_node_set_wrap(set, document); }
|
708
731
|
|
709
732
|
child = child->next;
|
710
|
-
while(NULL != child) {
|
733
|
+
while (NULL != child) {
|
711
734
|
xmlXPathNodeSetAddUnique(set, child);
|
712
735
|
child = child->next;
|
713
736
|
}
|
714
737
|
|
715
|
-
node_set =
|
738
|
+
node_set = noko_xml_node_set_wrap(set, document);
|
716
739
|
|
717
740
|
return node_set;
|
718
741
|
}
|
@@ -728,7 +751,8 @@ static VALUE children(VALUE self)
|
|
728
751
|
*
|
729
752
|
* @doc.root.element_children.all? { |x| x.element? } # => true
|
730
753
|
*/
|
731
|
-
static VALUE
|
754
|
+
static VALUE
|
755
|
+
element_children(VALUE self)
|
732
756
|
{
|
733
757
|
xmlNodePtr node;
|
734
758
|
xmlNodePtr child;
|
@@ -743,15 +767,15 @@ static VALUE element_children(VALUE self)
|
|
743
767
|
|
744
768
|
document = DOC_RUBY_OBJECT(node->doc);
|
745
769
|
|
746
|
-
if(!child) { return
|
770
|
+
if (!child) { return noko_xml_node_set_wrap(set, document); }
|
747
771
|
|
748
772
|
child = xmlNextElementSibling(child);
|
749
|
-
while(NULL != child) {
|
773
|
+
while (NULL != child) {
|
750
774
|
xmlXPathNodeSetAddUnique(set, child);
|
751
775
|
child = xmlNextElementSibling(child);
|
752
776
|
}
|
753
777
|
|
754
|
-
node_set =
|
778
|
+
node_set = noko_xml_node_set_wrap(set, document);
|
755
779
|
|
756
780
|
return node_set;
|
757
781
|
}
|
@@ -762,15 +786,16 @@ static VALUE element_children(VALUE self)
|
|
762
786
|
*
|
763
787
|
* Returns the child node
|
764
788
|
*/
|
765
|
-
static VALUE
|
789
|
+
static VALUE
|
790
|
+
child(VALUE self)
|
766
791
|
{
|
767
792
|
xmlNodePtr node, child;
|
768
793
|
Data_Get_Struct(self, xmlNode, node);
|
769
794
|
|
770
795
|
child = node->children;
|
771
|
-
if(!child) { return Qnil; }
|
796
|
+
if (!child) { return Qnil; }
|
772
797
|
|
773
|
-
return
|
798
|
+
return noko_xml_node_wrap(Qnil, child);
|
774
799
|
}
|
775
800
|
|
776
801
|
/*
|
@@ -783,15 +808,16 @@ static VALUE child(VALUE self)
|
|
783
808
|
*
|
784
809
|
* @doc.root.first_element_child.element? # => true
|
785
810
|
*/
|
786
|
-
static VALUE
|
811
|
+
static VALUE
|
812
|
+
first_element_child(VALUE self)
|
787
813
|
{
|
788
814
|
xmlNodePtr node, child;
|
789
815
|
Data_Get_Struct(self, xmlNode, node);
|
790
816
|
|
791
817
|
child = xmlFirstElementChild(node);
|
792
|
-
if(!child) { return Qnil; }
|
818
|
+
if (!child) { return Qnil; }
|
793
819
|
|
794
|
-
return
|
820
|
+
return noko_xml_node_wrap(Qnil, child);
|
795
821
|
}
|
796
822
|
|
797
823
|
/*
|
@@ -804,15 +830,16 @@ static VALUE first_element_child(VALUE self)
|
|
804
830
|
*
|
805
831
|
* @doc.root.last_element_child.element? # => true
|
806
832
|
*/
|
807
|
-
static VALUE
|
833
|
+
static VALUE
|
834
|
+
last_element_child(VALUE self)
|
808
835
|
{
|
809
836
|
xmlNodePtr node, child;
|
810
837
|
Data_Get_Struct(self, xmlNode, node);
|
811
838
|
|
812
839
|
child = xmlLastElementChild(node);
|
813
|
-
if(!child) { return Qnil; }
|
840
|
+
if (!child) { return Qnil; }
|
814
841
|
|
815
|
-
return
|
842
|
+
return noko_xml_node_wrap(Qnil, child);
|
816
843
|
}
|
817
844
|
|
818
845
|
/*
|
@@ -821,11 +848,12 @@ static VALUE last_element_child(VALUE self)
|
|
821
848
|
*
|
822
849
|
* Returns true if +attribute+ is set
|
823
850
|
*/
|
824
|
-
static VALUE
|
851
|
+
static VALUE
|
852
|
+
key_eh(VALUE self, VALUE attribute)
|
825
853
|
{
|
826
854
|
xmlNodePtr node;
|
827
855
|
Data_Get_Struct(self, xmlNode, node);
|
828
|
-
if(xmlHasProp(node, (xmlChar *)StringValueCStr(attribute))) {
|
856
|
+
if (xmlHasProp(node, (xmlChar *)StringValueCStr(attribute))) {
|
829
857
|
return Qtrue;
|
830
858
|
}
|
831
859
|
return Qfalse;
|
@@ -837,12 +865,13 @@ static VALUE key_eh(VALUE self, VALUE attribute)
|
|
837
865
|
*
|
838
866
|
* Returns true if +attribute+ is set with +namespace+
|
839
867
|
*/
|
840
|
-
static VALUE
|
868
|
+
static VALUE
|
869
|
+
namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
|
841
870
|
{
|
842
871
|
xmlNodePtr node;
|
843
872
|
Data_Get_Struct(self, xmlNode, node);
|
844
|
-
if(xmlHasNsProp(node, (xmlChar *)StringValueCStr(attribute),
|
845
|
-
|
873
|
+
if (xmlHasNsProp(node, (xmlChar *)StringValueCStr(attribute),
|
874
|
+
NIL_P(namespace) ? NULL : (xmlChar *)StringValueCStr(namespace))) {
|
846
875
|
return Qtrue;
|
847
876
|
}
|
848
877
|
return Qfalse;
|
@@ -854,7 +883,8 @@ static VALUE namespaced_key_eh(VALUE self, VALUE attribute, VALUE namespace)
|
|
854
883
|
*
|
855
884
|
* Set the +property+ to +value+
|
856
885
|
*/
|
857
|
-
static VALUE
|
886
|
+
static VALUE
|
887
|
+
set(VALUE self, VALUE property, VALUE value)
|
858
888
|
{
|
859
889
|
xmlNodePtr node, cur;
|
860
890
|
xmlAttrPtr prop;
|
@@ -867,13 +897,13 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
|
|
867
897
|
* We can avoid this by unlinking these nodes first.
|
868
898
|
*/
|
869
899
|
if (node->type != XML_ELEMENT_NODE) {
|
870
|
-
return(Qnil);
|
900
|
+
return (Qnil);
|
871
901
|
}
|
872
902
|
prop = xmlHasProp(node, (xmlChar *)StringValueCStr(property));
|
873
903
|
if (prop && prop->children) {
|
874
904
|
for (cur = prop->children; cur; cur = cur->next) {
|
875
905
|
if (cur->_private) {
|
876
|
-
|
906
|
+
noko_xml_document_pin_node(cur);
|
877
907
|
xmlUnlinkNode(cur);
|
878
908
|
}
|
879
909
|
}
|
@@ -891,7 +921,8 @@ static VALUE set(VALUE self, VALUE property, VALUE value)
|
|
891
921
|
*
|
892
922
|
* Get the value for +attribute+
|
893
923
|
*/
|
894
|
-
static VALUE
|
924
|
+
static VALUE
|
925
|
+
get(VALUE self, VALUE rattribute)
|
895
926
|
{
|
896
927
|
xmlNodePtr node;
|
897
928
|
xmlChar *value = 0;
|
@@ -917,7 +948,7 @@ static VALUE get(VALUE self, VALUE rattribute)
|
|
917
948
|
if (ns) {
|
918
949
|
value = xmlGetNsProp(node, attr_name, ns->href);
|
919
950
|
} else {
|
920
|
-
value = xmlGetProp(node, (xmlChar*)StringValueCStr(rattribute));
|
951
|
+
value = xmlGetProp(node, (xmlChar *)StringValueCStr(rattribute));
|
921
952
|
}
|
922
953
|
} else {
|
923
954
|
value = xmlGetNoNsProp(node, attribute);
|
@@ -938,14 +969,15 @@ static VALUE get(VALUE self, VALUE rattribute)
|
|
938
969
|
*
|
939
970
|
* Set the namespace to +namespace+
|
940
971
|
*/
|
941
|
-
static VALUE
|
972
|
+
static VALUE
|
973
|
+
set_namespace(VALUE self, VALUE namespace)
|
942
974
|
{
|
943
975
|
xmlNodePtr node;
|
944
976
|
xmlNsPtr ns = NULL;
|
945
977
|
|
946
978
|
Data_Get_Struct(self, xmlNode, node);
|
947
979
|
|
948
|
-
if(!NIL_P(namespace)) {
|
980
|
+
if (!NIL_P(namespace)) {
|
949
981
|
Data_Get_Struct(namespace, xmlNs, ns);
|
950
982
|
}
|
951
983
|
|
@@ -960,15 +992,16 @@ static VALUE set_namespace(VALUE self, VALUE namespace)
|
|
960
992
|
*
|
961
993
|
* Get the attribute node with +name+
|
962
994
|
*/
|
963
|
-
static VALUE
|
995
|
+
static VALUE
|
996
|
+
attr(VALUE self, VALUE name)
|
964
997
|
{
|
965
998
|
xmlNodePtr node;
|
966
999
|
xmlAttrPtr prop;
|
967
1000
|
Data_Get_Struct(self, xmlNode, node);
|
968
1001
|
prop = xmlHasProp(node, (xmlChar *)StringValueCStr(name));
|
969
1002
|
|
970
|
-
if(! prop) { return Qnil; }
|
971
|
-
return
|
1003
|
+
if (! prop) { return Qnil; }
|
1004
|
+
return noko_xml_node_wrap(Qnil, (xmlNodePtr)prop);
|
972
1005
|
}
|
973
1006
|
|
974
1007
|
/*
|
@@ -977,7 +1010,8 @@ static VALUE attr(VALUE self, VALUE name)
|
|
977
1010
|
*
|
978
1011
|
* Get the attribute node with +name+ and +namespace+
|
979
1012
|
*/
|
980
|
-
static VALUE
|
1013
|
+
static VALUE
|
1014
|
+
attribute_with_ns(VALUE self, VALUE name, VALUE namespace)
|
981
1015
|
{
|
982
1016
|
xmlNodePtr node;
|
983
1017
|
xmlAttrPtr prop;
|
@@ -985,28 +1019,23 @@ static VALUE attribute_with_ns(VALUE self, VALUE name, VALUE namespace)
|
|
985
1019
|
prop = xmlHasNsProp(node, (xmlChar *)StringValueCStr(name),
|
986
1020
|
NIL_P(namespace) ? NULL : (xmlChar *)StringValueCStr(namespace));
|
987
1021
|
|
988
|
-
if(! prop) { return Qnil; }
|
989
|
-
return
|
1022
|
+
if (! prop) { return Qnil; }
|
1023
|
+
return noko_xml_node_wrap(Qnil, (xmlNodePtr)prop);
|
990
1024
|
}
|
991
1025
|
|
992
1026
|
/*
|
993
|
-
*
|
994
|
-
*
|
995
|
-
*
|
996
|
-
* returns a list containing the Node attributes.
|
1027
|
+
* @overload attribute_nodes()
|
1028
|
+
* Get the attributes for a Node
|
1029
|
+
* @return [Array<Nokogiri::XML::Attr>] containing the Node's attributes.
|
997
1030
|
*/
|
998
|
-
static VALUE
|
1031
|
+
static VALUE
|
1032
|
+
attribute_nodes(VALUE rb_node)
|
999
1033
|
{
|
1000
|
-
|
1001
|
-
xmlNodePtr node;
|
1002
|
-
VALUE attr;
|
1003
|
-
|
1004
|
-
Data_Get_Struct(self, xmlNode, node);
|
1034
|
+
xmlNodePtr c_node;
|
1005
1035
|
|
1006
|
-
|
1007
|
-
Nokogiri_xml_node_properties(node, attr);
|
1036
|
+
Data_Get_Struct(rb_node, xmlNode, c_node);
|
1008
1037
|
|
1009
|
-
return
|
1038
|
+
return noko_xml_node_attrs(c_node);
|
1010
1039
|
}
|
1011
1040
|
|
1012
1041
|
|
@@ -1017,16 +1046,17 @@ static VALUE attribute_nodes(VALUE self)
|
|
1017
1046
|
* returns the namespace of the element or attribute node as a Namespace
|
1018
1047
|
* object, or nil if there is no namespace for the element or attribute.
|
1019
1048
|
*/
|
1020
|
-
static VALUE
|
1049
|
+
static VALUE
|
1050
|
+
noko_xml_node_namespace(VALUE rb_node)
|
1021
1051
|
{
|
1022
|
-
xmlNodePtr
|
1023
|
-
Data_Get_Struct(
|
1052
|
+
xmlNodePtr c_node ;
|
1053
|
+
Data_Get_Struct(rb_node, xmlNode, c_node);
|
1024
1054
|
|
1025
|
-
if (
|
1026
|
-
|
1027
|
-
}
|
1055
|
+
if (c_node->ns) {
|
1056
|
+
return noko_xml_namespace_wrap(c_node->ns, c_node->doc);
|
1057
|
+
}
|
1028
1058
|
|
1029
|
-
return Qnil ;
|
1059
|
+
return Qnil ;
|
1030
1060
|
}
|
1031
1061
|
|
1032
1062
|
/*
|
@@ -1035,27 +1065,27 @@ return Qnil ;
|
|
1035
1065
|
*
|
1036
1066
|
* returns namespaces defined on self element directly, as an array of Namespace objects. Includes both a default namespace (as in"xmlns="), and prefixed namespaces (as in "xmlns:prefix=").
|
1037
1067
|
*/
|
1038
|
-
static VALUE
|
1068
|
+
static VALUE
|
1069
|
+
namespace_definitions(VALUE rb_node)
|
1039
1070
|
{
|
1040
1071
|
/* this code in the mode of xmlHasProp() */
|
1041
|
-
xmlNodePtr
|
1042
|
-
|
1043
|
-
|
1072
|
+
xmlNodePtr c_node ;
|
1073
|
+
xmlNsPtr c_namespace;
|
1074
|
+
VALUE definitions = rb_ary_new();
|
1044
1075
|
|
1045
|
-
Data_Get_Struct(
|
1046
|
-
|
1047
|
-
list = rb_ary_new();
|
1048
|
-
|
1049
|
-
ns = node->nsDef;
|
1076
|
+
Data_Get_Struct(rb_node, xmlNode, c_node);
|
1050
1077
|
|
1051
|
-
|
1078
|
+
c_namespace = c_node->nsDef;
|
1079
|
+
if (!c_namespace) {
|
1080
|
+
return definitions;
|
1081
|
+
}
|
1052
1082
|
|
1053
|
-
while(
|
1054
|
-
rb_ary_push(
|
1055
|
-
|
1083
|
+
while (c_namespace != NULL) {
|
1084
|
+
rb_ary_push(definitions, noko_xml_namespace_wrap(c_namespace, c_node->doc));
|
1085
|
+
c_namespace = c_namespace->next;
|
1056
1086
|
}
|
1057
1087
|
|
1058
|
-
return
|
1088
|
+
return definitions;
|
1059
1089
|
}
|
1060
1090
|
|
1061
1091
|
/*
|
@@ -1067,26 +1097,27 @@ static VALUE namespace_definitions(VALUE self)
|
|
1067
1097
|
* namespaces ("xmlns=" style) for self are included in this array; Default
|
1068
1098
|
* namespaces for ancestors, however, are not. See also #namespaces
|
1069
1099
|
*/
|
1070
|
-
static VALUE
|
1100
|
+
static VALUE
|
1101
|
+
namespace_scopes(VALUE rb_node)
|
1071
1102
|
{
|
1072
|
-
xmlNodePtr
|
1073
|
-
|
1074
|
-
|
1103
|
+
xmlNodePtr c_node ;
|
1104
|
+
xmlNsPtr *namespaces;
|
1105
|
+
VALUE scopes = rb_ary_new();
|
1075
1106
|
int j;
|
1076
1107
|
|
1077
|
-
Data_Get_Struct(
|
1078
|
-
|
1079
|
-
list = rb_ary_new();
|
1080
|
-
ns_list = xmlGetNsList(node->doc, node);
|
1108
|
+
Data_Get_Struct(rb_node, xmlNode, c_node);
|
1081
1109
|
|
1082
|
-
|
1110
|
+
namespaces = xmlGetNsList(c_node->doc, c_node);
|
1111
|
+
if (!namespaces) {
|
1112
|
+
return scopes;
|
1113
|
+
}
|
1083
1114
|
|
1084
|
-
for (j = 0 ;
|
1085
|
-
rb_ary_push(
|
1115
|
+
for (j = 0 ; namespaces[j] != NULL ; ++j) {
|
1116
|
+
rb_ary_push(scopes, noko_xml_namespace_wrap(namespaces[j], c_node->doc));
|
1086
1117
|
}
|
1087
1118
|
|
1088
|
-
xmlFree(
|
1089
|
-
return
|
1119
|
+
xmlFree(namespaces);
|
1120
|
+
return scopes;
|
1090
1121
|
}
|
1091
1122
|
|
1092
1123
|
/*
|
@@ -1095,7 +1126,8 @@ static VALUE namespace_scopes(VALUE self)
|
|
1095
1126
|
*
|
1096
1127
|
* Get the type for this Node
|
1097
1128
|
*/
|
1098
|
-
static VALUE
|
1129
|
+
static VALUE
|
1130
|
+
node_type(VALUE self)
|
1099
1131
|
{
|
1100
1132
|
xmlNodePtr node;
|
1101
1133
|
Data_Get_Struct(self, xmlNode, node);
|
@@ -1108,7 +1140,8 @@ static VALUE node_type(VALUE self)
|
|
1108
1140
|
*
|
1109
1141
|
* Set the content for this Node
|
1110
1142
|
*/
|
1111
|
-
static VALUE
|
1143
|
+
static VALUE
|
1144
|
+
set_native_content(VALUE self, VALUE content)
|
1112
1145
|
{
|
1113
1146
|
xmlNodePtr node, child, next ;
|
1114
1147
|
Data_Get_Struct(self, xmlNode, node);
|
@@ -1117,7 +1150,7 @@ static VALUE set_native_content(VALUE self, VALUE content)
|
|
1117
1150
|
while (NULL != child) {
|
1118
1151
|
next = child->next ;
|
1119
1152
|
xmlUnlinkNode(child) ;
|
1120
|
-
|
1153
|
+
noko_xml_document_pin_node(child);
|
1121
1154
|
child = next ;
|
1122
1155
|
}
|
1123
1156
|
|
@@ -1132,15 +1165,16 @@ static VALUE set_native_content(VALUE self, VALUE content)
|
|
1132
1165
|
* Returns the plaintext content for this Node. Note that entities will always
|
1133
1166
|
* be expanded in the returned string.
|
1134
1167
|
*/
|
1135
|
-
static VALUE
|
1168
|
+
static VALUE
|
1169
|
+
get_native_content(VALUE self)
|
1136
1170
|
{
|
1137
1171
|
xmlNodePtr node;
|
1138
|
-
xmlChar *
|
1172
|
+
xmlChar *content;
|
1139
1173
|
|
1140
1174
|
Data_Get_Struct(self, xmlNode, node);
|
1141
1175
|
|
1142
1176
|
content = xmlNodeGetContent(node);
|
1143
|
-
if(content) {
|
1177
|
+
if (content) {
|
1144
1178
|
VALUE rval = NOKOGIRI_STR_NEW2(content);
|
1145
1179
|
xmlFree(content);
|
1146
1180
|
return rval;
|
@@ -1154,13 +1188,14 @@ static VALUE get_native_content(VALUE self)
|
|
1154
1188
|
*
|
1155
1189
|
* Set the language of a node, i.e. the values of the xml:lang attribute.
|
1156
1190
|
*/
|
1157
|
-
static VALUE
|
1191
|
+
static VALUE
|
1192
|
+
set_lang(VALUE self_rb, VALUE lang_rb)
|
1158
1193
|
{
|
1159
1194
|
xmlNodePtr self ;
|
1160
|
-
xmlChar*
|
1195
|
+
xmlChar *lang ;
|
1161
1196
|
|
1162
1197
|
Data_Get_Struct(self_rb, xmlNode, self);
|
1163
|
-
lang = (xmlChar*)StringValueCStr(lang_rb);
|
1198
|
+
lang = (xmlChar *)StringValueCStr(lang_rb);
|
1164
1199
|
|
1165
1200
|
xmlNodeSetLang(self, lang);
|
1166
1201
|
|
@@ -1174,10 +1209,11 @@ static VALUE set_lang(VALUE self_rb, VALUE lang_rb)
|
|
1174
1209
|
* Searches the language of a node, i.e. the values of the xml:lang attribute or
|
1175
1210
|
* the one carried by the nearest ancestor.
|
1176
1211
|
*/
|
1177
|
-
static VALUE
|
1212
|
+
static VALUE
|
1213
|
+
get_lang(VALUE self_rb)
|
1178
1214
|
{
|
1179
1215
|
xmlNodePtr self ;
|
1180
|
-
xmlChar*
|
1216
|
+
xmlChar *lang ;
|
1181
1217
|
VALUE lang_rb ;
|
1182
1218
|
|
1183
1219
|
Data_Get_Struct(self_rb, xmlNode, self);
|
@@ -1193,7 +1229,8 @@ static VALUE get_lang(VALUE self_rb)
|
|
1193
1229
|
}
|
1194
1230
|
|
1195
1231
|
/* :nodoc: */
|
1196
|
-
static VALUE
|
1232
|
+
static VALUE
|
1233
|
+
add_child(VALUE self, VALUE new_child)
|
1197
1234
|
{
|
1198
1235
|
return reparent_node_with(self, new_child, xmlAddChild);
|
1199
1236
|
}
|
@@ -1204,15 +1241,16 @@ static VALUE add_child(VALUE self, VALUE new_child)
|
|
1204
1241
|
*
|
1205
1242
|
* Get the parent Node for this Node
|
1206
1243
|
*/
|
1207
|
-
static VALUE
|
1244
|
+
static VALUE
|
1245
|
+
get_parent(VALUE self)
|
1208
1246
|
{
|
1209
1247
|
xmlNodePtr node, parent;
|
1210
1248
|
Data_Get_Struct(self, xmlNode, node);
|
1211
1249
|
|
1212
1250
|
parent = node->parent;
|
1213
|
-
if(!parent) { return Qnil; }
|
1251
|
+
if (!parent) { return Qnil; }
|
1214
1252
|
|
1215
|
-
return
|
1253
|
+
return noko_xml_node_wrap(Qnil, parent) ;
|
1216
1254
|
}
|
1217
1255
|
|
1218
1256
|
/*
|
@@ -1221,11 +1259,12 @@ static VALUE get_parent(VALUE self)
|
|
1221
1259
|
*
|
1222
1260
|
* Set the name for this Node
|
1223
1261
|
*/
|
1224
|
-
static VALUE
|
1262
|
+
static VALUE
|
1263
|
+
set_name(VALUE self, VALUE new_name)
|
1225
1264
|
{
|
1226
1265
|
xmlNodePtr node;
|
1227
1266
|
Data_Get_Struct(self, xmlNode, node);
|
1228
|
-
xmlNodeSetName(node, (xmlChar*)StringValueCStr(new_name));
|
1267
|
+
xmlNodeSetName(node, (xmlChar *)StringValueCStr(new_name));
|
1229
1268
|
return new_name;
|
1230
1269
|
}
|
1231
1270
|
|
@@ -1235,11 +1274,12 @@ static VALUE set_name(VALUE self, VALUE new_name)
|
|
1235
1274
|
*
|
1236
1275
|
* Returns the name for this Node
|
1237
1276
|
*/
|
1238
|
-
static VALUE
|
1277
|
+
static VALUE
|
1278
|
+
get_name(VALUE self)
|
1239
1279
|
{
|
1240
1280
|
xmlNodePtr node;
|
1241
1281
|
Data_Get_Struct(self, xmlNode, node);
|
1242
|
-
if(node->name) {
|
1282
|
+
if (node->name) {
|
1243
1283
|
return NOKOGIRI_STR_NEW2(node->name);
|
1244
1284
|
}
|
1245
1285
|
return Qnil;
|
@@ -1251,7 +1291,8 @@ static VALUE get_name(VALUE self)
|
|
1251
1291
|
*
|
1252
1292
|
* Returns the path associated with this Node
|
1253
1293
|
*/
|
1254
|
-
static VALUE
|
1294
|
+
static VALUE
|
1295
|
+
path(VALUE self)
|
1255
1296
|
{
|
1256
1297
|
xmlNodePtr node;
|
1257
1298
|
xmlChar *path ;
|
@@ -1266,13 +1307,15 @@ static VALUE path(VALUE self)
|
|
1266
1307
|
}
|
1267
1308
|
|
1268
1309
|
/* :nodoc: */
|
1269
|
-
static VALUE
|
1310
|
+
static VALUE
|
1311
|
+
add_next_sibling(VALUE self, VALUE new_sibling)
|
1270
1312
|
{
|
1271
1313
|
return reparent_node_with(self, new_sibling, xmlAddNextSibling) ;
|
1272
1314
|
}
|
1273
1315
|
|
1274
1316
|
/* :nodoc: */
|
1275
|
-
static VALUE
|
1317
|
+
static VALUE
|
1318
|
+
add_previous_sibling(VALUE self, VALUE new_sibling)
|
1276
1319
|
{
|
1277
1320
|
return reparent_node_with(self, new_sibling, xmlAddPrevSibling) ;
|
1278
1321
|
}
|
@@ -1283,7 +1326,8 @@ static VALUE add_previous_sibling(VALUE self, VALUE new_sibling)
|
|
1283
1326
|
*
|
1284
1327
|
* Write this Node to +io+ with +encoding+ and +options+
|
1285
1328
|
*/
|
1286
|
-
static VALUE
|
1329
|
+
static VALUE
|
1330
|
+
native_write_to(
|
1287
1331
|
VALUE self,
|
1288
1332
|
VALUE io,
|
1289
1333
|
VALUE encoding,
|
@@ -1292,7 +1336,7 @@ static VALUE native_write_to(
|
|
1292
1336
|
)
|
1293
1337
|
{
|
1294
1338
|
xmlNodePtr node;
|
1295
|
-
const char *
|
1339
|
+
const char *before_indent;
|
1296
1340
|
xmlSaveCtxtPtr savectx;
|
1297
1341
|
|
1298
1342
|
Data_Get_Struct(self, xmlNode, node);
|
@@ -1304,8 +1348,8 @@ static VALUE native_write_to(
|
|
1304
1348
|
xmlTreeIndentString = StringValueCStr(indent_string);
|
1305
1349
|
|
1306
1350
|
savectx = xmlSaveToIO(
|
1307
|
-
(xmlOutputWriteCallback)
|
1308
|
-
(xmlOutputCloseCallback)
|
1351
|
+
(xmlOutputWriteCallback)noko_io_write,
|
1352
|
+
(xmlOutputCloseCallback)noko_io_close,
|
1309
1353
|
(void *)io,
|
1310
1354
|
RTEST(encoding) ? StringValueCStr(encoding) : NULL,
|
1311
1355
|
(int)NUM2INT(options)
|
@@ -1324,7 +1368,8 @@ static VALUE native_write_to(
|
|
1324
1368
|
*
|
1325
1369
|
* Returns the line for this Node
|
1326
1370
|
*/
|
1327
|
-
static VALUE
|
1371
|
+
static VALUE
|
1372
|
+
line(VALUE self)
|
1328
1373
|
{
|
1329
1374
|
xmlNodePtr node;
|
1330
1375
|
Data_Get_Struct(self, xmlNode, node);
|
@@ -1338,12 +1383,13 @@ static VALUE line(VALUE self)
|
|
1338
1383
|
*
|
1339
1384
|
* Sets the line for this Node. num must be less than 65535.
|
1340
1385
|
*/
|
1341
|
-
static VALUE
|
1386
|
+
static VALUE
|
1387
|
+
set_line(VALUE self, VALUE num)
|
1342
1388
|
{
|
1343
1389
|
xmlNodePtr node;
|
1344
|
-
Data_Get_Struct(self, xmlNode, node);
|
1345
|
-
|
1346
1390
|
int value = NUM2INT(num);
|
1391
|
+
|
1392
|
+
Data_Get_Struct(self, xmlNode, node);
|
1347
1393
|
if (value < 65535) {
|
1348
1394
|
node->line = value;
|
1349
1395
|
}
|
@@ -1362,45 +1408,46 @@ static VALUE set_line(VALUE self, VALUE num)
|
|
1362
1408
|
* show up in #attributes, but they will be included as an xmlns attribute
|
1363
1409
|
* when the node is serialized to XML.
|
1364
1410
|
*/
|
1365
|
-
static VALUE
|
1411
|
+
static VALUE
|
1412
|
+
add_namespace_definition(VALUE rb_node, VALUE rb_prefix, VALUE rb_href)
|
1366
1413
|
{
|
1367
|
-
xmlNodePtr
|
1368
|
-
xmlNsPtr
|
1414
|
+
xmlNodePtr c_node, element;
|
1415
|
+
xmlNsPtr c_namespace;
|
1416
|
+
const xmlChar *c_prefix = (const xmlChar *)(NIL_P(rb_prefix) ? NULL : StringValueCStr(rb_prefix));
|
1369
1417
|
|
1370
|
-
Data_Get_Struct(
|
1371
|
-
|
1418
|
+
Data_Get_Struct(rb_node, xmlNode, c_node);
|
1419
|
+
element = c_node ;
|
1372
1420
|
|
1373
|
-
|
1374
|
-
node->doc,
|
1375
|
-
node,
|
1376
|
-
(const xmlChar *)(NIL_P(prefix) ? NULL : StringValueCStr(prefix))
|
1377
|
-
);
|
1421
|
+
c_namespace = xmlSearchNs(c_node->doc, c_node, c_prefix);
|
1378
1422
|
|
1379
|
-
if(!
|
1380
|
-
if (
|
1381
|
-
|
1423
|
+
if (!c_namespace) {
|
1424
|
+
if (c_node->type != XML_ELEMENT_NODE) {
|
1425
|
+
element = c_node->parent;
|
1382
1426
|
}
|
1383
|
-
|
1384
|
-
namespace,
|
1385
|
-
(const xmlChar *)StringValueCStr(href),
|
1386
|
-
(const xmlChar *)(NIL_P(prefix) ? NULL : StringValueCStr(prefix))
|
1387
|
-
);
|
1427
|
+
c_namespace = xmlNewNs(element, (const xmlChar *)StringValueCStr(rb_href), c_prefix);
|
1388
1428
|
}
|
1389
1429
|
|
1390
|
-
if (!
|
1430
|
+
if (!c_namespace) {
|
1431
|
+
return Qnil ;
|
1432
|
+
}
|
1391
1433
|
|
1392
|
-
if(NIL_P(
|
1434
|
+
if (NIL_P(rb_prefix) || c_node != element) {
|
1435
|
+
xmlSetNs(c_node, c_namespace);
|
1436
|
+
}
|
1393
1437
|
|
1394
|
-
return
|
1438
|
+
return noko_xml_namespace_wrap(c_namespace, c_node->doc);
|
1395
1439
|
}
|
1396
1440
|
|
1397
1441
|
/*
|
1398
|
-
*
|
1399
|
-
* new
|
1400
|
-
*
|
1401
|
-
*
|
1442
|
+
* @overload new(name, document)
|
1443
|
+
* Create a new node with +name+ sharing GC lifecycle with +document+.
|
1444
|
+
* @param name [String]
|
1445
|
+
* @param document [Nokogiri::XML::Document]
|
1446
|
+
* @return [Nokogiri::XML::Node]
|
1447
|
+
* @see Nokogiri::XML::Node#initialize
|
1402
1448
|
*/
|
1403
|
-
static VALUE
|
1449
|
+
static VALUE
|
1450
|
+
rb_xml_node_new(int argc, VALUE *argv, VALUE klass)
|
1404
1451
|
{
|
1405
1452
|
xmlDocPtr doc;
|
1406
1453
|
xmlNodePtr node;
|
@@ -1415,15 +1462,15 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
|
|
1415
1462
|
|
1416
1463
|
node = xmlNewNode(NULL, (xmlChar *)StringValueCStr(name));
|
1417
1464
|
node->doc = doc->doc;
|
1418
|
-
|
1465
|
+
noko_xml_document_pin_node(node);
|
1419
1466
|
|
1420
|
-
rb_node =
|
1467
|
+
rb_node = noko_xml_node_wrap(
|
1421
1468
|
klass == cNokogiriXmlNode ? (VALUE)NULL : klass,
|
1422
1469
|
node
|
1423
1470
|
);
|
1424
1471
|
rb_obj_call_init(rb_node, argc, argv);
|
1425
1472
|
|
1426
|
-
if(rb_block_given_p()) { rb_yield(rb_node); }
|
1473
|
+
if (rb_block_given_p()) { rb_yield(rb_node); }
|
1427
1474
|
|
1428
1475
|
return rb_node;
|
1429
1476
|
}
|
@@ -1434,7 +1481,8 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
|
|
1434
1481
|
*
|
1435
1482
|
* Returns the Node as html.
|
1436
1483
|
*/
|
1437
|
-
static VALUE
|
1484
|
+
static VALUE
|
1485
|
+
dump_html(VALUE self)
|
1438
1486
|
{
|
1439
1487
|
xmlBufferPtr buf ;
|
1440
1488
|
xmlNodePtr node ;
|
@@ -1455,7 +1503,8 @@ static VALUE dump_html(VALUE self)
|
|
1455
1503
|
*
|
1456
1504
|
* Compare this Node to +other+ with respect to their Document
|
1457
1505
|
*/
|
1458
|
-
static VALUE
|
1506
|
+
static VALUE
|
1507
|
+
compare(VALUE self, VALUE _other)
|
1459
1508
|
{
|
1460
1509
|
xmlNodePtr node, other;
|
1461
1510
|
Data_Get_Struct(self, xmlNode, node);
|
@@ -1472,7 +1521,8 @@ static VALUE compare(VALUE self, VALUE _other)
|
|
1472
1521
|
* Loads and substitutes all xinclude elements below the node. The
|
1473
1522
|
* parser context will be initialized with +options+.
|
1474
1523
|
*/
|
1475
|
-
static VALUE
|
1524
|
+
static VALUE
|
1525
|
+
process_xincludes(VALUE self, VALUE options)
|
1476
1526
|
{
|
1477
1527
|
int rcode ;
|
1478
1528
|
xmlNodePtr node;
|
@@ -1488,7 +1538,7 @@ static VALUE process_xincludes(VALUE self, VALUE options)
|
|
1488
1538
|
xmlErrorPtr error;
|
1489
1539
|
|
1490
1540
|
error = xmlGetLastError();
|
1491
|
-
if(error) {
|
1541
|
+
if (error) {
|
1492
1542
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
1493
1543
|
} else {
|
1494
1544
|
rb_raise(rb_eRuntimeError, "Could not perform xinclude substitution");
|
@@ -1500,7 +1550,8 @@ static VALUE process_xincludes(VALUE self, VALUE options)
|
|
1500
1550
|
|
1501
1551
|
|
1502
1552
|
/* TODO: DOCUMENT ME */
|
1503
|
-
static VALUE
|
1553
|
+
static VALUE
|
1554
|
+
in_context(VALUE self, VALUE _str, VALUE _options)
|
1504
1555
|
{
|
1505
1556
|
xmlNodePtr node, list = 0, tmp, child_iter, node_children, doc_children;
|
1506
1557
|
xmlNodeSetPtr set;
|
@@ -1595,15 +1646,16 @@ static VALUE in_context(VALUE self, VALUE _str, VALUE _options)
|
|
1595
1646
|
tmp = list->next;
|
1596
1647
|
list->next = NULL;
|
1597
1648
|
xmlXPathNodeSetAddUnique(set, list);
|
1598
|
-
|
1649
|
+
noko_xml_document_pin_node(list);
|
1599
1650
|
list = tmp;
|
1600
1651
|
}
|
1601
1652
|
|
1602
|
-
return
|
1653
|
+
return noko_xml_node_set_wrap(set, doc);
|
1603
1654
|
}
|
1604
1655
|
|
1605
1656
|
|
1606
|
-
VALUE
|
1657
|
+
VALUE
|
1658
|
+
noko_xml_node_wrap(VALUE klass, xmlNodePtr node)
|
1607
1659
|
{
|
1608
1660
|
VALUE document = Qnil ;
|
1609
1661
|
VALUE node_cache = Qnil ;
|
@@ -1614,7 +1666,7 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
|
|
1614
1666
|
|
1615
1667
|
assert(node);
|
1616
1668
|
|
1617
|
-
if(node->type == XML_DOCUMENT_NODE || node->type == XML_HTML_DOCUMENT_NODE) {
|
1669
|
+
if (node->type == XML_DOCUMENT_NODE || node->type == XML_HTML_DOCUMENT_NODE) {
|
1618
1670
|
return DOC_RUBY_OBJECT(node->doc);
|
1619
1671
|
}
|
1620
1672
|
|
@@ -1625,12 +1677,12 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
|
|
1625
1677
|
if (doc->type == XML_DOCUMENT_FRAG_NODE) { doc = doc->doc; }
|
1626
1678
|
node_has_a_document = DOC_RUBY_OBJECT_TEST(doc);
|
1627
1679
|
|
1628
|
-
if(node->_private && node_has_a_document) {
|
1680
|
+
if (node->_private && node_has_a_document) {
|
1629
1681
|
return (VALUE)node->_private;
|
1630
1682
|
}
|
1631
1683
|
|
1632
|
-
if(!RTEST(klass)) {
|
1633
|
-
switch(node->type) {
|
1684
|
+
if (!RTEST(klass)) {
|
1685
|
+
switch (node->type) {
|
1634
1686
|
case XML_ELEMENT_NODE:
|
1635
1687
|
klass = cNokogiriXmlElement;
|
1636
1688
|
break;
|
@@ -1688,83 +1740,83 @@ VALUE Nokogiri_wrap_xml_node(VALUE klass, xmlNodePtr node)
|
|
1688
1740
|
}
|
1689
1741
|
|
1690
1742
|
|
1691
|
-
|
1743
|
+
/*
|
1744
|
+
* return Array<Nokogiri::XML::Attr> containing the node's attributes
|
1745
|
+
*/
|
1746
|
+
VALUE
|
1747
|
+
noko_xml_node_attrs(xmlNodePtr c_node)
|
1692
1748
|
{
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1749
|
+
VALUE rb_properties = rb_ary_new();
|
1750
|
+
xmlAttrPtr c_property;
|
1751
|
+
|
1752
|
+
c_property = c_node->properties ;
|
1753
|
+
while (c_property != NULL) {
|
1754
|
+
rb_ary_push(rb_properties, noko_xml_node_wrap(Qnil, (xmlNodePtr)c_property));
|
1755
|
+
c_property = c_property->next ;
|
1698
1756
|
}
|
1699
|
-
}
|
1700
1757
|
|
1701
|
-
|
1702
|
-
|
1758
|
+
return rb_properties;
|
1759
|
+
}
|
1703
1760
|
|
1704
|
-
void
|
1761
|
+
void
|
1762
|
+
noko_init_xml_node()
|
1705
1763
|
{
|
1706
|
-
|
1707
|
-
|
1708
|
-
|
1709
|
-
|
1710
|
-
cNokogiriXmlNode
|
1711
|
-
|
1712
|
-
|
1713
|
-
|
1714
|
-
|
1715
|
-
|
1716
|
-
rb_define_method(
|
1717
|
-
rb_define_method(
|
1718
|
-
rb_define_method(
|
1719
|
-
rb_define_method(
|
1720
|
-
rb_define_method(
|
1721
|
-
rb_define_method(
|
1722
|
-
rb_define_method(
|
1723
|
-
rb_define_method(
|
1724
|
-
rb_define_method(
|
1725
|
-
rb_define_method(
|
1726
|
-
rb_define_method(
|
1727
|
-
rb_define_method(
|
1728
|
-
rb_define_method(
|
1729
|
-
rb_define_method(
|
1730
|
-
rb_define_method(
|
1731
|
-
rb_define_method(
|
1732
|
-
rb_define_method(
|
1733
|
-
rb_define_method(
|
1734
|
-
rb_define_method(
|
1735
|
-
rb_define_method(
|
1736
|
-
rb_define_method(
|
1737
|
-
rb_define_method(
|
1738
|
-
rb_define_method(
|
1739
|
-
rb_define_method(
|
1740
|
-
rb_define_method(
|
1741
|
-
rb_define_method(
|
1742
|
-
rb_define_method(
|
1743
|
-
rb_define_method(
|
1744
|
-
rb_define_method(
|
1745
|
-
rb_define_method(
|
1746
|
-
rb_define_method(
|
1747
|
-
rb_define_method(
|
1748
|
-
rb_define_method(
|
1749
|
-
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1755
|
-
|
1756
|
-
rb_define_private_method(
|
1757
|
-
rb_define_private_method(
|
1758
|
-
rb_define_private_method(
|
1759
|
-
rb_define_private_method(
|
1760
|
-
rb_define_private_method(
|
1761
|
-
rb_define_private_method(
|
1762
|
-
rb_define_private_method(klass, "dump_html", dump_html, 0);
|
1763
|
-
rb_define_private_method(klass, "native_write_to", native_write_to, 4);
|
1764
|
-
rb_define_private_method(klass, "get", get, 1);
|
1765
|
-
rb_define_private_method(klass, "set", set, 2);
|
1766
|
-
rb_define_private_method(klass, "set_namespace", set_namespace, 1);
|
1767
|
-
rb_define_private_method(klass, "compare", compare, 1);
|
1764
|
+
cNokogiriXmlNode = rb_define_class_under(mNokogiriXml, "Node", rb_cObject);
|
1765
|
+
|
1766
|
+
rb_define_singleton_method(cNokogiriXmlNode, "new", rb_xml_node_new, -1);
|
1767
|
+
|
1768
|
+
rb_define_method(cNokogiriXmlNode, "add_namespace_definition", add_namespace_definition, 2);
|
1769
|
+
rb_define_method(cNokogiriXmlNode, "node_name", get_name, 0);
|
1770
|
+
rb_define_method(cNokogiriXmlNode, "document", document, 0);
|
1771
|
+
rb_define_method(cNokogiriXmlNode, "node_name=", set_name, 1);
|
1772
|
+
rb_define_method(cNokogiriXmlNode, "parent", get_parent, 0);
|
1773
|
+
rb_define_method(cNokogiriXmlNode, "child", child, 0);
|
1774
|
+
rb_define_method(cNokogiriXmlNode, "first_element_child", first_element_child, 0);
|
1775
|
+
rb_define_method(cNokogiriXmlNode, "last_element_child", last_element_child, 0);
|
1776
|
+
rb_define_method(cNokogiriXmlNode, "children", children, 0);
|
1777
|
+
rb_define_method(cNokogiriXmlNode, "element_children", element_children, 0);
|
1778
|
+
rb_define_method(cNokogiriXmlNode, "next_sibling", next_sibling, 0);
|
1779
|
+
rb_define_method(cNokogiriXmlNode, "previous_sibling", previous_sibling, 0);
|
1780
|
+
rb_define_method(cNokogiriXmlNode, "next_element", next_element, 0);
|
1781
|
+
rb_define_method(cNokogiriXmlNode, "previous_element", previous_element, 0);
|
1782
|
+
rb_define_method(cNokogiriXmlNode, "node_type", node_type, 0);
|
1783
|
+
rb_define_method(cNokogiriXmlNode, "path", path, 0);
|
1784
|
+
rb_define_method(cNokogiriXmlNode, "key?", key_eh, 1);
|
1785
|
+
rb_define_method(cNokogiriXmlNode, "namespaced_key?", namespaced_key_eh, 2);
|
1786
|
+
rb_define_method(cNokogiriXmlNode, "blank?", blank_eh, 0);
|
1787
|
+
rb_define_method(cNokogiriXmlNode, "attribute_nodes", attribute_nodes, 0);
|
1788
|
+
rb_define_method(cNokogiriXmlNode, "attribute", attr, 1);
|
1789
|
+
rb_define_method(cNokogiriXmlNode, "attribute_with_ns", attribute_with_ns, 2);
|
1790
|
+
rb_define_method(cNokogiriXmlNode, "namespace", noko_xml_node_namespace, 0);
|
1791
|
+
rb_define_method(cNokogiriXmlNode, "namespace_definitions", namespace_definitions, 0);
|
1792
|
+
rb_define_method(cNokogiriXmlNode, "namespace_scopes", namespace_scopes, 0);
|
1793
|
+
rb_define_method(cNokogiriXmlNode, "encode_special_chars", encode_special_chars, 1);
|
1794
|
+
rb_define_method(cNokogiriXmlNode, "dup", duplicate_node, -1);
|
1795
|
+
rb_define_method(cNokogiriXmlNode, "unlink", unlink_node, 0);
|
1796
|
+
rb_define_method(cNokogiriXmlNode, "internal_subset", internal_subset, 0);
|
1797
|
+
rb_define_method(cNokogiriXmlNode, "external_subset", external_subset, 0);
|
1798
|
+
rb_define_method(cNokogiriXmlNode, "create_internal_subset", create_internal_subset, 3);
|
1799
|
+
rb_define_method(cNokogiriXmlNode, "create_external_subset", create_external_subset, 3);
|
1800
|
+
rb_define_method(cNokogiriXmlNode, "pointer_id", pointer_id, 0);
|
1801
|
+
rb_define_method(cNokogiriXmlNode, "line", line, 0);
|
1802
|
+
rb_define_method(cNokogiriXmlNode, "line=", set_line, 1);
|
1803
|
+
rb_define_method(cNokogiriXmlNode, "content", get_native_content, 0);
|
1804
|
+
rb_define_method(cNokogiriXmlNode, "native_content=", set_native_content, 1);
|
1805
|
+
rb_define_method(cNokogiriXmlNode, "lang", get_lang, 0);
|
1806
|
+
rb_define_method(cNokogiriXmlNode, "lang=", set_lang, 1);
|
1807
|
+
|
1808
|
+
rb_define_private_method(cNokogiriXmlNode, "process_xincludes", process_xincludes, 1);
|
1809
|
+
rb_define_private_method(cNokogiriXmlNode, "in_context", in_context, 2);
|
1810
|
+
rb_define_private_method(cNokogiriXmlNode, "add_child_node", add_child, 1);
|
1811
|
+
rb_define_private_method(cNokogiriXmlNode, "add_previous_sibling_node", add_previous_sibling, 1);
|
1812
|
+
rb_define_private_method(cNokogiriXmlNode, "add_next_sibling_node", add_next_sibling, 1);
|
1813
|
+
rb_define_private_method(cNokogiriXmlNode, "replace_node", replace, 1);
|
1814
|
+
rb_define_private_method(cNokogiriXmlNode, "dump_html", dump_html, 0);
|
1815
|
+
rb_define_private_method(cNokogiriXmlNode, "native_write_to", native_write_to, 4);
|
1816
|
+
rb_define_private_method(cNokogiriXmlNode, "get", get, 1);
|
1817
|
+
rb_define_private_method(cNokogiriXmlNode, "set", set, 2);
|
1818
|
+
rb_define_private_method(cNokogiriXmlNode, "set_namespace", set_namespace, 1);
|
1819
|
+
rb_define_private_method(cNokogiriXmlNode, "compare", compare, 1);
|
1768
1820
|
|
1769
1821
|
decorate = rb_intern("decorate");
|
1770
1822
|
decorate_bang = rb_intern("decorate!");
|