nokogiri 1.3.0-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of nokogiri might be problematic. Click here for more details.
- data/.autotest +27 -0
- data/CHANGELOG.ja.rdoc +233 -0
- data/CHANGELOG.rdoc +222 -0
- data/Manifest.txt +247 -0
- data/README.ja.rdoc +103 -0
- data/README.rdoc +117 -0
- data/Rakefile +205 -0
- data/bin/nokogiri +47 -0
- data/ext/nokogiri/extconf.rb +89 -0
- data/ext/nokogiri/html_document.c +183 -0
- data/ext/nokogiri/html_document.h +10 -0
- data/ext/nokogiri/html_element_description.c +272 -0
- data/ext/nokogiri/html_element_description.h +10 -0
- data/ext/nokogiri/html_entity_lookup.c +30 -0
- data/ext/nokogiri/html_entity_lookup.h +8 -0
- data/ext/nokogiri/html_sax_parser.c +57 -0
- data/ext/nokogiri/html_sax_parser.h +11 -0
- data/ext/nokogiri/iconv.dll +0 -0
- data/ext/nokogiri/libexslt.dll +0 -0
- data/ext/nokogiri/libxml2.dll +0 -0
- data/ext/nokogiri/libxslt.dll +0 -0
- data/ext/nokogiri/nokogiri.c +81 -0
- data/ext/nokogiri/nokogiri.h +149 -0
- data/ext/nokogiri/xml_attr.c +92 -0
- data/ext/nokogiri/xml_attr.h +9 -0
- data/ext/nokogiri/xml_cdata.c +53 -0
- data/ext/nokogiri/xml_cdata.h +9 -0
- data/ext/nokogiri/xml_comment.c +51 -0
- data/ext/nokogiri/xml_comment.h +9 -0
- data/ext/nokogiri/xml_document.c +308 -0
- data/ext/nokogiri/xml_document.h +21 -0
- data/ext/nokogiri/xml_document_fragment.c +48 -0
- data/ext/nokogiri/xml_document_fragment.h +10 -0
- data/ext/nokogiri/xml_dtd.c +102 -0
- data/ext/nokogiri/xml_dtd.h +8 -0
- data/ext/nokogiri/xml_entity_reference.c +50 -0
- data/ext/nokogiri/xml_entity_reference.h +9 -0
- data/ext/nokogiri/xml_io.c +24 -0
- data/ext/nokogiri/xml_io.h +10 -0
- data/ext/nokogiri/xml_namespace.c +69 -0
- data/ext/nokogiri/xml_namespace.h +12 -0
- data/ext/nokogiri/xml_node.c +928 -0
- data/ext/nokogiri/xml_node.h +14 -0
- data/ext/nokogiri/xml_node_set.c +386 -0
- data/ext/nokogiri/xml_node_set.h +9 -0
- data/ext/nokogiri/xml_processing_instruction.c +54 -0
- data/ext/nokogiri/xml_processing_instruction.h +9 -0
- data/ext/nokogiri/xml_reader.c +572 -0
- data/ext/nokogiri/xml_reader.h +10 -0
- data/ext/nokogiri/xml_relax_ng.c +106 -0
- data/ext/nokogiri/xml_relax_ng.h +9 -0
- data/ext/nokogiri/xml_sax_parser.c +336 -0
- data/ext/nokogiri/xml_sax_parser.h +10 -0
- data/ext/nokogiri/xml_sax_push_parser.c +86 -0
- data/ext/nokogiri/xml_sax_push_parser.h +9 -0
- data/ext/nokogiri/xml_schema.c +107 -0
- data/ext/nokogiri/xml_schema.h +9 -0
- data/ext/nokogiri/xml_syntax_error.c +203 -0
- data/ext/nokogiri/xml_syntax_error.h +12 -0
- data/ext/nokogiri/xml_text.c +47 -0
- data/ext/nokogiri/xml_text.h +9 -0
- data/ext/nokogiri/xml_xpath.c +53 -0
- data/ext/nokogiri/xml_xpath.h +11 -0
- data/ext/nokogiri/xml_xpath_context.c +252 -0
- data/ext/nokogiri/xml_xpath_context.h +9 -0
- data/ext/nokogiri/xslt_stylesheet.c +131 -0
- data/ext/nokogiri/xslt_stylesheet.h +9 -0
- data/ext/nokogiri/zlib1.dll +0 -0
- data/lib/action-nokogiri.rb +36 -0
- data/lib/nokogiri.rb +110 -0
- data/lib/nokogiri/1.8/nokogiri.so +0 -0
- data/lib/nokogiri/1.9/nokogiri.so +0 -0
- data/lib/nokogiri/css.rb +25 -0
- data/lib/nokogiri/css/generated_parser.rb +748 -0
- data/lib/nokogiri/css/generated_tokenizer.rb +144 -0
- data/lib/nokogiri/css/node.rb +107 -0
- data/lib/nokogiri/css/parser.rb +82 -0
- data/lib/nokogiri/css/parser.y +227 -0
- data/lib/nokogiri/css/syntax_error.rb +7 -0
- data/lib/nokogiri/css/tokenizer.rb +11 -0
- data/lib/nokogiri/css/tokenizer.rex +54 -0
- data/lib/nokogiri/css/xpath_visitor.rb +172 -0
- data/lib/nokogiri/decorators.rb +2 -0
- data/lib/nokogiri/decorators/hpricot.rb +3 -0
- data/lib/nokogiri/decorators/hpricot/node.rb +56 -0
- data/lib/nokogiri/decorators/hpricot/node_set.rb +54 -0
- data/lib/nokogiri/decorators/hpricot/xpath_visitor.rb +30 -0
- data/lib/nokogiri/decorators/slop.rb +33 -0
- data/lib/nokogiri/ffi/html/document.rb +37 -0
- data/lib/nokogiri/ffi/html/element_description.rb +85 -0
- data/lib/nokogiri/ffi/html/entity_lookup.rb +16 -0
- data/lib/nokogiri/ffi/html/sax/parser.rb +21 -0
- data/lib/nokogiri/ffi/io_callbacks.rb +32 -0
- data/lib/nokogiri/ffi/libxml.rb +314 -0
- data/lib/nokogiri/ffi/structs/common_node.rb +26 -0
- data/lib/nokogiri/ffi/structs/html_elem_desc.rb +24 -0
- data/lib/nokogiri/ffi/structs/html_entity_desc.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_alloc.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_attr.rb +19 -0
- data/lib/nokogiri/ffi/structs/xml_buffer.rb +16 -0
- data/lib/nokogiri/ffi/structs/xml_document.rb +108 -0
- data/lib/nokogiri/ffi/structs/xml_dtd.rb +26 -0
- data/lib/nokogiri/ffi/structs/xml_node.rb +28 -0
- data/lib/nokogiri/ffi/structs/xml_node_set.rb +53 -0
- data/lib/nokogiri/ffi/structs/xml_notation.rb +11 -0
- data/lib/nokogiri/ffi/structs/xml_ns.rb +15 -0
- data/lib/nokogiri/ffi/structs/xml_relax_ng.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_sax_handler.rb +51 -0
- data/lib/nokogiri/ffi/structs/xml_sax_push_parser_context.rb +14 -0
- data/lib/nokogiri/ffi/structs/xml_schema.rb +13 -0
- data/lib/nokogiri/ffi/structs/xml_syntax_error.rb +31 -0
- data/lib/nokogiri/ffi/structs/xml_text_reader.rb +12 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_context.rb +37 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_object.rb +35 -0
- data/lib/nokogiri/ffi/structs/xml_xpath_parser_context.rb +20 -0
- data/lib/nokogiri/ffi/structs/xslt_stylesheet.rb +13 -0
- data/lib/nokogiri/ffi/xml/attr.rb +41 -0
- data/lib/nokogiri/ffi/xml/cdata.rb +19 -0
- data/lib/nokogiri/ffi/xml/comment.rb +18 -0
- data/lib/nokogiri/ffi/xml/document.rb +107 -0
- data/lib/nokogiri/ffi/xml/document_fragment.rb +26 -0
- data/lib/nokogiri/ffi/xml/dtd.rb +42 -0
- data/lib/nokogiri/ffi/xml/entity_reference.rb +19 -0
- data/lib/nokogiri/ffi/xml/namespace.rb +38 -0
- data/lib/nokogiri/ffi/xml/node.rb +380 -0
- data/lib/nokogiri/ffi/xml/node_set.rb +130 -0
- data/lib/nokogiri/ffi/xml/processing_instruction.rb +20 -0
- data/lib/nokogiri/ffi/xml/reader.rb +217 -0
- data/lib/nokogiri/ffi/xml/relax_ng.rb +51 -0
- data/lib/nokogiri/ffi/xml/sax/parser.rb +148 -0
- data/lib/nokogiri/ffi/xml/sax/push_parser.rb +38 -0
- data/lib/nokogiri/ffi/xml/schema.rb +55 -0
- data/lib/nokogiri/ffi/xml/syntax_error.rb +76 -0
- data/lib/nokogiri/ffi/xml/text.rb +18 -0
- data/lib/nokogiri/ffi/xml/xpath.rb +19 -0
- data/lib/nokogiri/ffi/xml/xpath_context.rb +135 -0
- data/lib/nokogiri/ffi/xslt/stylesheet.rb +47 -0
- data/lib/nokogiri/hpricot.rb +62 -0
- data/lib/nokogiri/html.rb +34 -0
- data/lib/nokogiri/html/builder.rb +35 -0
- data/lib/nokogiri/html/document.rb +71 -0
- data/lib/nokogiri/html/document_fragment.rb +15 -0
- data/lib/nokogiri/html/element_description.rb +23 -0
- data/lib/nokogiri/html/entity_lookup.rb +13 -0
- data/lib/nokogiri/html/sax/parser.rb +47 -0
- data/lib/nokogiri/nokogiri.rb +1 -0
- data/lib/nokogiri/syntax_error.rb +4 -0
- data/lib/nokogiri/version.rb +29 -0
- data/lib/nokogiri/version_warning.rb +11 -0
- data/lib/nokogiri/xml.rb +62 -0
- data/lib/nokogiri/xml/attr.rb +9 -0
- data/lib/nokogiri/xml/builder.rb +254 -0
- data/lib/nokogiri/xml/cdata.rb +11 -0
- data/lib/nokogiri/xml/document.rb +100 -0
- data/lib/nokogiri/xml/document_fragment.rb +49 -0
- data/lib/nokogiri/xml/dtd.rb +11 -0
- data/lib/nokogiri/xml/entity_declaration.rb +11 -0
- data/lib/nokogiri/xml/fragment_handler.rb +55 -0
- data/lib/nokogiri/xml/namespace.rb +7 -0
- data/lib/nokogiri/xml/node.rb +745 -0
- data/lib/nokogiri/xml/node/save_options.rb +42 -0
- data/lib/nokogiri/xml/node_set.rb +238 -0
- data/lib/nokogiri/xml/notation.rb +6 -0
- data/lib/nokogiri/xml/parse_options.rb +80 -0
- data/lib/nokogiri/xml/processing_instruction.rb +8 -0
- data/lib/nokogiri/xml/reader.rb +66 -0
- data/lib/nokogiri/xml/relax_ng.rb +32 -0
- data/lib/nokogiri/xml/sax.rb +3 -0
- data/lib/nokogiri/xml/sax/document.rb +143 -0
- data/lib/nokogiri/xml/sax/parser.rb +101 -0
- data/lib/nokogiri/xml/sax/push_parser.rb +60 -0
- data/lib/nokogiri/xml/schema.rb +65 -0
- data/lib/nokogiri/xml/syntax_error.rb +34 -0
- data/lib/nokogiri/xml/xpath.rb +10 -0
- data/lib/nokogiri/xml/xpath/syntax_error.rb +8 -0
- data/lib/nokogiri/xml/xpath_context.rb +16 -0
- data/lib/nokogiri/xslt.rb +48 -0
- data/lib/nokogiri/xslt/stylesheet.rb +25 -0
- data/lib/xsd/xmlparser/nokogiri.rb +64 -0
- data/tasks/test.rb +161 -0
- data/test/css/test_nthiness.rb +160 -0
- data/test/css/test_parser.rb +277 -0
- data/test/css/test_tokenizer.rb +176 -0
- data/test/css/test_xpath_visitor.rb +76 -0
- data/test/ffi/test_document.rb +35 -0
- data/test/files/address_book.rlx +12 -0
- data/test/files/address_book.xml +10 -0
- data/test/files/dont_hurt_em_why.xml +422 -0
- data/test/files/exslt.xml +8 -0
- data/test/files/exslt.xslt +35 -0
- data/test/files/po.xml +32 -0
- data/test/files/po.xsd +66 -0
- data/test/files/staff.xml +59 -0
- data/test/files/staff.xslt +32 -0
- data/test/files/tlm.html +850 -0
- data/test/helper.rb +123 -0
- data/test/hpricot/files/basic.xhtml +17 -0
- data/test/hpricot/files/boingboing.html +2266 -0
- data/test/hpricot/files/cy0.html +3653 -0
- data/test/hpricot/files/immob.html +400 -0
- data/test/hpricot/files/pace_application.html +1320 -0
- data/test/hpricot/files/tenderlove.html +16 -0
- data/test/hpricot/files/uswebgen.html +220 -0
- data/test/hpricot/files/utf8.html +1054 -0
- data/test/hpricot/files/week9.html +1723 -0
- data/test/hpricot/files/why.xml +19 -0
- data/test/hpricot/load_files.rb +11 -0
- data/test/hpricot/test_alter.rb +68 -0
- data/test/hpricot/test_builder.rb +20 -0
- data/test/hpricot/test_parser.rb +426 -0
- data/test/hpricot/test_paths.rb +15 -0
- data/test/hpricot/test_preserved.rb +77 -0
- data/test/hpricot/test_xml.rb +30 -0
- data/test/html/sax/test_parser.rb +52 -0
- data/test/html/test_builder.rb +156 -0
- data/test/html/test_document.rb +361 -0
- data/test/html/test_document_encoding.rb +46 -0
- data/test/html/test_document_fragment.rb +97 -0
- data/test/html/test_element_description.rb +95 -0
- data/test/html/test_named_characters.rb +14 -0
- data/test/html/test_node.rb +165 -0
- data/test/test_convert_xpath.rb +186 -0
- data/test/test_css_cache.rb +56 -0
- data/test/test_gc.rb +15 -0
- data/test/test_memory_leak.rb +77 -0
- data/test/test_nokogiri.rb +127 -0
- data/test/test_reader.rb +316 -0
- data/test/test_xslt_transforms.rb +131 -0
- data/test/xml/node/test_save_options.rb +20 -0
- data/test/xml/node/test_subclass.rb +44 -0
- data/test/xml/sax/test_parser.rb +169 -0
- data/test/xml/sax/test_push_parser.rb +92 -0
- data/test/xml/test_attr.rb +38 -0
- data/test/xml/test_builder.rb +73 -0
- data/test/xml/test_cdata.rb +38 -0
- data/test/xml/test_comment.rb +23 -0
- data/test/xml/test_document.rb +397 -0
- data/test/xml/test_document_encoding.rb +26 -0
- data/test/xml/test_document_fragment.rb +76 -0
- data/test/xml/test_dtd.rb +42 -0
- data/test/xml/test_dtd_encoding.rb +31 -0
- data/test/xml/test_entity_reference.rb +21 -0
- data/test/xml/test_namespace.rb +43 -0
- data/test/xml/test_node.rb +808 -0
- data/test/xml/test_node_attributes.rb +34 -0
- data/test/xml/test_node_encoding.rb +84 -0
- data/test/xml/test_node_set.rb +368 -0
- data/test/xml/test_parse_options.rb +52 -0
- data/test/xml/test_processing_instruction.rb +30 -0
- data/test/xml/test_reader_encoding.rb +126 -0
- data/test/xml/test_relax_ng.rb +60 -0
- data/test/xml/test_schema.rb +65 -0
- data/test/xml/test_text.rb +18 -0
- data/test/xml/test_unparented_node.rb +381 -0
- data/test/xml/test_xpath.rb +106 -0
- metadata +409 -0
@@ -0,0 +1,149 @@
|
|
1
|
+
#ifndef NOKOGIRI_NATIVE
|
2
|
+
#define NOKOGIRI_NATIVE
|
3
|
+
|
4
|
+
#include <stdlib.h>
|
5
|
+
#include <assert.h>
|
6
|
+
#include <ruby.h>
|
7
|
+
#include <libxml/parser.h>
|
8
|
+
#include <libxml/xpath.h>
|
9
|
+
#include <libxml/xpathInternals.h>
|
10
|
+
#include <libxml/xmlreader.h>
|
11
|
+
#include <libxml/xmlsave.h>
|
12
|
+
#include <libxml/xmlschemas.h>
|
13
|
+
#include <libxml/HTMLparser.h>
|
14
|
+
#include <libxml/HTMLtree.h>
|
15
|
+
|
16
|
+
#ifdef USE_INCLUDED_VASPRINTF
|
17
|
+
int vasprintf (char **strp, const char *fmt, va_list ap);
|
18
|
+
#else
|
19
|
+
|
20
|
+
#ifndef _GNU_SOURCE
|
21
|
+
#define _GNU_SOURCE
|
22
|
+
#endif
|
23
|
+
|
24
|
+
# include <stdio.h>
|
25
|
+
|
26
|
+
#endif
|
27
|
+
|
28
|
+
int is_2_6_16(void) ;
|
29
|
+
|
30
|
+
#ifndef UNUSED
|
31
|
+
# if defined(__GNUC__)
|
32
|
+
# define MAYBE_UNUSED(name) name __attribute__((unused))
|
33
|
+
# define UNUSED(name) MAYBE_UNUSED(UNUSED_ ## name)
|
34
|
+
# else
|
35
|
+
# define MAYBE_UNUSED(name) name
|
36
|
+
# define UNUSED(name) name
|
37
|
+
# endif
|
38
|
+
#endif
|
39
|
+
|
40
|
+
#ifdef HAVE_RUBY_ENCODING_H
|
41
|
+
|
42
|
+
#include <ruby/encoding.h>
|
43
|
+
|
44
|
+
#define NOKOGIRI_STR_NEW2(str, encoding) \
|
45
|
+
({ \
|
46
|
+
VALUE _string = rb_str_new2((const char *)str); \
|
47
|
+
if(NULL != encoding) { \
|
48
|
+
int _enc = rb_enc_find_index(encoding); \
|
49
|
+
if(_enc == -1) \
|
50
|
+
rb_enc_associate_index(_string, rb_enc_find_index("ASCII")); \
|
51
|
+
else \
|
52
|
+
rb_enc_associate_index(_string, _enc); \
|
53
|
+
} \
|
54
|
+
_string; \
|
55
|
+
})
|
56
|
+
|
57
|
+
#define NOKOGIRI_STR_NEW(str, len, encoding) \
|
58
|
+
({ \
|
59
|
+
VALUE _string = rb_str_new((const char *)str, (long)len); \
|
60
|
+
if(NULL != encoding) { \
|
61
|
+
int _enc = rb_enc_find_index(encoding); \
|
62
|
+
if(_enc == -1) \
|
63
|
+
rb_enc_associate_index(_string, rb_enc_find_index("ASCII")); \
|
64
|
+
else \
|
65
|
+
rb_enc_associate_index(_string, _enc); \
|
66
|
+
} \
|
67
|
+
_string; \
|
68
|
+
})
|
69
|
+
|
70
|
+
#else
|
71
|
+
|
72
|
+
#define NOKOGIRI_STR_NEW2(str, doc) \
|
73
|
+
rb_str_new2((const char *)str)
|
74
|
+
|
75
|
+
#define NOKOGIRI_STR_NEW(str, len, doc) \
|
76
|
+
rb_str_new((const char *)str, (long)len)
|
77
|
+
#endif
|
78
|
+
|
79
|
+
#include <xml_io.h>
|
80
|
+
#include <xml_document.h>
|
81
|
+
#include <html_entity_lookup.h>
|
82
|
+
#include <html_document.h>
|
83
|
+
#include <xml_node.h>
|
84
|
+
#include <xml_text.h>
|
85
|
+
#include <xml_cdata.h>
|
86
|
+
#include <xml_attr.h>
|
87
|
+
#include <xml_processing_instruction.h>
|
88
|
+
#include <xml_entity_reference.h>
|
89
|
+
#include <xml_document_fragment.h>
|
90
|
+
#include <xml_comment.h>
|
91
|
+
#include <xml_node_set.h>
|
92
|
+
#include <xml_xpath.h>
|
93
|
+
#include <xml_dtd.h>
|
94
|
+
#include <xml_xpath_context.h>
|
95
|
+
#include <xml_sax_parser.h>
|
96
|
+
#include <xml_sax_push_parser.h>
|
97
|
+
#include <xml_reader.h>
|
98
|
+
#include <html_sax_parser.h>
|
99
|
+
#include <xslt_stylesheet.h>
|
100
|
+
#include <xml_syntax_error.h>
|
101
|
+
#include <xml_schema.h>
|
102
|
+
#include <xml_relax_ng.h>
|
103
|
+
#include <html_element_description.h>
|
104
|
+
#include <xml_namespace.h>
|
105
|
+
|
106
|
+
extern VALUE mNokogiri ;
|
107
|
+
extern VALUE mNokogiriXml ;
|
108
|
+
extern VALUE mNokogiriXmlSax ;
|
109
|
+
extern VALUE mNokogiriHtml ;
|
110
|
+
extern VALUE mNokogiriHtmlSax ;
|
111
|
+
extern VALUE mNokogiriXslt ;
|
112
|
+
|
113
|
+
#define NOKOGIRI_ROOT_NODE(_node) \
|
114
|
+
({ \
|
115
|
+
nokogiriTuplePtr tuple = (nokogiriTuplePtr)(_node->doc->_private); \
|
116
|
+
xmlNodeSetPtr node_set = (xmlNodeSetPtr)(tuple->unlinkedNodes); \
|
117
|
+
xmlXPathNodeSetAdd(node_set, _node); \
|
118
|
+
_node; \
|
119
|
+
})
|
120
|
+
|
121
|
+
#ifdef DEBUG
|
122
|
+
|
123
|
+
#define NOKOGIRI_DEBUG_START(p) if (getenv("NOKOGIRI_NO_FREE")) return ; if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p start\n", __FILE__, __LINE__, p);
|
124
|
+
#define NOKOGIRI_DEBUG_END(p) if (getenv("NOKOGIRI_DEBUG")) fprintf(stderr,"nokogiri: %s:%d %p end\n", __FILE__, __LINE__, p);
|
125
|
+
|
126
|
+
#else
|
127
|
+
|
128
|
+
#define NOKOGIRI_DEBUG_START(p)
|
129
|
+
#define NOKOGIRI_DEBUG_END(p)
|
130
|
+
|
131
|
+
#ifndef RSTRING_PTR
|
132
|
+
#define RSTRING_PTR(s) (RSTRING(s)->ptr)
|
133
|
+
#endif
|
134
|
+
|
135
|
+
#ifndef RSTRING_LEN
|
136
|
+
#define RSTRING_LEN(s) (RSTRING(s)->len)
|
137
|
+
#endif
|
138
|
+
|
139
|
+
#ifndef RARRAY_PTR
|
140
|
+
#define RARRAY_PTR(a) RARRAY(a)->ptr
|
141
|
+
#endif
|
142
|
+
|
143
|
+
#ifndef RARRAY_LEN
|
144
|
+
#define RARRAY_LEN(a) RARRAY(a)->len
|
145
|
+
#endif
|
146
|
+
|
147
|
+
#endif
|
148
|
+
|
149
|
+
#endif
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#include <xml_attr.h>
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* value=(content)
|
6
|
+
*
|
7
|
+
* Set the value for this Attr to +content+
|
8
|
+
*/
|
9
|
+
static VALUE set_value(VALUE self, VALUE content)
|
10
|
+
{
|
11
|
+
xmlAttrPtr attr;
|
12
|
+
Data_Get_Struct(self, xmlAttr, attr);
|
13
|
+
|
14
|
+
if(attr->children) xmlFreeNodeList(attr->children);
|
15
|
+
|
16
|
+
attr->children = attr->last = NULL;
|
17
|
+
|
18
|
+
if(content) {
|
19
|
+
xmlChar *buffer;
|
20
|
+
xmlNode *tmp;
|
21
|
+
|
22
|
+
// Encode our content
|
23
|
+
buffer = xmlEncodeEntitiesReentrant(attr->doc, (unsigned char *)StringValuePtr(content));
|
24
|
+
|
25
|
+
attr->children = xmlStringGetNodeList(attr->doc, buffer);
|
26
|
+
attr->last = NULL;
|
27
|
+
tmp = attr->children;
|
28
|
+
|
29
|
+
// Loop through the children
|
30
|
+
for(tmp = attr->children; tmp; tmp = tmp->next) {
|
31
|
+
tmp->parent = (xmlNode *)attr;
|
32
|
+
tmp->doc = attr->doc;
|
33
|
+
if(tmp->next == NULL) attr->last = tmp;
|
34
|
+
}
|
35
|
+
|
36
|
+
// Free up memory
|
37
|
+
xmlFree(buffer);
|
38
|
+
}
|
39
|
+
|
40
|
+
return content;
|
41
|
+
}
|
42
|
+
|
43
|
+
/*
|
44
|
+
* call-seq:
|
45
|
+
* new(document, name)
|
46
|
+
*
|
47
|
+
* Create a new Attr element on the +document+ with +name+
|
48
|
+
*/
|
49
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
50
|
+
{
|
51
|
+
xmlDocPtr xml_doc;
|
52
|
+
VALUE document;
|
53
|
+
VALUE name;
|
54
|
+
VALUE rest;
|
55
|
+
|
56
|
+
rb_scan_args(argc, argv, "2*", &document, &name, &rest);
|
57
|
+
|
58
|
+
Data_Get_Struct(document, xmlDoc, xml_doc);
|
59
|
+
|
60
|
+
xmlAttrPtr node = xmlNewDocProp(
|
61
|
+
xml_doc,
|
62
|
+
(const xmlChar *)StringValuePtr(name),
|
63
|
+
NULL
|
64
|
+
);
|
65
|
+
|
66
|
+
NOKOGIRI_ROOT_NODE((xmlNodePtr)node);
|
67
|
+
|
68
|
+
VALUE rb_node = Nokogiri_wrap_xml_node(klass, (xmlNodePtr)node);
|
69
|
+
rb_funcall2(rb_node, rb_intern("initialize"), argc, argv);
|
70
|
+
|
71
|
+
if(rb_block_given_p()) rb_yield(rb_node);
|
72
|
+
|
73
|
+
return rb_node;
|
74
|
+
}
|
75
|
+
|
76
|
+
VALUE cNokogiriXmlAttr;
|
77
|
+
void init_xml_attr()
|
78
|
+
{
|
79
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
80
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
81
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
82
|
+
|
83
|
+
/*
|
84
|
+
* Attr represents a Attr node in an xml document.
|
85
|
+
*/
|
86
|
+
VALUE klass = rb_define_class_under(xml, "Attr", node);
|
87
|
+
|
88
|
+
cNokogiriXmlAttr = klass;
|
89
|
+
|
90
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
91
|
+
rb_define_method(klass, "value=", set_value, 1);
|
92
|
+
}
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#include <xml_cdata.h>
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* new(document, content)
|
6
|
+
*
|
7
|
+
* Create a new CData element on the +document+ with +content+
|
8
|
+
*/
|
9
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
10
|
+
{
|
11
|
+
xmlDocPtr xml_doc;
|
12
|
+
VALUE doc;
|
13
|
+
VALUE content;
|
14
|
+
VALUE rest;
|
15
|
+
|
16
|
+
rb_scan_args(argc, argv, "2*", &doc, &content, &rest);
|
17
|
+
|
18
|
+
Data_Get_Struct(doc, xmlDoc, xml_doc);
|
19
|
+
|
20
|
+
xmlNodePtr node = xmlNewCDataBlock(
|
21
|
+
xml_doc->doc,
|
22
|
+
Qnil == content ? NULL : (const xmlChar *)StringValuePtr(content),
|
23
|
+
Qnil == content ? 0 : RSTRING_LEN(content)
|
24
|
+
);
|
25
|
+
|
26
|
+
NOKOGIRI_ROOT_NODE(node);
|
27
|
+
|
28
|
+
VALUE rb_node = Nokogiri_wrap_xml_node(klass, node);
|
29
|
+
rb_funcall2(rb_node, rb_intern("initialize"), argc, argv);
|
30
|
+
|
31
|
+
if(rb_block_given_p()) rb_yield(rb_node);
|
32
|
+
|
33
|
+
return rb_node;
|
34
|
+
}
|
35
|
+
|
36
|
+
VALUE cNokogiriXmlCData;
|
37
|
+
void init_xml_cdata()
|
38
|
+
{
|
39
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
40
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
41
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
42
|
+
VALUE text = rb_define_class_under(xml, "Text", node);
|
43
|
+
|
44
|
+
/*
|
45
|
+
* CData represents a CData node in an xml document.
|
46
|
+
*/
|
47
|
+
VALUE klass = rb_define_class_under(xml, "CDATA", text);
|
48
|
+
|
49
|
+
|
50
|
+
cNokogiriXmlCData = klass;
|
51
|
+
|
52
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
53
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#include <xml_comment.h>
|
2
|
+
|
3
|
+
/*
|
4
|
+
* call-seq:
|
5
|
+
* new(document, content)
|
6
|
+
*
|
7
|
+
* Create a new Comment element on the +document+ with +content+
|
8
|
+
*/
|
9
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
10
|
+
{
|
11
|
+
xmlDocPtr xml_doc;
|
12
|
+
VALUE document;
|
13
|
+
VALUE content;
|
14
|
+
VALUE rest;
|
15
|
+
|
16
|
+
rb_scan_args(argc, argv, "2*", &document, &content, &rest);
|
17
|
+
|
18
|
+
Data_Get_Struct(document, xmlDoc, xml_doc);
|
19
|
+
|
20
|
+
xmlNodePtr node = xmlNewDocComment(
|
21
|
+
xml_doc,
|
22
|
+
(const xmlChar *)StringValuePtr(content)
|
23
|
+
);
|
24
|
+
|
25
|
+
VALUE rb_node = Nokogiri_wrap_xml_node(klass, node);
|
26
|
+
rb_funcall2(rb_node, rb_intern("initialize"), argc, argv);
|
27
|
+
|
28
|
+
NOKOGIRI_ROOT_NODE(node);
|
29
|
+
|
30
|
+
if(rb_block_given_p()) rb_yield(rb_node);
|
31
|
+
|
32
|
+
return rb_node;
|
33
|
+
}
|
34
|
+
|
35
|
+
VALUE cNokogiriXmlComment;
|
36
|
+
void init_xml_comment()
|
37
|
+
{
|
38
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
39
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
40
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
41
|
+
|
42
|
+
/*
|
43
|
+
* Comment represents a comment node in an xml document.
|
44
|
+
*/
|
45
|
+
VALUE klass = rb_define_class_under(xml, "Comment", node);
|
46
|
+
|
47
|
+
|
48
|
+
cNokogiriXmlComment = klass;
|
49
|
+
|
50
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
51
|
+
}
|
@@ -0,0 +1,308 @@
|
|
1
|
+
#include <xml_document.h>
|
2
|
+
|
3
|
+
static void dealloc(xmlDocPtr doc)
|
4
|
+
{
|
5
|
+
NOKOGIRI_DEBUG_START(doc);
|
6
|
+
|
7
|
+
nokogiriTuplePtr tuple = doc->_private;
|
8
|
+
xmlNodeSetPtr node_set = tuple->unlinkedNodes;
|
9
|
+
|
10
|
+
xmlDeregisterNodeFunc func = xmlDeregisterNodeDefault(NULL);
|
11
|
+
|
12
|
+
int j ;
|
13
|
+
for(j = 0 ; j < node_set->nodeNr ; j++) {
|
14
|
+
xmlNodePtr node = node_set->nodeTab[j];
|
15
|
+
switch(node->type)
|
16
|
+
{
|
17
|
+
case XML_ATTRIBUTE_NODE:
|
18
|
+
xmlFreePropList((xmlAttrPtr)node);
|
19
|
+
break;
|
20
|
+
default:
|
21
|
+
if(node->parent == NULL) {
|
22
|
+
xmlAddChild((xmlNodePtr)doc, node);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
if (node_set->nodeTab != NULL)
|
28
|
+
xmlFree(node_set->nodeTab);
|
29
|
+
xmlFree(node_set);
|
30
|
+
|
31
|
+
free(doc->_private);
|
32
|
+
doc->_private = NULL;
|
33
|
+
xmlFreeDoc(doc);
|
34
|
+
|
35
|
+
xmlDeregisterNodeDefault(func);
|
36
|
+
|
37
|
+
NOKOGIRI_DEBUG_END(doc);
|
38
|
+
}
|
39
|
+
|
40
|
+
/*
|
41
|
+
* call-seq:
|
42
|
+
* url
|
43
|
+
*
|
44
|
+
* Get the url name for this document.
|
45
|
+
*/
|
46
|
+
static VALUE url(VALUE self)
|
47
|
+
{
|
48
|
+
xmlDocPtr doc;
|
49
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
50
|
+
|
51
|
+
if(doc->URL)
|
52
|
+
return NOKOGIRI_STR_NEW2(doc->URL, doc->encoding);
|
53
|
+
|
54
|
+
return Qnil;
|
55
|
+
}
|
56
|
+
|
57
|
+
/*
|
58
|
+
* call-seq:
|
59
|
+
* root=
|
60
|
+
*
|
61
|
+
* Set the root element on this document
|
62
|
+
*/
|
63
|
+
static VALUE set_root(VALUE self, VALUE root)
|
64
|
+
{
|
65
|
+
xmlDocPtr doc;
|
66
|
+
xmlNodePtr new_root;
|
67
|
+
|
68
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
69
|
+
Data_Get_Struct(root, xmlNode, new_root);
|
70
|
+
|
71
|
+
xmlDocSetRootElement(doc, new_root);
|
72
|
+
return root;
|
73
|
+
}
|
74
|
+
|
75
|
+
/*
|
76
|
+
* call-seq:
|
77
|
+
* root
|
78
|
+
*
|
79
|
+
* Get the root node for this document.
|
80
|
+
*/
|
81
|
+
static VALUE root(VALUE self)
|
82
|
+
{
|
83
|
+
xmlDocPtr doc;
|
84
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
85
|
+
|
86
|
+
xmlNodePtr root = xmlDocGetRootElement(doc);
|
87
|
+
|
88
|
+
if(!root) return Qnil;
|
89
|
+
return Nokogiri_wrap_xml_node(Qnil, root) ;
|
90
|
+
}
|
91
|
+
|
92
|
+
/*
|
93
|
+
* call-seq:
|
94
|
+
* encoding= encoding
|
95
|
+
*
|
96
|
+
* Set the encoding string for this Document
|
97
|
+
*/
|
98
|
+
static VALUE set_encoding(VALUE self, VALUE encoding)
|
99
|
+
{
|
100
|
+
xmlDocPtr doc;
|
101
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
102
|
+
|
103
|
+
doc->encoding = xmlStrdup((xmlChar *)StringValuePtr(encoding));
|
104
|
+
|
105
|
+
return encoding;
|
106
|
+
}
|
107
|
+
|
108
|
+
/*
|
109
|
+
* call-seq:
|
110
|
+
* encoding
|
111
|
+
*
|
112
|
+
* Get the encoding for this Document
|
113
|
+
*/
|
114
|
+
static VALUE encoding(VALUE self)
|
115
|
+
{
|
116
|
+
xmlDocPtr doc;
|
117
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
118
|
+
|
119
|
+
if(!doc->encoding) return Qnil;
|
120
|
+
return NOKOGIRI_STR_NEW2(doc->encoding, doc->encoding);
|
121
|
+
}
|
122
|
+
|
123
|
+
/*
|
124
|
+
* call-seq:
|
125
|
+
* read_io(io, url, encoding, options)
|
126
|
+
*
|
127
|
+
* Create a new document from an IO object
|
128
|
+
*/
|
129
|
+
static VALUE read_io( VALUE klass,
|
130
|
+
VALUE io,
|
131
|
+
VALUE url,
|
132
|
+
VALUE encoding,
|
133
|
+
VALUE options )
|
134
|
+
{
|
135
|
+
const char * c_url = (url == Qnil) ? NULL : StringValuePtr(url);
|
136
|
+
const char * c_enc = (encoding == Qnil) ? NULL : StringValuePtr(encoding);
|
137
|
+
VALUE error_list = rb_ary_new();
|
138
|
+
|
139
|
+
xmlInitParser();
|
140
|
+
xmlResetLastError();
|
141
|
+
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
142
|
+
|
143
|
+
xmlDocPtr doc = xmlReadIO(
|
144
|
+
(xmlInputReadCallback)io_read_callback,
|
145
|
+
(xmlInputCloseCallback)io_close_callback,
|
146
|
+
(void *)io,
|
147
|
+
c_url,
|
148
|
+
c_enc,
|
149
|
+
NUM2INT(options)
|
150
|
+
);
|
151
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
152
|
+
|
153
|
+
if(doc == NULL) {
|
154
|
+
xmlFreeDoc(doc);
|
155
|
+
|
156
|
+
xmlErrorPtr error = xmlGetLastError();
|
157
|
+
if(error)
|
158
|
+
rb_funcall(rb_mKernel, rb_intern("raise"), 1,
|
159
|
+
Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error)
|
160
|
+
);
|
161
|
+
else
|
162
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
163
|
+
|
164
|
+
return Qnil;
|
165
|
+
}
|
166
|
+
|
167
|
+
VALUE document = Nokogiri_wrap_xml_document(klass, doc);
|
168
|
+
rb_funcall(document, rb_intern("errors="), 1, error_list);
|
169
|
+
return document;
|
170
|
+
}
|
171
|
+
|
172
|
+
/*
|
173
|
+
* call-seq:
|
174
|
+
* read_memory(string, url, encoding, options)
|
175
|
+
*
|
176
|
+
* Create a new document from a String
|
177
|
+
*/
|
178
|
+
static VALUE read_memory( VALUE klass,
|
179
|
+
VALUE string,
|
180
|
+
VALUE url,
|
181
|
+
VALUE encoding,
|
182
|
+
VALUE options )
|
183
|
+
{
|
184
|
+
const char * c_buffer = StringValuePtr(string);
|
185
|
+
const char * c_url = (url == Qnil) ? NULL : StringValuePtr(url);
|
186
|
+
const char * c_enc = (encoding == Qnil) ? NULL : StringValuePtr(encoding);
|
187
|
+
int len = RSTRING_LEN(string);
|
188
|
+
VALUE error_list = rb_ary_new();
|
189
|
+
|
190
|
+
xmlInitParser();
|
191
|
+
xmlResetLastError();
|
192
|
+
xmlSetStructuredErrorFunc((void *)error_list, Nokogiri_error_array_pusher);
|
193
|
+
xmlDocPtr doc = xmlReadMemory(c_buffer, len, c_url, c_enc, NUM2INT(options));
|
194
|
+
xmlSetStructuredErrorFunc(NULL, NULL);
|
195
|
+
|
196
|
+
if(doc == NULL) {
|
197
|
+
xmlFreeDoc(doc);
|
198
|
+
|
199
|
+
xmlErrorPtr error = xmlGetLastError();
|
200
|
+
if(error)
|
201
|
+
rb_funcall(rb_mKernel, rb_intern("raise"), 1,
|
202
|
+
Nokogiri_wrap_xml_syntax_error((VALUE)NULL, error)
|
203
|
+
);
|
204
|
+
else
|
205
|
+
rb_raise(rb_eRuntimeError, "Could not parse document");
|
206
|
+
|
207
|
+
return Qnil;
|
208
|
+
}
|
209
|
+
|
210
|
+
VALUE document = Nokogiri_wrap_xml_document(klass, doc);
|
211
|
+
rb_funcall(document, rb_intern("errors="), 1, error_list);
|
212
|
+
return document;
|
213
|
+
}
|
214
|
+
|
215
|
+
/*
|
216
|
+
* call-seq:
|
217
|
+
* dup
|
218
|
+
*
|
219
|
+
* Copy this Document. An optional depth may be passed in, but it defaults
|
220
|
+
* to a deep copy. 0 is a shallow copy, 1 is a deep copy.
|
221
|
+
*/
|
222
|
+
static VALUE duplicate_node(int argc, VALUE *argv, VALUE self)
|
223
|
+
{
|
224
|
+
VALUE level;
|
225
|
+
|
226
|
+
if(rb_scan_args(argc, argv, "01", &level) == 0)
|
227
|
+
level = INT2NUM(1);
|
228
|
+
|
229
|
+
xmlDocPtr doc, dup;
|
230
|
+
Data_Get_Struct(self, xmlDoc, doc);
|
231
|
+
|
232
|
+
dup = xmlCopyDoc(doc, NUM2INT(level));
|
233
|
+
if(dup == NULL) return Qnil;
|
234
|
+
|
235
|
+
dup->type = doc->type;
|
236
|
+
return Nokogiri_wrap_xml_document(RBASIC(self)->klass, dup);
|
237
|
+
}
|
238
|
+
|
239
|
+
/*
|
240
|
+
* call-seq:
|
241
|
+
* new(version = default)
|
242
|
+
*
|
243
|
+
* Create a new document with +version+ (defaults to "1.0")
|
244
|
+
*/
|
245
|
+
static VALUE new(int argc, VALUE *argv, VALUE klass)
|
246
|
+
{
|
247
|
+
VALUE version, rest, rb_doc ;
|
248
|
+
|
249
|
+
rb_scan_args(argc, argv, "0*", &rest);
|
250
|
+
version = rb_ary_entry(rest, 0);
|
251
|
+
if (version == Qnil) {
|
252
|
+
version = rb_str_new2("1.0");
|
253
|
+
}
|
254
|
+
|
255
|
+
xmlDocPtr doc = xmlNewDoc((xmlChar *)StringValuePtr(version));
|
256
|
+
rb_doc = Nokogiri_wrap_xml_document(klass, doc);
|
257
|
+
rb_funcall2(rb_doc, rb_intern("initialize"), argc, argv);
|
258
|
+
return rb_doc ;
|
259
|
+
}
|
260
|
+
|
261
|
+
VALUE cNokogiriXmlDocument ;
|
262
|
+
void init_xml_document()
|
263
|
+
{
|
264
|
+
VALUE nokogiri = rb_define_module("Nokogiri");
|
265
|
+
VALUE xml = rb_define_module_under(nokogiri, "XML");
|
266
|
+
VALUE node = rb_define_class_under(xml, "Node", rb_cObject);
|
267
|
+
|
268
|
+
/*
|
269
|
+
* Nokogiri::XML::Document wraps an xml document.
|
270
|
+
*/
|
271
|
+
VALUE klass = rb_define_class_under(xml, "Document", node);
|
272
|
+
|
273
|
+
cNokogiriXmlDocument = klass;
|
274
|
+
|
275
|
+
rb_define_singleton_method(klass, "read_memory", read_memory, 4);
|
276
|
+
rb_define_singleton_method(klass, "read_io", read_io, 4);
|
277
|
+
rb_define_singleton_method(klass, "new", new, -1);
|
278
|
+
|
279
|
+
rb_define_method(klass, "root", root, 0);
|
280
|
+
rb_define_method(klass, "root=", set_root, 1);
|
281
|
+
rb_define_method(klass, "encoding", encoding, 0);
|
282
|
+
rb_define_method(klass, "encoding=", set_encoding, 1);
|
283
|
+
rb_define_method(klass, "dup", duplicate_node, -1);
|
284
|
+
rb_define_method(klass, "url", url, 0);
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
/* this takes klass as a param because it's used for HtmlDocument, too. */
|
289
|
+
VALUE Nokogiri_wrap_xml_document(VALUE klass, xmlDocPtr doc)
|
290
|
+
{
|
291
|
+
nokogiriTuplePtr tuple = (nokogiriTuplePtr)malloc(sizeof(nokogiriTuple));
|
292
|
+
|
293
|
+
VALUE rb_doc = Data_Wrap_Struct(
|
294
|
+
klass ? klass : cNokogiriXmlDocument,
|
295
|
+
0,
|
296
|
+
dealloc,
|
297
|
+
doc
|
298
|
+
);
|
299
|
+
rb_iv_set(rb_doc, "@decorators", Qnil);
|
300
|
+
rb_iv_set(rb_doc, "@node_cache", rb_ary_new());
|
301
|
+
rb_funcall(rb_doc, rb_intern("initialize"), 0);
|
302
|
+
|
303
|
+
tuple->doc = (void *)rb_doc;
|
304
|
+
tuple->unlinkedNodes = xmlXPathNodeSetCreate(NULL);
|
305
|
+
doc->_private = tuple ;
|
306
|
+
|
307
|
+
return rb_doc ;
|
308
|
+
}
|