libxml-ruby 2.2.2 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +14 -2
- data/MANIFEST +1 -0
- data/README.rdoc +2 -2
- data/ext/libxml/ruby_xml_document.c +191 -29
- data/ext/libxml/ruby_xml_document.h +1 -0
- data/ext/libxml/ruby_xml_encoding.c +21 -7
- data/ext/libxml/ruby_xml_encoding.h +1 -0
- data/ext/libxml/ruby_xml_node.c +38 -0
- data/ext/libxml/ruby_xml_sax2_handler.c +30 -34
- data/ext/libxml/ruby_xml_sax_parser.c +0 -14
- data/ext/libxml/ruby_xml_version.h +4 -4
- data/lib/libxml/document.rb +18 -16
- data/libxml-ruby.gemspec +3 -2
- data/test/c14n/given/doc.dtd +1 -0
- data/test/c14n/given/example-1.xml +14 -0
- data/test/c14n/given/example-2.xml +11 -0
- data/test/c14n/given/example-3.xml +18 -0
- data/test/c14n/given/example-4.xml +9 -0
- data/test/c14n/given/example-5.xml +12 -0
- data/test/c14n/given/example-6.xml +2 -0
- data/test/c14n/given/example-7.xml +11 -0
- data/test/c14n/given/example-8.xml +11 -0
- data/test/c14n/given/example-8.xpath +10 -0
- data/test/c14n/given/world.txt +1 -0
- data/test/c14n/result/1-1-without-comments/example-1 +4 -0
- data/test/c14n/result/1-1-without-comments/example-2 +11 -0
- data/test/c14n/result/1-1-without-comments/example-3 +14 -0
- data/test/c14n/result/1-1-without-comments/example-4 +9 -0
- data/test/c14n/result/1-1-without-comments/example-5 +3 -0
- data/test/c14n/result/1-1-without-comments/example-6 +1 -0
- data/test/c14n/result/1-1-without-comments/example-7 +1 -0
- data/test/c14n/result/1-1-without-comments/example-8 +1 -0
- data/test/c14n/result/with-comments/example-1 +6 -0
- data/test/c14n/result/with-comments/example-2 +11 -0
- data/test/c14n/result/with-comments/example-3 +14 -0
- data/test/c14n/result/with-comments/example-4 +9 -0
- data/test/c14n/result/with-comments/example-5 +4 -0
- data/test/c14n/result/with-comments/example-6 +1 -0
- data/test/c14n/result/with-comments/example-7 +1 -0
- data/test/c14n/result/without-comments/example-1 +4 -0
- data/test/c14n/result/without-comments/example-2 +11 -0
- data/test/c14n/result/without-comments/example-3 +14 -0
- data/test/c14n/result/without-comments/example-4 +9 -0
- data/test/c14n/result/without-comments/example-5 +3 -0
- data/test/c14n/result/without-comments/example-6 +1 -0
- data/test/c14n/result/without-comments/example-7 +1 -0
- data/test/tc_canonicalize.rb +125 -0
- data/test/tc_document.rb +2 -18
- data/test/tc_encoding.rb +7 -5
- data/test/tc_encoding_sax.rb +115 -0
- data/test/tc_node_pi.rb +40 -0
- data/test/tc_xpath.rb +23 -0
- data/test/test_suite.rb +7 -1
- metadata +45 -6
- data/test/new_main.rb +0 -29
@@ -30,30 +30,28 @@ const char *value, int len)
|
|
30
30
|
|
31
31
|
if (handler != Qnil)
|
32
32
|
{
|
33
|
-
rb_funcall(handler, cbidOnCdataBlock,1,
|
33
|
+
rb_funcall(handler, cbidOnCdataBlock,1, rxml_new_cstr_len(value, len, NULL));
|
34
34
|
}
|
35
35
|
}
|
36
36
|
|
37
|
-
static void characters_callback(void *ctx,
|
38
|
-
const char *chars, int len)
|
37
|
+
static void characters_callback(void *ctx, const char *chars, int len)
|
39
38
|
{
|
40
39
|
VALUE handler = (VALUE) ctx;
|
41
40
|
|
42
41
|
if (handler != Qnil)
|
43
42
|
{
|
44
|
-
VALUE rchars =
|
43
|
+
VALUE rchars = rxml_new_cstr_len(chars, len, NULL);
|
45
44
|
rb_funcall(handler, cbidOnCharacters, 1, rchars);
|
46
45
|
}
|
47
46
|
}
|
48
47
|
|
49
|
-
static void comment_callback(void *ctx,
|
50
|
-
const char *msg)
|
48
|
+
static void comment_callback(void *ctx, const char *msg)
|
51
49
|
{
|
52
50
|
VALUE handler = (VALUE) ctx;
|
53
51
|
|
54
52
|
if (handler != Qnil)
|
55
53
|
{
|
56
|
-
rb_funcall(handler, cbidOnComment,1,
|
54
|
+
rb_funcall(handler, cbidOnComment,1,rxml_new_cstr(msg, NULL));
|
57
55
|
}
|
58
56
|
}
|
59
57
|
|
@@ -81,21 +79,21 @@ static void end_element_ns_callback(void *ctx,
|
|
81
79
|
VALUE name;
|
82
80
|
if (xprefix)
|
83
81
|
{
|
84
|
-
name =
|
82
|
+
name = rxml_new_cstr(xprefix, NULL);
|
85
83
|
rb_str_cat2(name, ":");
|
86
84
|
rb_str_cat2(name, xlocalname);
|
87
85
|
}
|
88
86
|
else
|
89
87
|
{
|
90
|
-
name =
|
88
|
+
name = rxml_new_cstr(xlocalname, NULL);
|
91
89
|
}
|
92
90
|
rb_funcall(handler, cbidOnEndElement, 1, name);
|
93
91
|
}
|
94
92
|
|
95
93
|
rb_funcall(handler, cbidOnEndElementNs, 3,
|
96
|
-
|
97
|
-
xprefix ?
|
98
|
-
xURI ?
|
94
|
+
rxml_new_cstr(xlocalname, NULL),
|
95
|
+
xprefix ? rxml_new_cstr(xprefix, NULL) : Qnil,
|
96
|
+
xURI ? rxml_new_cstr(xURI, NULL) : Qnil);
|
99
97
|
}
|
100
98
|
|
101
99
|
static void external_subset_callback(void *ctx, const char *name, const char *extid, const char *sysid)
|
@@ -104,9 +102,9 @@ static void external_subset_callback(void *ctx, const char *name, const char *ex
|
|
104
102
|
|
105
103
|
if (handler != Qnil)
|
106
104
|
{
|
107
|
-
VALUE rname = name ?
|
108
|
-
VALUE rextid = extid ?
|
109
|
-
VALUE rsysid = sysid ?
|
105
|
+
VALUE rname = name ? rxml_new_cstr(name, NULL) : Qnil;
|
106
|
+
VALUE rextid = extid ? rxml_new_cstr(extid, NULL) : Qnil;
|
107
|
+
VALUE rsysid = sysid ? rxml_new_cstr(sysid, NULL) : Qnil;
|
110
108
|
rb_funcall(handler, cbidOnExternalSubset, 3, rname, rextid, rsysid);
|
111
109
|
}
|
112
110
|
}
|
@@ -137,9 +135,9 @@ static void internal_subset_callback(void *ctx, const char *name, const char *ex
|
|
137
135
|
|
138
136
|
if (handler != Qnil)
|
139
137
|
{
|
140
|
-
VALUE rname = name ?
|
141
|
-
VALUE rextid = extid ?
|
142
|
-
VALUE rsysid = sysid ?
|
138
|
+
VALUE rname = name ? rxml_new_cstr(name, NULL) : Qnil;
|
139
|
+
VALUE rextid = extid ? rxml_new_cstr(extid, NULL) : Qnil;
|
140
|
+
VALUE rsysid = sysid ? rxml_new_cstr(sysid, NULL) : Qnil;
|
143
141
|
rb_funcall(handler, cbidOnInternalSubset, 3, rname, rextid, rsysid);
|
144
142
|
}
|
145
143
|
}
|
@@ -160,8 +158,8 @@ static void processing_instruction_callback(void *ctx, const char *target, const
|
|
160
158
|
|
161
159
|
if (handler != Qnil)
|
162
160
|
{
|
163
|
-
VALUE rtarget = target ?
|
164
|
-
VALUE rdata = data ?
|
161
|
+
VALUE rtarget = target ? rxml_new_cstr(target, NULL) : Qnil;
|
162
|
+
VALUE rdata = data ? rxml_new_cstr(data, NULL) : Qnil;
|
165
163
|
rb_funcall(handler, cbidOnProcessingInstruction, 2, rtarget, rdata);
|
166
164
|
}
|
167
165
|
}
|
@@ -172,7 +170,7 @@ static void reference_callback(void *ctx, const char *name)
|
|
172
170
|
|
173
171
|
if (handler != Qnil)
|
174
172
|
{
|
175
|
-
rb_funcall(handler, cbidOnReference,1,
|
173
|
+
rb_funcall(handler, cbidOnReference,1,rxml_new_cstr(name, NULL));
|
176
174
|
}
|
177
175
|
}
|
178
176
|
|
@@ -188,8 +186,8 @@ static void start_document_callback(void *ctx)
|
|
188
186
|
|
189
187
|
static void start_element_ns_callback(void *ctx,
|
190
188
|
const xmlChar *xlocalname, const xmlChar *xprefix, const xmlChar *xURI,
|
191
|
-
|
192
|
-
|
189
|
+
int nb_namespaces, const xmlChar **xnamespaces,
|
190
|
+
int nb_attributes, int nb_defaulted, const xmlChar **xattributes)
|
193
191
|
{
|
194
192
|
VALUE handler = (VALUE) ctx;
|
195
193
|
VALUE attributes = rb_hash_new();
|
@@ -204,10 +202,8 @@ static void start_element_ns_callback(void *ctx,
|
|
204
202
|
int i;
|
205
203
|
for (i = 0;i < nb_attributes * 5; i+=5)
|
206
204
|
{
|
207
|
-
VALUE attrName =
|
208
|
-
VALUE attrValue =
|
209
|
-
/* VALUE attrPrefix = xattributes[i+1] ? rb_str_new2(xattributes[i+1]) : Qnil;
|
210
|
-
VALUE attrURI = xattributes[i+2] ? rb_str_new2(xattributes[i+2]) : Qnil; */
|
205
|
+
VALUE attrName = rxml_new_cstr(xattributes[i+0], NULL);
|
206
|
+
VALUE attrValue = rxml_new_cstr_len(xattributes[i+3], xattributes[i+4] - xattributes[i+3], NULL);
|
211
207
|
|
212
208
|
rb_hash_aset(attributes, attrName, attrValue);
|
213
209
|
}
|
@@ -218,8 +214,8 @@ static void start_element_ns_callback(void *ctx,
|
|
218
214
|
int i;
|
219
215
|
for (i = 0;i < nb_namespaces * 2; i+=2)
|
220
216
|
{
|
221
|
-
VALUE nsPrefix = xnamespaces[i+0] ?
|
222
|
-
VALUE nsURI = xnamespaces[i+1] ?
|
217
|
+
VALUE nsPrefix = xnamespaces[i+0] ? rxml_new_cstr(xnamespaces[i+0], NULL) : Qnil;
|
218
|
+
VALUE nsURI = xnamespaces[i+1] ? rxml_new_cstr(xnamespaces[i+1], NULL) : Qnil;
|
223
219
|
rb_hash_aset(namespaces, nsPrefix, nsURI);
|
224
220
|
}
|
225
221
|
}
|
@@ -230,22 +226,22 @@ static void start_element_ns_callback(void *ctx,
|
|
230
226
|
VALUE name;
|
231
227
|
if (xprefix)
|
232
228
|
{
|
233
|
-
name =
|
229
|
+
name = rxml_new_cstr(xprefix, NULL);
|
234
230
|
rb_str_cat2(name, ":");
|
235
231
|
rb_str_cat2(name, xlocalname);
|
236
232
|
}
|
237
233
|
else
|
238
234
|
{
|
239
|
-
name =
|
235
|
+
name = rxml_new_cstr(xlocalname, NULL);
|
240
236
|
}
|
241
237
|
rb_funcall(handler, cbidOnStartElement, 2, name, attributes);
|
242
238
|
}
|
243
239
|
|
244
240
|
rb_funcall(handler, cbidOnStartElementNs, 5,
|
245
|
-
|
241
|
+
rxml_new_cstr(xlocalname, NULL),
|
246
242
|
attributes,
|
247
|
-
xprefix ?
|
248
|
-
xURI ?
|
243
|
+
xprefix ? rxml_new_cstr(xprefix, NULL) : Qnil,
|
244
|
+
xURI ? rxml_new_cstr(xURI, NULL) : Qnil,
|
249
245
|
namespaces);
|
250
246
|
}
|
251
247
|
|
@@ -43,20 +43,6 @@ static ID CONTEXT_ATTR;
|
|
43
43
|
|
44
44
|
/* ====== Parser =========== */
|
45
45
|
|
46
|
-
/*static int rxml_sax_parser_parse_io(VALUE self, VALUE input)
|
47
|
-
{
|
48
|
-
VALUE handler = rb_ivar_get(self, CALLBACKS_ATTR);
|
49
|
-
VALUE io = rb_ivar_get(input, IO_ATTR);
|
50
|
-
VALUE encoding = rb_ivar_get(input, ENCODING_ATTR);
|
51
|
-
xmlCharEncoding xmlEncoding = NUM2INT(encoding);
|
52
|
-
xmlParserCtxtPtr ctxt =
|
53
|
-
xmlCreateIOParserCtxt((xmlSAXHandlerPtr) &rxml_sax_handler,
|
54
|
-
(void *) handler, (xmlInputReadCallback) rxml_read_callback, NULL,
|
55
|
-
(void *) io, xmlEncoding);
|
56
|
-
return xmlParseDocument(ctxt);
|
57
|
-
}*/
|
58
|
-
|
59
|
-
|
60
46
|
/*
|
61
47
|
* call-seq:
|
62
48
|
* parser.initialize(context) -> XML::Parser
|
@@ -1,9 +1,9 @@
|
|
1
1
|
/* Don't nuke this block! It is used for automatically updating the
|
2
2
|
* versions below. VERSION = string formatting, VERNUM = numbered
|
3
3
|
* version for inline testing: increment both or none at all.*/
|
4
|
-
#define RUBY_LIBXML_VERSION "2.
|
5
|
-
#define RUBY_LIBXML_VERNUM
|
4
|
+
#define RUBY_LIBXML_VERSION "2.3.0"
|
5
|
+
#define RUBY_LIBXML_VERNUM 230
|
6
6
|
#define RUBY_LIBXML_VER_MAJ 2
|
7
|
-
#define RUBY_LIBXML_VER_MIN
|
8
|
-
#define RUBY_LIBXML_VER_MIC
|
7
|
+
#define RUBY_LIBXML_VER_MIN 3
|
8
|
+
#define RUBY_LIBXML_VER_MIC 0
|
9
9
|
#define RUBY_LIBXML_VER_PATCH 0
|
data/lib/libxml/document.rb
CHANGED
@@ -56,7 +56,7 @@ module LibXML
|
|
56
56
|
end
|
57
57
|
|
58
58
|
# call-seq:
|
59
|
-
# XML::Document.string(string)
|
59
|
+
# XML::Document.string(string) -> XML::Document
|
60
60
|
# XML::Document.string(string, :encoding => XML::Encoding::UTF_8,
|
61
61
|
# :options => XML::Parser::Options::NOENT
|
62
62
|
# :base_uri="http://libxml.org") -> XML::Document
|
@@ -66,12 +66,12 @@ module LibXML
|
|
66
66
|
# You may provide an optional hash table to control how the
|
67
67
|
# parsing is performed. Valid options are:
|
68
68
|
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
69
|
+
# base_uri - The base url for the parsed document.
|
70
|
+
# encoding - The document encoding, defaults to nil. Valid values
|
71
|
+
# are the encoding constants defined on XML::Encoding.
|
72
|
+
# options - Parser options. Valid values are the constants defined on
|
73
|
+
# XML::Parser::Options. Mutliple options can be combined
|
74
|
+
# by using Bitwise OR (|).
|
75
75
|
def self.string(value, options = {})
|
76
76
|
Parser.string(value, options).parse
|
77
77
|
end
|
@@ -94,11 +94,13 @@ module LibXML
|
|
94
94
|
# optionally using the specified namespace. For more
|
95
95
|
# information about working with namespaces, please refer
|
96
96
|
# to the XML::XPath documentation.
|
97
|
+
#
|
98
|
+
# call-seq:
|
99
|
+
# document.find(xpath, nslist=nil) -> XML::XPath::Object
|
97
100
|
#
|
98
101
|
# Parameters:
|
99
102
|
# * xpath - The xpath expression as a string
|
100
103
|
# * namespaces - An optional list of namespaces (see XML::XPath for information).
|
101
|
-
# * Returns - XML::XPath::Object
|
102
104
|
#
|
103
105
|
# document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
|
104
106
|
#
|
@@ -131,14 +133,14 @@ module LibXML
|
|
131
133
|
# Returns this node's type name
|
132
134
|
def node_type_name
|
133
135
|
case node_type
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
136
|
+
when XML::Node::DOCUMENT_NODE
|
137
|
+
'document_xml'
|
138
|
+
when XML::Node::DOCB_DOCUMENT_NODE
|
139
|
+
'document_docbook'
|
140
|
+
when XML::Node::HTML_DOCUMENT_NODE
|
141
|
+
'document_html'
|
142
|
+
else
|
143
|
+
raise(UnknownType, "Unknown node type: %n", node.node_type);
|
142
144
|
end
|
143
145
|
end
|
144
146
|
# :enddoc:
|
data/libxml-ruby.gemspec
CHANGED
@@ -16,7 +16,8 @@ Gem::Specification.new do |spec|
|
|
16
16
|
by the informal benchmark below.
|
17
17
|
EOS
|
18
18
|
spec.authors = ['Ross Bamform', 'Wai-Sun Chia', 'Sean Chittenden',
|
19
|
-
'Dan Janwoski', 'Anurag Priyam', 'Charlie Savage'
|
19
|
+
'Dan Janwoski', 'Anurag Priyam', 'Charlie Savage',
|
20
|
+
'Ryan Johnson']
|
20
21
|
spec.platform = Gem::Platform::RUBY
|
21
22
|
spec.bindir = "bin"
|
22
23
|
spec.extensions = ["ext/libxml/extconf.rb"]
|
@@ -39,4 +40,4 @@ Gem::Specification.new do |spec|
|
|
39
40
|
spec.test_files = Dir.glob("test/tc_*.rb")
|
40
41
|
spec.required_ruby_version = '>= 1.8.6'
|
41
42
|
spec.date = DateTime.now
|
42
|
-
end
|
43
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<!-- Empty DTD -->
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<!DOCTYPE doc [<!ATTLIST e9 attr CDATA "default">]>
|
2
|
+
<doc>
|
3
|
+
<e1 />
|
4
|
+
<e2 ></e2>
|
5
|
+
<e3 name = "elem3" id="elem3" />
|
6
|
+
<e4 name="elem4" id="elem4" ></e4>
|
7
|
+
<e5 a:attr="out" b:attr="sorted" attr2="all" attr="I'm"
|
8
|
+
xmlns:b="http://www.ietf.org"
|
9
|
+
xmlns:a="http://www.w3.org"
|
10
|
+
xmlns="http://www.uvic.ca"/>
|
11
|
+
<e6 xmlns="" xmlns:a="http://www.w3.org">
|
12
|
+
<e7 xmlns="http://www.ietf.org">
|
13
|
+
<e8 xmlns="" xmlns:a="http://www.w3.org">
|
14
|
+
<e9 xmlns="" xmlns:a="http://www.ietf.org" attr="default"/>
|
15
|
+
</e8>
|
16
|
+
</e7>
|
17
|
+
</e6>
|
18
|
+
</doc>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<!DOCTYPE doc [<!ATTLIST normId id ID #IMPLIED>]>
|
2
|
+
<doc>
|
3
|
+
<text>First line
 Second line</text>
|
4
|
+
<value>2</value>
|
5
|
+
<compute><![CDATA[value>"0" && value<"10" ?"valid":"error"]]></compute>
|
6
|
+
<compute expr='value>"0" && value<"10" ?"valid":"error"'>valid</compute>
|
7
|
+
<norm attr=' '   
	 ' '/>
|
8
|
+
<normId id=' '   
	 ' '/>
|
9
|
+
</doc>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<!DOCTYPE doc [
|
2
|
+
<!ATTLIST doc attrExtEnt ENTITY #IMPLIED>
|
3
|
+
<!ENTITY ent1 "Hello">
|
4
|
+
<!ENTITY ent2 SYSTEM "world.txt">
|
5
|
+
<!ENTITY entExt SYSTEM "earth.gif" NDATA gif>
|
6
|
+
<!NOTATION gif SYSTEM "viewgif.exe">
|
7
|
+
]>
|
8
|
+
<doc attrExtEnt="entExt">
|
9
|
+
&ent1;, &ent2;!
|
10
|
+
</doc>
|
11
|
+
|
12
|
+
<!-- Let world.txt contain "world" (excluding the quotes) -->
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<!DOCTYPE doc [
|
2
|
+
<!ATTLIST e2 xml:space (default|preserve) 'preserve'>
|
3
|
+
<!ATTLIST e3 id ID #IMPLIED>
|
4
|
+
]>
|
5
|
+
<doc xmlns="http://www.ietf.org" xmlns:w3c="http://www.w3.org" xml:base="something/else">
|
6
|
+
<e1>
|
7
|
+
<e2 xmlns="" xml:id="abc" xml:base="bar/">
|
8
|
+
<e3 id="E3" xml:base="foo"/>
|
9
|
+
</e2>
|
10
|
+
</e1>
|
11
|
+
</doc>
|
@@ -0,0 +1 @@
|
|
1
|
+
world
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<doc>
|
2
|
+
<e1></e1>
|
3
|
+
<e2></e2>
|
4
|
+
<e3 id="elem3" name="elem3"></e3>
|
5
|
+
<e4 id="elem4" name="elem4"></e4>
|
6
|
+
<e5 xmlns="http://www.uvic.ca" xmlns:a="http://www.w3.org" xmlns:b="http://www.ietf.org" attr="I'm" attr2="all" b:attr="sorted" a:attr="out"></e5>
|
7
|
+
<e6 xmlns:a="http://www.w3.org">
|
8
|
+
<e7 xmlns="http://www.ietf.org">
|
9
|
+
<e8 xmlns="">
|
10
|
+
<e9 xmlns:a="http://www.ietf.org" attr="default"></e9>
|
11
|
+
</e8>
|
12
|
+
</e7>
|
13
|
+
</e6>
|
14
|
+
</doc>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<doc>
|
2
|
+
<text>First line
|
3
|
+
Second line</text>
|
4
|
+
<value>2</value>
|
5
|
+
<compute>value>"0" && value<"10" ?"valid":"error"</compute>
|
6
|
+
<compute expr="value>"0" && value<"10" ?"valid":"error"">valid</compute>
|
7
|
+
<norm attr=" ' 
	 ' "></norm>
|
8
|
+
<normId id="' 
	 '"></normId>
|
9
|
+
</doc>
|