nokogiri 1.11.0.rc2-java → 1.11.3-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/LICENSE-DEPENDENCIES.md +1015 -947
- data/LICENSE.md +1 -1
- data/README.md +171 -94
- data/ext/java/nokogiri/EncodingHandler.java +76 -89
- data/ext/java/nokogiri/HtmlDocument.java +135 -144
- data/ext/java/nokogiri/HtmlElementDescription.java +102 -117
- data/ext/java/nokogiri/HtmlEntityLookup.java +33 -60
- data/ext/java/nokogiri/HtmlSaxParserContext.java +218 -222
- data/ext/java/nokogiri/HtmlSaxPushParser.java +162 -169
- data/ext/java/nokogiri/NokogiriService.java +595 -556
- data/ext/java/nokogiri/XmlAttr.java +118 -126
- data/ext/java/nokogiri/XmlAttributeDecl.java +95 -106
- data/ext/java/nokogiri/XmlCdata.java +35 -58
- data/ext/java/nokogiri/XmlComment.java +46 -67
- data/ext/java/nokogiri/XmlDocument.java +645 -572
- data/ext/java/nokogiri/XmlDocumentFragment.java +125 -137
- data/ext/java/nokogiri/XmlDtd.java +448 -414
- data/ext/java/nokogiri/XmlElement.java +23 -48
- data/ext/java/nokogiri/XmlElementContent.java +343 -316
- data/ext/java/nokogiri/XmlElementDecl.java +124 -125
- data/ext/java/nokogiri/XmlEntityDecl.java +119 -127
- data/ext/java/nokogiri/XmlEntityReference.java +49 -72
- data/ext/java/nokogiri/XmlNamespace.java +175 -175
- data/ext/java/nokogiri/XmlNode.java +1843 -1622
- data/ext/java/nokogiri/XmlNodeSet.java +361 -331
- data/ext/java/nokogiri/XmlProcessingInstruction.java +47 -69
- data/ext/java/nokogiri/XmlReader.java +513 -450
- data/ext/java/nokogiri/XmlRelaxng.java +89 -101
- data/ext/java/nokogiri/XmlSaxParserContext.java +328 -310
- data/ext/java/nokogiri/XmlSaxPushParser.java +227 -220
- data/ext/java/nokogiri/XmlSchema.java +335 -242
- data/ext/java/nokogiri/XmlSyntaxError.java +113 -119
- data/ext/java/nokogiri/XmlText.java +55 -76
- data/ext/java/nokogiri/XmlXpathContext.java +242 -210
- data/ext/java/nokogiri/XsltStylesheet.java +280 -269
- data/ext/java/nokogiri/internals/ClosedStreamException.java +5 -2
- data/ext/java/nokogiri/internals/HtmlDomParserContext.java +201 -190
- data/ext/java/nokogiri/internals/IgnoreSchemaErrorsErrorHandler.java +17 -10
- data/ext/java/nokogiri/internals/NokogiriBlockingQueueInputStream.java +43 -16
- data/ext/java/nokogiri/internals/NokogiriDomParser.java +63 -80
- data/ext/java/nokogiri/internals/NokogiriEntityResolver.java +107 -88
- data/ext/java/nokogiri/internals/NokogiriErrorHandler.java +27 -52
- data/ext/java/nokogiri/internals/NokogiriHandler.java +316 -286
- data/ext/java/nokogiri/internals/NokogiriHelpers.java +736 -652
- data/ext/java/nokogiri/internals/NokogiriNamespaceCache.java +184 -173
- data/ext/java/nokogiri/internals/NokogiriNamespaceContext.java +79 -89
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler.java +64 -79
- data/ext/java/nokogiri/internals/NokogiriNonStrictErrorHandler4NekoHtml.java +84 -99
- data/ext/java/nokogiri/internals/NokogiriStrictErrorHandler.java +48 -65
- data/ext/java/nokogiri/internals/NokogiriXPathFunction.java +119 -78
- data/ext/java/nokogiri/internals/NokogiriXPathFunctionResolver.java +34 -54
- data/ext/java/nokogiri/internals/NokogiriXPathVariableResolver.java +23 -46
- data/ext/java/nokogiri/internals/NokogiriXsltErrorListener.java +55 -72
- data/ext/java/nokogiri/internals/ParserContext.java +206 -211
- data/ext/java/nokogiri/internals/ReaderNode.java +478 -403
- data/ext/java/nokogiri/internals/SaveContextVisitor.java +822 -739
- data/ext/java/nokogiri/internals/SchemaErrorHandler.java +31 -54
- data/ext/java/nokogiri/internals/XalanDTMManagerPatch.java +129 -123
- data/ext/java/nokogiri/internals/XmlDeclHandler.java +3 -34
- data/ext/java/nokogiri/internals/XmlDomParserContext.java +206 -207
- data/ext/java/nokogiri/internals/XmlSaxParser.java +22 -47
- data/ext/java/nokogiri/internals/c14n/AttrCompare.java +71 -68
- data/ext/java/nokogiri/internals/c14n/C14nHelper.java +137 -118
- data/ext/java/nokogiri/internals/c14n/CanonicalFilter.java +27 -21
- data/ext/java/nokogiri/internals/c14n/CanonicalizationException.java +74 -61
- data/ext/java/nokogiri/internals/c14n/Canonicalizer.java +230 -205
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11.java +572 -547
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_OmitComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer11_WithComments.java +17 -10
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315.java +323 -302
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315Excl.java +232 -219
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclOmitComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315ExclWithComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315OmitComments.java +23 -16
- data/ext/java/nokogiri/internals/c14n/Canonicalizer20010315WithComments.java +22 -15
- data/ext/java/nokogiri/internals/c14n/CanonicalizerBase.java +575 -545
- data/ext/java/nokogiri/internals/c14n/CanonicalizerPhysical.java +141 -120
- data/ext/java/nokogiri/internals/c14n/CanonicalizerSpi.java +39 -38
- data/ext/java/nokogiri/internals/c14n/Constants.java +13 -10
- data/ext/java/nokogiri/internals/c14n/ElementProxy.java +279 -247
- data/ext/java/nokogiri/internals/c14n/HelperNodeList.java +66 -53
- data/ext/java/nokogiri/internals/c14n/IgnoreAllErrorHandler.java +44 -37
- data/ext/java/nokogiri/internals/c14n/InclusiveNamespaces.java +135 -120
- data/ext/java/nokogiri/internals/c14n/InvalidCanonicalizerException.java +59 -48
- data/ext/java/nokogiri/internals/c14n/NameSpaceSymbTable.java +384 -334
- data/ext/java/nokogiri/internals/c14n/NodeFilter.java +25 -24
- data/ext/java/nokogiri/internals/c14n/UtfHelpper.java +151 -140
- data/ext/java/nokogiri/internals/c14n/XMLUtils.java +456 -423
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTM.java +1466 -1500
- data/ext/java/nokogiri/internals/dom2dtm/DOM2DTMdefaultNamespaceDeclarationNode.java +626 -574
- data/ext/nokogiri/depend +37 -358
- data/ext/nokogiri/extconf.rb +581 -374
- data/ext/nokogiri/html_document.c +78 -82
- 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 +69 -66
- data/ext/nokogiri/html_sax_push_parser.c +42 -34
- data/ext/nokogiri/libxml2_backwards_compat.c +121 -0
- data/ext/nokogiri/nokogiri.c +192 -93
- data/ext/nokogiri/test_global_handlers.c +40 -0
- 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 +250 -187
- 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 +371 -320
- 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 +52 -28
- data/ext/nokogiri/xml_sax_parser.c +118 -118
- data/ext/nokogiri/xml_sax_parser_context.c +103 -86
- data/ext/nokogiri/xml_sax_push_parser.c +36 -27
- data/ext/nokogiri/xml_schema.c +95 -47
- data/ext/nokogiri/xml_syntax_error.c +42 -21
- data/ext/nokogiri/xml_text.c +13 -17
- data/ext/nokogiri/xml_xpath_context.c +206 -123
- data/ext/nokogiri/xslt_stylesheet.c +158 -161
- data/lib/nokogiri.rb +4 -8
- data/lib/nokogiri/css/parser.rb +62 -62
- data/lib/nokogiri/css/parser.y +2 -2
- data/lib/nokogiri/css/xpath_visitor.rb +70 -42
- data/lib/nokogiri/extension.rb +26 -0
- data/lib/nokogiri/html/document.rb +12 -26
- data/lib/nokogiri/html/document_fragment.rb +15 -15
- data/lib/nokogiri/nokogiri.jar +0 -0
- data/lib/nokogiri/version.rb +2 -148
- data/lib/nokogiri/version/constant.rb +5 -0
- data/lib/nokogiri/version/info.rb +205 -0
- data/lib/nokogiri/xml/builder.rb +2 -2
- data/lib/nokogiri/xml/document.rb +91 -35
- data/lib/nokogiri/xml/document_fragment.rb +4 -6
- data/lib/nokogiri/xml/node.rb +89 -69
- data/lib/nokogiri/xml/parse_options.rb +6 -0
- data/lib/nokogiri/xml/reader.rb +2 -9
- data/lib/nokogiri/xml/relax_ng.rb +6 -2
- data/lib/nokogiri/xml/schema.rb +12 -4
- data/lib/nokogiri/xml/searchable.rb +3 -1
- data/lib/nokogiri/xml/xpath.rb +1 -3
- data/lib/nokogiri/xml/xpath/syntax_error.rb +1 -1
- metadata +87 -164
- 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/nokogiri.h +0 -134
- 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 -61
- 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 -13
- 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
data/ext/nokogiri/xml_cdata.c
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
#include <
|
|
1
|
+
#include <nokogiri.h>
|
|
2
|
+
|
|
3
|
+
VALUE cNokogiriXmlCData;
|
|
2
4
|
|
|
3
5
|
/*
|
|
4
6
|
* call-seq:
|
|
@@ -9,7 +11,8 @@
|
|
|
9
11
|
* If +content+ cannot be implicitly converted to a string, this method will
|
|
10
12
|
* raise a TypeError exception.
|
|
11
13
|
*/
|
|
12
|
-
static VALUE
|
|
14
|
+
static VALUE
|
|
15
|
+
new (int argc, VALUE *argv, VALUE klass)
|
|
13
16
|
{
|
|
14
17
|
xmlDocPtr xml_doc;
|
|
15
18
|
xmlNodePtr node;
|
|
@@ -31,32 +34,24 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
|
|
|
31
34
|
|
|
32
35
|
node = xmlNewCDataBlock(xml_doc->doc, content_str, content_str_len);
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
noko_xml_document_pin_node(node);
|
|
35
38
|
|
|
36
|
-
rb_node =
|
|
39
|
+
rb_node = noko_xml_node_wrap(klass, node);
|
|
37
40
|
rb_obj_call_init(rb_node, argc, argv);
|
|
38
41
|
|
|
39
|
-
if(rb_block_given_p()) { rb_yield(rb_node); }
|
|
42
|
+
if (rb_block_given_p()) { rb_yield(rb_node); }
|
|
40
43
|
|
|
41
44
|
return rb_node;
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
void
|
|
48
|
+
noko_init_xml_cdata()
|
|
46
49
|
{
|
|
47
|
-
|
|
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
|
-
|
|
50
|
+
assert(cNokogiriXmlText);
|
|
53
51
|
/*
|
|
54
52
|
* CData represents a CData node in an xml document.
|
|
55
53
|
*/
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
cNokogiriXmlCData = klass;
|
|
54
|
+
cNokogiriXmlCData = rb_define_class_under(mNokogiriXml, "CDATA", cNokogiriXmlText);
|
|
60
55
|
|
|
61
|
-
rb_define_singleton_method(
|
|
56
|
+
rb_define_singleton_method(cNokogiriXmlCData, "new", new, -1);
|
|
62
57
|
}
|
data/ext/nokogiri/xml_comment.c
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
#include <
|
|
1
|
+
#include <nokogiri.h>
|
|
2
|
+
|
|
3
|
+
VALUE cNokogiriXmlComment;
|
|
2
4
|
|
|
3
5
|
static ID document_id ;
|
|
4
6
|
|
|
@@ -9,7 +11,8 @@ static ID document_id ;
|
|
|
9
11
|
* Create a new Comment element on the +document+ with +content+.
|
|
10
12
|
* Alternatively, if a +node+ is passed, the +node+'s document is used.
|
|
11
13
|
*/
|
|
12
|
-
static VALUE
|
|
14
|
+
static VALUE
|
|
15
|
+
new (int argc, VALUE *argv, VALUE klass)
|
|
13
16
|
{
|
|
14
17
|
xmlDocPtr xml_doc;
|
|
15
18
|
xmlNodePtr node;
|
|
@@ -20,50 +23,40 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
|
|
|
20
23
|
|
|
21
24
|
rb_scan_args(argc, argv, "2*", &document, &content, &rest);
|
|
22
25
|
|
|
23
|
-
if (rb_obj_is_kind_of(document, cNokogiriXmlNode))
|
|
24
|
-
{
|
|
26
|
+
if (rb_obj_is_kind_of(document, cNokogiriXmlNode)) {
|
|
25
27
|
document = rb_funcall(document, document_id, 0);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
&& !rb_obj_is_kind_of(document, cNokogiriXmlDocumentFragment))
|
|
29
|
-
{
|
|
28
|
+
} else if (!rb_obj_is_kind_of(document, cNokogiriXmlDocument)
|
|
29
|
+
&& !rb_obj_is_kind_of(document, cNokogiriXmlDocumentFragment)) {
|
|
30
30
|
rb_raise(rb_eArgError, "first argument must be a XML::Document or XML::Node");
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
Data_Get_Struct(document, xmlDoc, xml_doc);
|
|
34
34
|
|
|
35
35
|
node = xmlNewDocComment(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
xml_doc,
|
|
37
|
+
(const xmlChar *)StringValueCStr(content)
|
|
38
|
+
);
|
|
39
39
|
|
|
40
|
-
rb_node =
|
|
40
|
+
rb_node = noko_xml_node_wrap(klass, node);
|
|
41
41
|
rb_obj_call_init(rb_node, argc, argv);
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
noko_xml_document_pin_node(node);
|
|
44
44
|
|
|
45
|
-
if(rb_block_given_p()) rb_yield(rb_node);
|
|
45
|
+
if (rb_block_given_p()) { rb_yield(rb_node); }
|
|
46
46
|
|
|
47
47
|
return rb_node;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
void
|
|
51
|
+
noko_init_xml_comment()
|
|
52
52
|
{
|
|
53
|
-
|
|
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
|
-
|
|
53
|
+
assert(cNokogiriXmlCharacterData);
|
|
58
54
|
/*
|
|
59
55
|
* Comment represents a comment node in an xml document.
|
|
60
56
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
cNokogiriXmlComment = klass;
|
|
57
|
+
cNokogiriXmlComment = rb_define_class_under(mNokogiriXml, "Comment", cNokogiriXmlCharacterData);
|
|
65
58
|
|
|
66
|
-
rb_define_singleton_method(
|
|
59
|
+
rb_define_singleton_method(cNokogiriXmlComment, "new", new, -1);
|
|
67
60
|
|
|
68
61
|
document_id = rb_intern("document");
|
|
69
62
|
}
|
data/ext/nokogiri/xml_document.c
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
#include <
|
|
1
|
+
#include <nokogiri.h>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
VALUE cNokogiriXmlDocument ;
|
|
4
|
+
|
|
5
|
+
static int
|
|
6
|
+
dealloc_node_i2(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
|
|
4
7
|
{
|
|
5
|
-
switch(node->type) {
|
|
8
|
+
switch (node->type) {
|
|
6
9
|
case XML_ATTRIBUTE_NODE:
|
|
7
10
|
xmlFreePropList((xmlAttrPtr)node);
|
|
8
11
|
break;
|
|
@@ -13,41 +16,52 @@ static int dealloc_node_i(xmlNodePtr key, xmlNodePtr node, xmlDocPtr doc)
|
|
|
13
16
|
xmlFreeDtd((xmlDtdPtr)node);
|
|
14
17
|
break;
|
|
15
18
|
default:
|
|
16
|
-
if(node->parent == NULL) {
|
|
19
|
+
if (node->parent == NULL) {
|
|
17
20
|
xmlAddChild((xmlNodePtr)doc, node);
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
return ST_CONTINUE;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
|
-
static
|
|
26
|
+
static int
|
|
27
|
+
dealloc_node_i(st_data_t key, st_data_t node, st_data_t doc)
|
|
28
|
+
{
|
|
29
|
+
return dealloc_node_i2((xmlNodePtr)key, (xmlNodePtr)node, (xmlDocPtr)doc);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static void
|
|
33
|
+
remove_private(xmlNodePtr node)
|
|
24
34
|
{
|
|
25
35
|
xmlNodePtr child;
|
|
26
36
|
|
|
27
|
-
for (child = node->children; child; child = child->next)
|
|
37
|
+
for (child = node->children; child; child = child->next) {
|
|
28
38
|
remove_private(child);
|
|
39
|
+
}
|
|
29
40
|
|
|
30
41
|
if ((node->type == XML_ELEMENT_NODE ||
|
|
31
42
|
node->type == XML_XINCLUDE_START ||
|
|
32
43
|
node->type == XML_XINCLUDE_END) &&
|
|
33
44
|
node->properties) {
|
|
34
|
-
for (child = (xmlNodePtr)node->properties; child; child = child->next)
|
|
45
|
+
for (child = (xmlNodePtr)node->properties; child; child = child->next) {
|
|
35
46
|
remove_private(child);
|
|
47
|
+
}
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
node->_private = NULL;
|
|
39
51
|
}
|
|
40
52
|
|
|
41
|
-
static void
|
|
53
|
+
static void
|
|
54
|
+
mark(xmlDocPtr doc)
|
|
42
55
|
{
|
|
43
56
|
nokogiriTuplePtr tuple = (nokogiriTuplePtr)doc->_private;
|
|
44
|
-
if(tuple) {
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
if (tuple) {
|
|
58
|
+
rb_gc_mark(tuple->doc);
|
|
59
|
+
rb_gc_mark(tuple->node_cache);
|
|
47
60
|
}
|
|
48
61
|
}
|
|
49
62
|
|
|
50
|
-
static void
|
|
63
|
+
static void
|
|
64
|
+
dealloc(xmlDocPtr doc)
|
|
51
65
|
{
|
|
52
66
|
st_table *node_hash;
|
|
53
67
|
|
|
@@ -65,23 +79,26 @@ static void dealloc(xmlDocPtr doc)
|
|
|
65
79
|
* xmlDeregisterNode callback from accessing VALUE pointers from ruby's GC
|
|
66
80
|
* free context, which can result in segfaults.
|
|
67
81
|
*/
|
|
68
|
-
if (xmlDeregisterNodeDefaultValue)
|
|
82
|
+
if (xmlDeregisterNodeDefaultValue) {
|
|
69
83
|
remove_private((xmlNodePtr)doc);
|
|
84
|
+
}
|
|
70
85
|
|
|
71
86
|
xmlFreeDoc(doc);
|
|
72
87
|
|
|
73
88
|
NOKOGIRI_DEBUG_END(doc);
|
|
74
89
|
}
|
|
75
90
|
|
|
76
|
-
static void
|
|
91
|
+
static void
|
|
92
|
+
recursively_remove_namespaces_from_node(xmlNodePtr node)
|
|
77
93
|
{
|
|
78
94
|
xmlNodePtr child ;
|
|
79
95
|
xmlAttrPtr property ;
|
|
80
96
|
|
|
81
97
|
xmlSetNs(node, NULL);
|
|
82
98
|
|
|
83
|
-
for (child = node->children ; child ; child = child->next)
|
|
99
|
+
for (child = node->children ; child ; child = child->next) {
|
|
84
100
|
recursively_remove_namespaces_from_node(child);
|
|
101
|
+
}
|
|
85
102
|
|
|
86
103
|
if (((node->type == XML_ELEMENT_NODE) ||
|
|
87
104
|
(node->type == XML_XINCLUDE_START) ||
|
|
@@ -94,7 +111,7 @@ static void recursively_remove_namespaces_from_node(xmlNodePtr node)
|
|
|
94
111
|
if (node->type == XML_ELEMENT_NODE && node->properties != NULL) {
|
|
95
112
|
property = node->properties ;
|
|
96
113
|
while (property != NULL) {
|
|
97
|
-
if (property->ns) property->ns = NULL ;
|
|
114
|
+
if (property->ns) { property->ns = NULL ; }
|
|
98
115
|
property = property->next ;
|
|
99
116
|
}
|
|
100
117
|
}
|
|
@@ -106,12 +123,13 @@ static void recursively_remove_namespaces_from_node(xmlNodePtr node)
|
|
|
106
123
|
*
|
|
107
124
|
* Get the url name for this document.
|
|
108
125
|
*/
|
|
109
|
-
static VALUE
|
|
126
|
+
static VALUE
|
|
127
|
+
url(VALUE self)
|
|
110
128
|
{
|
|
111
129
|
xmlDocPtr doc;
|
|
112
130
|
Data_Get_Struct(self, xmlDoc, doc);
|
|
113
131
|
|
|
114
|
-
if(doc->URL) return NOKOGIRI_STR_NEW2(doc->URL);
|
|
132
|
+
if (doc->URL) { return NOKOGIRI_STR_NEW2(doc->URL); }
|
|
115
133
|
|
|
116
134
|
return Qnil;
|
|
117
135
|
}
|
|
@@ -122,42 +140,42 @@ static VALUE url(VALUE self)
|
|
|
122
140
|
*
|
|
123
141
|
* Set the root element on this document
|
|
124
142
|
*/
|
|
125
|
-
static VALUE
|
|
143
|
+
static VALUE
|
|
144
|
+
rb_xml_document_root_set(VALUE self, VALUE rb_new_root)
|
|
126
145
|
{
|
|
127
|
-
xmlDocPtr
|
|
128
|
-
xmlNodePtr
|
|
129
|
-
xmlNodePtr old_root;
|
|
130
|
-
|
|
131
|
-
Data_Get_Struct(self, xmlDoc, doc);
|
|
146
|
+
xmlDocPtr c_document;
|
|
147
|
+
xmlNodePtr c_new_root = NULL, c_current_root;
|
|
132
148
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if(NIL_P(root)) {
|
|
136
|
-
old_root = xmlDocGetRootElement(doc);
|
|
137
|
-
|
|
138
|
-
if(old_root) {
|
|
139
|
-
xmlUnlinkNode(old_root);
|
|
140
|
-
nokogiri_root_node(old_root);
|
|
141
|
-
}
|
|
149
|
+
Data_Get_Struct(self, xmlDoc, c_document);
|
|
142
150
|
|
|
143
|
-
|
|
151
|
+
c_current_root = xmlDocGetRootElement(c_document);
|
|
152
|
+
if (c_current_root) {
|
|
153
|
+
xmlUnlinkNode(c_current_root);
|
|
154
|
+
noko_xml_document_pin_node(c_current_root);
|
|
144
155
|
}
|
|
145
156
|
|
|
146
|
-
|
|
157
|
+
if (!NIL_P(rb_new_root)) {
|
|
158
|
+
if (!rb_obj_is_kind_of(rb_new_root, cNokogiriXmlNode)) {
|
|
159
|
+
rb_raise(rb_eArgError,
|
|
160
|
+
"expected Nokogiri::XML::Node but received %"PRIsVALUE,
|
|
161
|
+
rb_obj_class(rb_new_root));
|
|
162
|
+
}
|
|
147
163
|
|
|
164
|
+
Data_Get_Struct(rb_new_root, xmlNode, c_new_root);
|
|
148
165
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
166
|
+
/* If the new root's document is not the same as the current document,
|
|
167
|
+
* then we need to dup the node in to this document. */
|
|
168
|
+
if (c_new_root->doc != c_document) {
|
|
169
|
+
c_new_root = xmlDocCopyNode(c_new_root, c_document, 1);
|
|
170
|
+
if (!c_new_root) {
|
|
171
|
+
rb_raise(rb_eRuntimeError, "Could not reparent node (xmlDocCopyNode)");
|
|
172
|
+
}
|
|
155
173
|
}
|
|
156
174
|
}
|
|
157
175
|
|
|
158
|
-
xmlDocSetRootElement(
|
|
159
|
-
|
|
160
|
-
return
|
|
176
|
+
xmlDocSetRootElement(c_document, c_new_root);
|
|
177
|
+
|
|
178
|
+
return rb_new_root;
|
|
161
179
|
}
|
|
162
180
|
|
|
163
181
|
/*
|
|
@@ -166,17 +184,20 @@ static VALUE set_root(VALUE self, VALUE root)
|
|
|
166
184
|
*
|
|
167
185
|
* Get the root node for this document.
|
|
168
186
|
*/
|
|
169
|
-
static VALUE
|
|
187
|
+
static VALUE
|
|
188
|
+
rb_xml_document_root(VALUE self)
|
|
170
189
|
{
|
|
171
|
-
xmlDocPtr
|
|
172
|
-
xmlNodePtr
|
|
190
|
+
xmlDocPtr c_document;
|
|
191
|
+
xmlNodePtr c_root;
|
|
173
192
|
|
|
174
|
-
Data_Get_Struct(self, xmlDoc,
|
|
193
|
+
Data_Get_Struct(self, xmlDoc, c_document);
|
|
175
194
|
|
|
176
|
-
|
|
195
|
+
c_root = xmlDocGetRootElement(c_document);
|
|
196
|
+
if (!c_root) {
|
|
197
|
+
return Qnil;
|
|
198
|
+
}
|
|
177
199
|
|
|
178
|
-
|
|
179
|
-
return Nokogiri_wrap_xml_node(Qnil, root) ;
|
|
200
|
+
return noko_xml_node_wrap(Qnil, c_root) ;
|
|
180
201
|
}
|
|
181
202
|
|
|
182
203
|
/*
|
|
@@ -185,13 +206,15 @@ static VALUE root(VALUE self)
|
|
|
185
206
|
*
|
|
186
207
|
* Set the encoding string for this Document
|
|
187
208
|
*/
|
|
188
|
-
static VALUE
|
|
209
|
+
static VALUE
|
|
210
|
+
set_encoding(VALUE self, VALUE encoding)
|
|
189
211
|
{
|
|
190
212
|
xmlDocPtr doc;
|
|
191
213
|
Data_Get_Struct(self, xmlDoc, doc);
|
|
192
214
|
|
|
193
|
-
if (doc->encoding)
|
|
194
|
-
|
|
215
|
+
if (doc->encoding) {
|
|
216
|
+
free((char *)(uintptr_t) doc->encoding); /* avoid gcc cast warning */
|
|
217
|
+
}
|
|
195
218
|
|
|
196
219
|
doc->encoding = xmlStrdup((xmlChar *)StringValueCStr(encoding));
|
|
197
220
|
|
|
@@ -204,12 +227,13 @@ static VALUE set_encoding(VALUE self, VALUE encoding)
|
|
|
204
227
|
*
|
|
205
228
|
* Get the encoding for this Document
|
|
206
229
|
*/
|
|
207
|
-
static VALUE
|
|
230
|
+
static VALUE
|
|
231
|
+
encoding(VALUE self)
|
|
208
232
|
{
|
|
209
233
|
xmlDocPtr doc;
|
|
210
234
|
Data_Get_Struct(self, xmlDoc, doc);
|
|
211
235
|
|
|
212
|
-
if(!doc->encoding) return Qnil;
|
|
236
|
+
if (!doc->encoding) { return Qnil; }
|
|
213
237
|
return NOKOGIRI_STR_NEW2(doc->encoding);
|
|
214
238
|
}
|
|
215
239
|
|
|
@@ -219,12 +243,13 @@ static VALUE encoding(VALUE self)
|
|
|
219
243
|
*
|
|
220
244
|
* Get the XML version for this Document
|
|
221
245
|
*/
|
|
222
|
-
static VALUE
|
|
246
|
+
static VALUE
|
|
247
|
+
version(VALUE self)
|
|
223
248
|
{
|
|
224
249
|
xmlDocPtr doc;
|
|
225
250
|
Data_Get_Struct(self, xmlDoc, doc);
|
|
226
251
|
|
|
227
|
-
if(!doc->version) return Qnil;
|
|
252
|
+
if (!doc->version) { return Qnil; }
|
|
228
253
|
return NOKOGIRI_STR_NEW2(doc->version);
|
|
229
254
|
}
|
|
230
255
|
|
|
@@ -234,14 +259,15 @@ static VALUE version(VALUE self)
|
|
|
234
259
|
*
|
|
235
260
|
* Create a new document from an IO object
|
|
236
261
|
*/
|
|
237
|
-
static VALUE
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
262
|
+
static VALUE
|
|
263
|
+
read_io(VALUE klass,
|
|
264
|
+
VALUE io,
|
|
265
|
+
VALUE url,
|
|
266
|
+
VALUE encoding,
|
|
267
|
+
VALUE options)
|
|
242
268
|
{
|
|
243
|
-
const char *
|
|
244
|
-
const char *
|
|
269
|
+
const char *c_url = NIL_P(url) ? NULL : StringValueCStr(url);
|
|
270
|
+
const char *c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
|
|
245
271
|
VALUE error_list = rb_ary_new();
|
|
246
272
|
VALUE document;
|
|
247
273
|
xmlDocPtr doc;
|
|
@@ -250,30 +276,31 @@ static VALUE read_io( VALUE klass,
|
|
|
250
276
|
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
|
251
277
|
|
|
252
278
|
doc = xmlReadIO(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
279
|
+
(xmlInputReadCallback)noko_io_read,
|
|
280
|
+
(xmlInputCloseCallback)noko_io_close,
|
|
281
|
+
(void *)io,
|
|
282
|
+
c_url,
|
|
283
|
+
c_enc,
|
|
284
|
+
(int)NUM2INT(options)
|
|
285
|
+
);
|
|
260
286
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
|
261
287
|
|
|
262
|
-
if(doc == NULL) {
|
|
288
|
+
if (doc == NULL) {
|
|
263
289
|
xmlErrorPtr error;
|
|
264
290
|
|
|
265
291
|
xmlFreeDoc(doc);
|
|
266
292
|
|
|
267
293
|
error = xmlGetLastError();
|
|
268
|
-
if(error)
|
|
294
|
+
if (error) {
|
|
269
295
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
|
270
|
-
else
|
|
296
|
+
} else {
|
|
271
297
|
rb_raise(rb_eRuntimeError, "Could not parse document");
|
|
298
|
+
}
|
|
272
299
|
|
|
273
300
|
return Qnil;
|
|
274
301
|
}
|
|
275
302
|
|
|
276
|
-
document =
|
|
303
|
+
document = noko_xml_document_wrap(klass, doc);
|
|
277
304
|
rb_iv_set(document, "@errors", error_list);
|
|
278
305
|
return document;
|
|
279
306
|
}
|
|
@@ -284,15 +311,16 @@ static VALUE read_io( VALUE klass,
|
|
|
284
311
|
*
|
|
285
312
|
* Create a new document from a String
|
|
286
313
|
*/
|
|
287
|
-
static VALUE
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
314
|
+
static VALUE
|
|
315
|
+
read_memory(VALUE klass,
|
|
316
|
+
VALUE string,
|
|
317
|
+
VALUE url,
|
|
318
|
+
VALUE encoding,
|
|
319
|
+
VALUE options)
|
|
292
320
|
{
|
|
293
|
-
const char *
|
|
294
|
-
const char *
|
|
295
|
-
const char *
|
|
321
|
+
const char *c_buffer = StringValuePtr(string);
|
|
322
|
+
const char *c_url = NIL_P(url) ? NULL : StringValueCStr(url);
|
|
323
|
+
const char *c_enc = NIL_P(encoding) ? NULL : StringValueCStr(encoding);
|
|
296
324
|
int len = (int)RSTRING_LEN(string);
|
|
297
325
|
VALUE error_list = rb_ary_new();
|
|
298
326
|
VALUE document;
|
|
@@ -303,21 +331,22 @@ static VALUE read_memory( VALUE klass,
|
|
|
303
331
|
doc = xmlReadMemory(c_buffer, len, c_url, c_enc, (int)NUM2INT(options));
|
|
304
332
|
xmlSetStructuredErrorFunc(NULL, NULL);
|
|
305
333
|
|
|
306
|
-
if(doc == NULL) {
|
|
334
|
+
if (doc == NULL) {
|
|
307
335
|
xmlErrorPtr error;
|
|
308
336
|
|
|
309
337
|
xmlFreeDoc(doc);
|
|
310
338
|
|
|
311
339
|
error = xmlGetLastError();
|
|
312
|
-
if(error)
|
|
340
|
+
if (error) {
|
|
313
341
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
|
314
|
-
else
|
|
342
|
+
} else {
|
|
315
343
|
rb_raise(rb_eRuntimeError, "Could not parse document");
|
|
344
|
+
}
|
|
316
345
|
|
|
317
346
|
return Qnil;
|
|
318
347
|
}
|
|
319
348
|
|
|
320
|
-
document =
|
|
349
|
+
document = noko_xml_document_wrap(klass, doc);
|
|
321
350
|
rb_iv_set(document, "@errors", error_list);
|
|
322
351
|
return document;
|
|
323
352
|
}
|
|
@@ -329,26 +358,26 @@ static VALUE read_memory( VALUE klass,
|
|
|
329
358
|
* Copy this Document. An optional depth may be passed in, but it defaults
|
|
330
359
|
* to a deep copy. 0 is a shallow copy, 1 is a deep copy.
|
|
331
360
|
*/
|
|
332
|
-
static VALUE
|
|
361
|
+
static VALUE
|
|
362
|
+
duplicate_document(int argc, VALUE *argv, VALUE self)
|
|
333
363
|
{
|
|
334
364
|
xmlDocPtr doc, dup;
|
|
335
365
|
VALUE copy;
|
|
336
366
|
VALUE level;
|
|
337
|
-
VALUE error_list;
|
|
338
367
|
|
|
339
|
-
if(rb_scan_args(argc, argv, "01", &level) == 0)
|
|
368
|
+
if (rb_scan_args(argc, argv, "01", &level) == 0) {
|
|
340
369
|
level = INT2NUM((long)1);
|
|
370
|
+
}
|
|
341
371
|
|
|
342
372
|
Data_Get_Struct(self, xmlDoc, doc);
|
|
343
373
|
|
|
344
374
|
dup = xmlCopyDoc(doc, (int)NUM2INT(level));
|
|
345
375
|
|
|
346
|
-
if(dup == NULL) return Qnil;
|
|
376
|
+
if (dup == NULL) { return Qnil; }
|
|
347
377
|
|
|
348
378
|
dup->type = doc->type;
|
|
349
|
-
copy =
|
|
350
|
-
|
|
351
|
-
rb_iv_set(copy, "@errors", error_list);
|
|
379
|
+
copy = noko_xml_document_wrap(rb_obj_class(self), dup);
|
|
380
|
+
rb_iv_set(copy, "@errors", rb_iv_get(self, "@errors"));
|
|
352
381
|
return copy ;
|
|
353
382
|
}
|
|
354
383
|
|
|
@@ -358,18 +387,18 @@ static VALUE duplicate_document(int argc, VALUE *argv, VALUE self)
|
|
|
358
387
|
*
|
|
359
388
|
* Create a new document with +version+ (defaults to "1.0")
|
|
360
389
|
*/
|
|
361
|
-
static VALUE
|
|
390
|
+
static VALUE
|
|
391
|
+
new (int argc, VALUE *argv, VALUE klass)
|
|
362
392
|
{
|
|
363
393
|
xmlDocPtr doc;
|
|
364
394
|
VALUE version, rest, rb_doc ;
|
|
365
395
|
|
|
366
396
|
rb_scan_args(argc, argv, "0*", &rest);
|
|
367
397
|
version = rb_ary_entry(rest, (long)0);
|
|
368
|
-
if (NIL_P(version)) version = rb_str_new2("1.0");
|
|
398
|
+
if (NIL_P(version)) { version = rb_str_new2("1.0"); }
|
|
369
399
|
|
|
370
400
|
doc = xmlNewDoc((xmlChar *)StringValueCStr(version));
|
|
371
|
-
rb_doc =
|
|
372
|
-
rb_obj_call_init(rb_doc, argc, argv);
|
|
401
|
+
rb_doc = noko_xml_document_wrap_with_init_args(klass, doc, argc, argv);
|
|
373
402
|
return rb_doc ;
|
|
374
403
|
}
|
|
375
404
|
|
|
@@ -410,7 +439,8 @@ static VALUE new(int argc, VALUE *argv, VALUE klass)
|
|
|
410
439
|
* please direct your browser to
|
|
411
440
|
* http://tenderlovemaking.com/2009/04/23/namespaces-in-xml.html
|
|
412
441
|
*/
|
|
413
|
-
|
|
442
|
+
static VALUE
|
|
443
|
+
remove_namespaces_bang(VALUE self)
|
|
414
444
|
{
|
|
415
445
|
xmlDocPtr doc ;
|
|
416
446
|
Data_Get_Struct(self, xmlDoc, doc);
|
|
@@ -430,7 +460,8 @@ VALUE remove_namespaces_bang(VALUE self)
|
|
|
430
460
|
* +external_id+, +system_id+, and +content+ set the External ID, System ID,
|
|
431
461
|
* and content respectively. All of these parameters are optional.
|
|
432
462
|
*/
|
|
433
|
-
static VALUE
|
|
463
|
+
static VALUE
|
|
464
|
+
create_entity(int argc, VALUE *argv, VALUE self)
|
|
434
465
|
{
|
|
435
466
|
VALUE name;
|
|
436
467
|
VALUE type;
|
|
@@ -443,52 +474,50 @@ static VALUE create_entity(int argc, VALUE *argv, VALUE self)
|
|
|
443
474
|
Data_Get_Struct(self, xmlDoc, doc);
|
|
444
475
|
|
|
445
476
|
rb_scan_args(argc, argv, "14", &name, &type, &external_id, &system_id,
|
|
446
|
-
|
|
477
|
+
&content);
|
|
447
478
|
|
|
448
479
|
xmlResetLastError();
|
|
449
480
|
ptr = xmlAddDocEntity(
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
if(NULL == ptr) {
|
|
481
|
+
doc,
|
|
482
|
+
(xmlChar *)(NIL_P(name) ? NULL : StringValueCStr(name)),
|
|
483
|
+
(int)(NIL_P(type) ? XML_INTERNAL_GENERAL_ENTITY : NUM2INT(type)),
|
|
484
|
+
(xmlChar *)(NIL_P(external_id) ? NULL : StringValueCStr(external_id)),
|
|
485
|
+
(xmlChar *)(NIL_P(system_id) ? NULL : StringValueCStr(system_id)),
|
|
486
|
+
(xmlChar *)(NIL_P(content) ? NULL : StringValueCStr(content))
|
|
487
|
+
);
|
|
488
|
+
|
|
489
|
+
if (NULL == ptr) {
|
|
459
490
|
xmlErrorPtr error = xmlGetLastError();
|
|
460
|
-
if(error)
|
|
491
|
+
if (error) {
|
|
461
492
|
rb_exc_raise(Nokogiri_wrap_xml_syntax_error(error));
|
|
462
|
-
else
|
|
493
|
+
} else {
|
|
463
494
|
rb_raise(rb_eRuntimeError, "Could not create entity");
|
|
495
|
+
}
|
|
464
496
|
|
|
465
497
|
return Qnil;
|
|
466
498
|
}
|
|
467
499
|
|
|
468
|
-
return
|
|
500
|
+
return noko_xml_node_wrap(cNokogiriXmlEntityDecl, (xmlNodePtr)ptr);
|
|
469
501
|
}
|
|
470
502
|
|
|
471
|
-
static int
|
|
503
|
+
static int
|
|
504
|
+
block_caller(void *ctx, xmlNodePtr c_node, xmlNodePtr c_parent_node)
|
|
472
505
|
{
|
|
473
|
-
VALUE block;
|
|
474
|
-
VALUE
|
|
475
|
-
VALUE
|
|
506
|
+
VALUE block = (VALUE)ctx;
|
|
507
|
+
VALUE rb_node;
|
|
508
|
+
VALUE rb_parent_node;
|
|
476
509
|
VALUE ret;
|
|
477
510
|
|
|
478
|
-
if(
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
node = Nokogiri_wrap_xml_node(Qnil, _node);
|
|
511
|
+
if (c_node->type == XML_NAMESPACE_DECL) {
|
|
512
|
+
rb_node = noko_xml_namespace_wrap((xmlNsPtr)c_node, c_parent_node->doc);
|
|
513
|
+
} else {
|
|
514
|
+
rb_node = noko_xml_node_wrap(Qnil, c_node);
|
|
483
515
|
}
|
|
484
|
-
|
|
485
|
-
block = (VALUE)ctx;
|
|
516
|
+
rb_parent_node = c_parent_node ? noko_xml_node_wrap(Qnil, c_parent_node) : Qnil;
|
|
486
517
|
|
|
487
|
-
ret = rb_funcall(block, rb_intern("call"), 2,
|
|
518
|
+
ret = rb_funcall(block, rb_intern("call"), 2, rb_node, rb_parent_node);
|
|
488
519
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
return 1;
|
|
520
|
+
return (Qfalse == ret || Qnil == ret) ? 0 : 1;
|
|
492
521
|
}
|
|
493
522
|
|
|
494
523
|
/* call-seq:
|
|
@@ -501,7 +530,8 @@ static int block_caller(void * ctx, xmlNodePtr _node, xmlNodePtr _parent)
|
|
|
501
530
|
* The block must return a non-nil, non-false value if the +obj+ passed in
|
|
502
531
|
* should be included in the canonicalized document.
|
|
503
532
|
*/
|
|
504
|
-
static VALUE
|
|
533
|
+
static VALUE
|
|
534
|
+
rb_xml_document_canonicalize(int argc, VALUE *argv, VALUE self)
|
|
505
535
|
{
|
|
506
536
|
VALUE mode;
|
|
507
537
|
VALUE incl_ns;
|
|
@@ -512,7 +542,7 @@ static VALUE canonicalize(int argc, VALUE* argv, VALUE self)
|
|
|
512
542
|
xmlDocPtr doc;
|
|
513
543
|
xmlOutputBufferPtr buf;
|
|
514
544
|
xmlC14NIsVisibleCallback cb = NULL;
|
|
515
|
-
void *
|
|
545
|
+
void *ctx = NULL;
|
|
516
546
|
|
|
517
547
|
VALUE rb_cStringIO;
|
|
518
548
|
VALUE io;
|
|
@@ -525,93 +555,126 @@ static VALUE canonicalize(int argc, VALUE* argv, VALUE self)
|
|
|
525
555
|
io = rb_class_new_instance(0, 0, rb_cStringIO);
|
|
526
556
|
buf = xmlAllocOutputBuffer(NULL);
|
|
527
557
|
|
|
528
|
-
buf->writecallback = (xmlOutputWriteCallback)
|
|
529
|
-
buf->closecallback = (xmlOutputCloseCallback)
|
|
558
|
+
buf->writecallback = (xmlOutputWriteCallback)noko_io_write;
|
|
559
|
+
buf->closecallback = (xmlOutputCloseCallback)noko_io_close;
|
|
530
560
|
buf->context = (void *)io;
|
|
531
561
|
|
|
532
|
-
if(rb_block_given_p()) {
|
|
562
|
+
if (rb_block_given_p()) {
|
|
533
563
|
cb = block_caller;
|
|
534
564
|
ctx = (void *)rb_block_proc();
|
|
535
565
|
}
|
|
536
566
|
|
|
537
|
-
if(NIL_P(incl_ns)){
|
|
567
|
+
if (NIL_P(incl_ns)) {
|
|
538
568
|
ns = NULL;
|
|
539
|
-
}
|
|
540
|
-
else{
|
|
569
|
+
} else {
|
|
541
570
|
Check_Type(incl_ns, T_ARRAY);
|
|
542
571
|
ns_len = RARRAY_LEN(incl_ns);
|
|
543
|
-
ns = calloc((size_t)ns_len+1, sizeof(xmlChar *));
|
|
572
|
+
ns = calloc((size_t)ns_len + 1, sizeof(xmlChar *));
|
|
544
573
|
for (i = 0 ; i < ns_len ; i++) {
|
|
545
574
|
VALUE entry = rb_ary_entry(incl_ns, i);
|
|
546
|
-
ns[i] = (xmlChar*)StringValueCStr(entry);
|
|
575
|
+
ns[i] = (xmlChar *)StringValueCStr(entry);
|
|
547
576
|
}
|
|
548
577
|
}
|
|
549
578
|
|
|
550
579
|
|
|
551
580
|
xmlC14NExecute(doc, cb, ctx,
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
581
|
+
(int)(NIL_P(mode) ? 0 : NUM2INT(mode)),
|
|
582
|
+
ns,
|
|
583
|
+
(int) RTEST(with_comments),
|
|
584
|
+
buf);
|
|
556
585
|
|
|
557
586
|
xmlOutputBufferClose(buf);
|
|
558
587
|
|
|
559
588
|
return rb_funcall(io, rb_intern("string"), 0);
|
|
560
589
|
}
|
|
561
590
|
|
|
562
|
-
VALUE
|
|
563
|
-
|
|
591
|
+
VALUE
|
|
592
|
+
noko_xml_document_wrap_with_init_args(VALUE klass, xmlDocPtr c_document, int argc, VALUE *argv)
|
|
564
593
|
{
|
|
565
|
-
VALUE
|
|
566
|
-
|
|
567
|
-
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
|
594
|
+
VALUE rb_document;
|
|
595
|
+
nokogiriTuplePtr tuple;
|
|
568
596
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
rb_define_method(klass, "remove_namespaces!", remove_namespaces_bang, 0);
|
|
597
|
+
if (!klass) {
|
|
598
|
+
klass = cNokogiriXmlDocument;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
rb_document = Data_Wrap_Struct(klass, mark, dealloc, c_document);
|
|
602
|
+
|
|
603
|
+
tuple = (nokogiriTuplePtr)malloc(sizeof(nokogiriTuple));
|
|
604
|
+
tuple->doc = rb_document;
|
|
605
|
+
tuple->unlinkedNodes = st_init_numtable_with_size(128);
|
|
606
|
+
tuple->node_cache = rb_ary_new();
|
|
607
|
+
|
|
608
|
+
c_document->_private = tuple ;
|
|
609
|
+
|
|
610
|
+
rb_iv_set(rb_document, "@decorators", Qnil);
|
|
611
|
+
rb_iv_set(rb_document, "@errors", Qnil);
|
|
612
|
+
rb_iv_set(rb_document, "@node_cache", tuple->node_cache);
|
|
613
|
+
|
|
614
|
+
rb_obj_call_init(rb_document, argc, argv);
|
|
615
|
+
|
|
616
|
+
return rb_document ;
|
|
590
617
|
}
|
|
591
618
|
|
|
592
619
|
|
|
593
|
-
/*
|
|
594
|
-
VALUE
|
|
620
|
+
/* deprecated. use noko_xml_document_wrap() instead. */
|
|
621
|
+
VALUE
|
|
622
|
+
Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc)
|
|
595
623
|
{
|
|
596
|
-
|
|
624
|
+
/* TODO: deprecate this method in v2.0 */
|
|
625
|
+
return noko_xml_document_wrap_with_init_args(klass, doc, 0, NULL);
|
|
626
|
+
}
|
|
597
627
|
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
);
|
|
628
|
+
VALUE
|
|
629
|
+
noko_xml_document_wrap(VALUE klass, xmlDocPtr doc)
|
|
630
|
+
{
|
|
631
|
+
return noko_xml_document_wrap_with_init_args(klass, doc, 0, NULL);
|
|
632
|
+
}
|
|
604
633
|
|
|
605
|
-
VALUE cache = rb_ary_new();
|
|
606
|
-
rb_iv_set(rb_doc, "@decorators", Qnil);
|
|
607
|
-
rb_iv_set(rb_doc, "@node_cache", cache);
|
|
608
634
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
doc
|
|
635
|
+
void
|
|
636
|
+
noko_xml_document_pin_node(xmlNodePtr node)
|
|
637
|
+
{
|
|
638
|
+
xmlDocPtr doc;
|
|
639
|
+
nokogiriTuplePtr tuple;
|
|
613
640
|
|
|
614
|
-
|
|
641
|
+
doc = node->doc;
|
|
642
|
+
tuple = (nokogiriTuplePtr)doc->_private;
|
|
643
|
+
st_insert(tuple->unlinkedNodes, (st_data_t)node, (st_data_t)node);
|
|
644
|
+
}
|
|
615
645
|
|
|
616
|
-
|
|
646
|
+
|
|
647
|
+
void
|
|
648
|
+
noko_xml_document_pin_namespace(xmlNsPtr ns, xmlDocPtr doc)
|
|
649
|
+
{
|
|
650
|
+
nokogiriTuplePtr tuple;
|
|
651
|
+
|
|
652
|
+
tuple = (nokogiriTuplePtr)doc->_private;
|
|
653
|
+
st_insert(tuple->unlinkedNodes, (st_data_t)ns, (st_data_t)ns);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
void
|
|
658
|
+
noko_init_xml_document()
|
|
659
|
+
{
|
|
660
|
+
assert(cNokogiriXmlNode);
|
|
661
|
+
/*
|
|
662
|
+
* Nokogiri::XML::Document wraps an xml document.
|
|
663
|
+
*/
|
|
664
|
+
cNokogiriXmlDocument = rb_define_class_under(mNokogiriXml, "Document", cNokogiriXmlNode);
|
|
665
|
+
|
|
666
|
+
rb_define_singleton_method(cNokogiriXmlDocument, "read_memory", read_memory, 4);
|
|
667
|
+
rb_define_singleton_method(cNokogiriXmlDocument, "read_io", read_io, 4);
|
|
668
|
+
rb_define_singleton_method(cNokogiriXmlDocument, "new", new, -1);
|
|
669
|
+
|
|
670
|
+
rb_define_method(cNokogiriXmlDocument, "root", rb_xml_document_root, 0);
|
|
671
|
+
rb_define_method(cNokogiriXmlDocument, "root=", rb_xml_document_root_set, 1);
|
|
672
|
+
rb_define_method(cNokogiriXmlDocument, "encoding", encoding, 0);
|
|
673
|
+
rb_define_method(cNokogiriXmlDocument, "encoding=", set_encoding, 1);
|
|
674
|
+
rb_define_method(cNokogiriXmlDocument, "version", version, 0);
|
|
675
|
+
rb_define_method(cNokogiriXmlDocument, "canonicalize", rb_xml_document_canonicalize, -1);
|
|
676
|
+
rb_define_method(cNokogiriXmlDocument, "dup", duplicate_document, -1);
|
|
677
|
+
rb_define_method(cNokogiriXmlDocument, "url", url, 0);
|
|
678
|
+
rb_define_method(cNokogiriXmlDocument, "create_entity", create_entity, -1);
|
|
679
|
+
rb_define_method(cNokogiriXmlDocument, "remove_namespaces!", remove_namespaces_bang, 0);
|
|
617
680
|
}
|