libxml-ruby 2.9.0 → 3.0.0
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/HISTORY +811 -790
- data/LICENSE +20 -20
- data/MANIFEST +166 -166
- data/README.rdoc +188 -184
- data/Rakefile +1 -1
- data/ext/libxml/libxml.c +80 -80
- data/ext/libxml/ruby_libxml.h +75 -75
- data/ext/libxml/ruby_xml.c +0 -84
- data/ext/libxml/ruby_xml.h +0 -10
- data/ext/libxml/ruby_xml_attr.h +12 -12
- data/ext/libxml/ruby_xml_attr_decl.c +153 -153
- data/ext/libxml/ruby_xml_attr_decl.h +11 -11
- data/ext/libxml/ruby_xml_attributes.c +275 -275
- data/ext/libxml/ruby_xml_attributes.h +15 -15
- data/ext/libxml/ruby_xml_document.c +21 -27
- data/ext/libxml/ruby_xml_document.h +11 -11
- data/ext/libxml/ruby_xml_dtd.c +2 -13
- data/ext/libxml/ruby_xml_dtd.h +9 -9
- data/ext/libxml/ruby_xml_error.c +996 -996
- data/ext/libxml/ruby_xml_error.h +12 -12
- data/ext/libxml/ruby_xml_html_parser.c +89 -92
- data/ext/libxml/ruby_xml_html_parser.h +10 -10
- data/ext/libxml/ruby_xml_html_parser_context.h +10 -10
- data/ext/libxml/ruby_xml_html_parser_options.c +46 -46
- data/ext/libxml/ruby_xml_html_parser_options.h +10 -10
- data/ext/libxml/ruby_xml_input_cbg.h +20 -20
- data/ext/libxml/ruby_xml_io.c +0 -1
- data/ext/libxml/ruby_xml_io.h +10 -10
- data/ext/libxml/ruby_xml_namespace.c +153 -153
- data/ext/libxml/ruby_xml_namespace.h +10 -10
- data/ext/libxml/ruby_xml_namespaces.c +293 -293
- data/ext/libxml/ruby_xml_namespaces.h +9 -9
- data/ext/libxml/ruby_xml_node.c +100 -143
- data/ext/libxml/ruby_xml_node.h +13 -11
- data/ext/libxml/ruby_xml_parser.c +91 -94
- data/ext/libxml/ruby_xml_parser.h +12 -12
- data/ext/libxml/ruby_xml_parser_context.h +10 -10
- data/ext/libxml/ruby_xml_parser_options.c +66 -66
- data/ext/libxml/ruby_xml_parser_options.h +12 -12
- data/ext/libxml/ruby_xml_reader.c +45 -37
- data/ext/libxml/ruby_xml_reader.h +17 -17
- data/ext/libxml/ruby_xml_relaxng.h +10 -10
- data/ext/libxml/ruby_xml_sax2_handler.c +3 -3
- data/ext/libxml/ruby_xml_sax2_handler.h +10 -10
- data/ext/libxml/ruby_xml_sax_parser.c +116 -120
- data/ext/libxml/ruby_xml_sax_parser.h +10 -10
- data/ext/libxml/ruby_xml_schema.h +809 -809
- data/ext/libxml/ruby_xml_schema_attribute.c +109 -109
- data/ext/libxml/ruby_xml_schema_attribute.h +15 -15
- data/ext/libxml/ruby_xml_schema_element.c +94 -94
- data/ext/libxml/ruby_xml_schema_element.h +14 -14
- data/ext/libxml/ruby_xml_schema_facet.c +52 -52
- data/ext/libxml/ruby_xml_schema_facet.h +13 -13
- data/ext/libxml/ruby_xml_schema_type.c +259 -259
- data/ext/libxml/ruby_xml_schema_type.h +9 -9
- data/ext/libxml/ruby_xml_version.h +9 -9
- data/ext/libxml/ruby_xml_writer.c +1136 -1136
- data/ext/libxml/ruby_xml_writer.h +10 -10
- data/ext/libxml/ruby_xml_xinclude.c +16 -16
- data/ext/libxml/ruby_xml_xinclude.h +11 -11
- data/ext/libxml/ruby_xml_xpath.c +42 -36
- data/ext/libxml/ruby_xml_xpath.h +13 -13
- data/ext/libxml/ruby_xml_xpath_context.c +1 -1
- data/ext/libxml/ruby_xml_xpath_context.h +9 -9
- data/ext/libxml/ruby_xml_xpath_expression.c +81 -81
- data/ext/libxml/ruby_xml_xpath_expression.h +10 -10
- data/ext/libxml/ruby_xml_xpath_object.c +5 -2
- data/ext/libxml/ruby_xml_xpath_object.h +17 -17
- data/ext/libxml/ruby_xml_xpointer.c +99 -99
- data/ext/libxml/ruby_xml_xpointer.h +11 -11
- data/ext/vc/libxml_ruby.sln +17 -15
- data/lib/libxml.rb +1 -6
- data/lib/libxml/node.rb +2 -78
- data/lib/libxml/parser.rb +0 -266
- data/lib/libxml/sax_parser.rb +0 -17
- data/lib/libxml/schema.rb +66 -66
- data/lib/libxml/schema/attribute.rb +19 -19
- data/lib/libxml/schema/element.rb +27 -27
- data/lib/libxml/schema/type.rb +29 -29
- data/script/benchmark/depixelate +634 -634
- data/script/benchmark/hamlet.xml +9054 -9054
- data/script/benchmark/parsecount +170 -170
- data/script/benchmark/throughput +41 -41
- data/script/test +6 -6
- data/test/c14n/given/example-1.xml +14 -14
- data/test/c14n/given/example-2.xml +11 -11
- data/test/c14n/given/example-3.xml +18 -18
- data/test/c14n/given/example-4.xml +9 -9
- data/test/c14n/given/example-5.xml +12 -12
- data/test/c14n/given/example-6.xml +2 -2
- data/test/c14n/given/example-7.xml +11 -11
- data/test/c14n/given/example-8.xml +11 -11
- data/test/c14n/given/example-8.xpath +9 -9
- data/test/c14n/result/1-1-without-comments/example-1 +3 -3
- data/test/c14n/result/1-1-without-comments/example-2 +10 -10
- data/test/c14n/result/1-1-without-comments/example-3 +13 -13
- data/test/c14n/result/1-1-without-comments/example-4 +8 -8
- data/test/c14n/result/1-1-without-comments/example-5 +2 -2
- data/test/c14n/result/with-comments/example-1 +5 -5
- data/test/c14n/result/with-comments/example-2 +10 -10
- data/test/c14n/result/with-comments/example-3 +13 -13
- data/test/c14n/result/with-comments/example-4 +8 -8
- data/test/c14n/result/with-comments/example-5 +3 -3
- data/test/c14n/result/without-comments/example-1 +3 -3
- data/test/c14n/result/without-comments/example-2 +10 -10
- data/test/c14n/result/without-comments/example-3 +13 -13
- data/test/c14n/result/without-comments/example-4 +8 -8
- data/test/c14n/result/without-comments/example-5 +2 -2
- data/test/model/atom.xml +12 -12
- data/test/model/bands.iso-8859-1.xml +4 -4
- data/test/model/bands.utf-8.xml +4 -4
- data/test/model/bands.xml +4 -4
- data/test/model/books.xml +153 -153
- data/test/model/merge_bug_data.xml +58 -58
- data/test/model/ruby-lang.html +238 -238
- data/test/model/rubynet.xml +79 -79
- data/test/model/shiporder.rnc +28 -28
- data/test/model/shiporder.rng +86 -86
- data/test/model/shiporder.xml +22 -22
- data/test/model/shiporder.xsd +39 -39
- data/test/model/soap.xml +27 -27
- data/test/model/xinclude.xml +4 -4
- data/test/tc_attributes.rb +0 -6
- data/test/tc_error.rb +157 -158
- data/test/tc_node.rb +33 -17
- data/test/tc_node_edit.rb +0 -15
- data/test/tc_node_pi.rb +39 -39
- data/test/tc_parser.rb +0 -48
- data/test/tc_reader.rb +12 -53
- data/test/tc_writer.rb +447 -447
- data/test/tc_xpath.rb +1 -1
- data/test/test_helper.rb +2 -2
- metadata +3 -8
- data/ext/libxml/extconf.h +0 -4
- data/lib/libxml/ns.rb +0 -22
- data/lib/libxml/properties.rb +0 -23
- data/lib/libxml/reader.rb +0 -29
- data/lib/libxml/xpath_object.rb +0 -16
@@ -1,10 +1,10 @@
|
|
1
|
-
#ifndef __RXML_WRITER__
|
2
|
-
#define __RXML_WRITER__
|
3
|
-
|
4
|
-
#ifdef LIBXML_WRITER_ENABLED
|
5
|
-
#include <libxml/xmlwriter.h>
|
6
|
-
#endif
|
7
|
-
|
8
|
-
extern VALUE cXMLWriter;
|
9
|
-
void rxml_init_writer(void);
|
10
|
-
#endif
|
1
|
+
#ifndef __RXML_WRITER__
|
2
|
+
#define __RXML_WRITER__
|
3
|
+
|
4
|
+
#ifdef LIBXML_WRITER_ENABLED
|
5
|
+
#include <libxml/xmlwriter.h>
|
6
|
+
#endif
|
7
|
+
|
8
|
+
extern VALUE cXMLWriter;
|
9
|
+
void rxml_init_writer(void);
|
10
|
+
#endif
|
@@ -1,16 +1,16 @@
|
|
1
|
-
#include "ruby_libxml.h"
|
2
|
-
#include "ruby_xml_xinclude.h"
|
3
|
-
|
4
|
-
VALUE cXMLXInclude;
|
5
|
-
|
6
|
-
/*
|
7
|
-
* Document-class: LibXML::XML::XInclude
|
8
|
-
*
|
9
|
-
* The ruby bindings do not currently expose libxml's
|
10
|
-
* XInclude fuctionality.
|
11
|
-
*/
|
12
|
-
|
13
|
-
void rxml_init_xinclude(void)
|
14
|
-
{
|
15
|
-
cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
|
16
|
-
}
|
1
|
+
#include "ruby_libxml.h"
|
2
|
+
#include "ruby_xml_xinclude.h"
|
3
|
+
|
4
|
+
VALUE cXMLXInclude;
|
5
|
+
|
6
|
+
/*
|
7
|
+
* Document-class: LibXML::XML::XInclude
|
8
|
+
*
|
9
|
+
* The ruby bindings do not currently expose libxml's
|
10
|
+
* XInclude fuctionality.
|
11
|
+
*/
|
12
|
+
|
13
|
+
void rxml_init_xinclude(void)
|
14
|
+
{
|
15
|
+
cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
|
16
|
+
}
|
@@ -1,11 +1,11 @@
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
-
|
3
|
-
#ifndef __RXML_XINCLUDE__
|
4
|
-
#define __RXML_XINCLUDE__
|
5
|
-
|
6
|
-
extern VALUE cXMLXInclude;
|
7
|
-
extern VALUE eXMLXIncludeError;
|
8
|
-
|
9
|
-
void rxml_init_xinclude(void);
|
10
|
-
|
11
|
-
#endif
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RXML_XINCLUDE__
|
4
|
+
#define __RXML_XINCLUDE__
|
5
|
+
|
6
|
+
extern VALUE cXMLXInclude;
|
7
|
+
extern VALUE eXMLXIncludeError;
|
8
|
+
|
9
|
+
void rxml_init_xinclude(void);
|
10
|
+
|
11
|
+
#endif
|
data/ext/libxml/ruby_xml_xpath.c
CHANGED
@@ -74,17 +74,17 @@
|
|
74
74
|
* ['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
|
75
75
|
*/
|
76
76
|
|
77
|
-
|
78
77
|
#include "ruby_libxml.h"
|
79
78
|
|
80
79
|
VALUE mXPath;
|
81
80
|
|
82
|
-
VALUE
|
83
|
-
|
81
|
+
VALUE rxml_xpath_to_value(xmlXPathContextPtr xctxt, xmlXPathObjectPtr xobject)
|
82
|
+
{
|
84
83
|
VALUE result;
|
85
84
|
int type;
|
86
85
|
|
87
|
-
if (xobject == NULL)
|
86
|
+
if (xobject == NULL)
|
87
|
+
{
|
88
88
|
/* xmlLastError is different than xctxt->lastError. Use
|
89
89
|
xmlLastError since it has the message set while xctxt->lastError
|
90
90
|
does not. */
|
@@ -92,7 +92,8 @@ rxml_xpath_to_value(xmlXPathContextPtr xctxt, xmlXPathObjectPtr xobject) {
|
|
92
92
|
rxml_raise(xerror);
|
93
93
|
}
|
94
94
|
|
95
|
-
switch (type = xobject->type)
|
95
|
+
switch (type = xobject->type)
|
96
|
+
{
|
96
97
|
case XPATH_NODESET:
|
97
98
|
result = rxml_xpath_object_wrap(xctxt->doc, xobject);
|
98
99
|
break;
|
@@ -118,44 +119,49 @@ rxml_xpath_to_value(xmlXPathContextPtr xctxt, xmlXPathObjectPtr xobject) {
|
|
118
119
|
return result;
|
119
120
|
}
|
120
121
|
|
121
|
-
xmlXPathObjectPtr
|
122
|
-
|
122
|
+
xmlXPathObjectPtr rxml_xpath_from_value(VALUE value)
|
123
|
+
{
|
123
124
|
xmlXPathObjectPtr result = NULL;
|
124
125
|
|
125
|
-
switch (TYPE(value))
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
126
|
+
switch (TYPE(value))
|
127
|
+
{
|
128
|
+
case T_TRUE:
|
129
|
+
case T_FALSE:
|
130
|
+
result = xmlXPathNewBoolean(RTEST(value));
|
131
|
+
break;
|
132
|
+
case T_FIXNUM:
|
133
|
+
case T_FLOAT:
|
134
|
+
result = xmlXPathNewFloat(NUM2DBL(value));
|
135
|
+
break;
|
136
|
+
case T_STRING:
|
137
|
+
result = xmlXPathWrapString(xmlStrdup((const xmlChar *)StringValuePtr(value)));
|
138
|
+
break;
|
139
|
+
case T_NIL:
|
140
|
+
result = xmlXPathNewNodeSet(NULL);
|
141
|
+
break;
|
142
|
+
case T_ARRAY:
|
143
|
+
{
|
144
|
+
long i, j;
|
145
|
+
result = xmlXPathNewNodeSet(NULL);
|
143
146
|
|
144
|
-
|
145
|
-
|
147
|
+
for (i = RARRAY_LEN(value); i > 0; i--)
|
148
|
+
{
|
149
|
+
xmlXPathObjectPtr obj = rxml_xpath_from_value(rb_ary_shift(value));
|
146
150
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
+
if ((obj->nodesetval != NULL) && (obj->nodesetval->nodeNr != 0))
|
152
|
+
{
|
153
|
+
for (j = 0; j < obj->nodesetval->nodeNr; j++)
|
154
|
+
{
|
155
|
+
xmlXPathNodeSetAdd(result->nodesetval, obj->nodesetval->nodeTab[j]);
|
151
156
|
}
|
152
157
|
}
|
153
|
-
break;
|
154
158
|
}
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
+
break;
|
160
|
+
}
|
161
|
+
default:
|
162
|
+
rb_raise(rb_eTypeError,
|
163
|
+
"can't convert object of type %s to XPath object", rb_obj_classname(value)
|
164
|
+
);
|
159
165
|
}
|
160
166
|
|
161
167
|
return result;
|
data/ext/libxml/ruby_xml_xpath.h
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
-
|
3
|
-
#ifndef __RXML_XPATH__
|
4
|
-
#define __RXML_XPATH__
|
5
|
-
|
6
|
-
extern VALUE mXPath;
|
7
|
-
|
8
|
-
void rxml_init_xpath(void);
|
9
|
-
|
10
|
-
VALUE rxml_xpath_to_value(xmlXPathContextPtr, xmlXPathObjectPtr);
|
11
|
-
xmlXPathObjectPtr rxml_xpath_from_value(VALUE);
|
12
|
-
|
13
|
-
#endif
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RXML_XPATH__
|
4
|
+
#define __RXML_XPATH__
|
5
|
+
|
6
|
+
extern VALUE mXPath;
|
7
|
+
|
8
|
+
void rxml_init_xpath(void);
|
9
|
+
|
10
|
+
VALUE rxml_xpath_to_value(xmlXPathContextPtr, xmlXPathObjectPtr);
|
11
|
+
xmlXPathObjectPtr rxml_xpath_from_value(VALUE);
|
12
|
+
|
13
|
+
#endif
|
@@ -1,9 +1,9 @@
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
-
|
3
|
-
#ifndef __RXML_XPATH_CONTEXT__
|
4
|
-
#define __RXML_XPATH_CONTEXT__
|
5
|
-
|
6
|
-
extern VALUE cXMLXPathContext;
|
7
|
-
void rxml_init_xpath_context(void);
|
8
|
-
|
9
|
-
#endif
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RXML_XPATH_CONTEXT__
|
4
|
+
#define __RXML_XPATH_CONTEXT__
|
5
|
+
|
6
|
+
extern VALUE cXMLXPathContext;
|
7
|
+
void rxml_init_xpath_context(void);
|
8
|
+
|
9
|
+
#endif
|
@@ -1,81 +1,81 @@
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
-
|
3
|
-
#include "ruby_libxml.h"
|
4
|
-
#include "ruby_xml_xpath.h"
|
5
|
-
#include "ruby_xml_xpath_expression.h"
|
6
|
-
|
7
|
-
/*
|
8
|
-
* Document-class: LibXML::XML::XPath::Expression
|
9
|
-
*
|
10
|
-
* The XML::XPath::Expression class is used to compile
|
11
|
-
* XPath expressions so they can be parsed only once
|
12
|
-
* but reused multiple times.
|
13
|
-
*
|
14
|
-
* doc = XML::Document.string(IO.read('some xml file'))
|
15
|
-
* expr = XPath::Expression.new('//first')
|
16
|
-
* doc.root.each do |node|
|
17
|
-
* result = node.find(expr) # many, many, many times
|
18
|
-
* # ...
|
19
|
-
* end
|
20
|
-
*/
|
21
|
-
|
22
|
-
VALUE cXMLXPathExpression;
|
23
|
-
|
24
|
-
static void rxml_xpath_expression_free(xmlXPathCompExprPtr expr)
|
25
|
-
{
|
26
|
-
xmlXPathFreeCompExpr(expr);
|
27
|
-
}
|
28
|
-
|
29
|
-
static VALUE rxml_xpath_expression_alloc(VALUE klass)
|
30
|
-
{
|
31
|
-
return Data_Wrap_Struct(cXMLXPathExpression, NULL,
|
32
|
-
rxml_xpath_expression_free, NULL);
|
33
|
-
}
|
34
|
-
|
35
|
-
/* call-seq:
|
36
|
-
* XPath::Expression.compile(expression) -> XPath::Expression
|
37
|
-
*
|
38
|
-
* Compiles an XPatch expression. This improves performance
|
39
|
-
* when an XPath expression is called multiple times.
|
40
|
-
*
|
41
|
-
* doc = XML::Document.string('<header><first>hi</first></header>')
|
42
|
-
* expr = XPath::Expression.new('//first')
|
43
|
-
* nodes = doc.find(expr)
|
44
|
-
*/
|
45
|
-
static VALUE rxml_xpath_expression_compile(VALUE klass, VALUE expression)
|
46
|
-
{
|
47
|
-
VALUE args[] = {expression};
|
48
|
-
return rb_class_new_instance(1, args, cXMLXPathExpression);
|
49
|
-
}
|
50
|
-
|
51
|
-
/* call-seq:
|
52
|
-
* XPath::Expression.new(expression) -> XPath::Expression
|
53
|
-
*
|
54
|
-
* Compiles an XPatch expression. This improves performance
|
55
|
-
* when an XPath expression is called multiple times.
|
56
|
-
*
|
57
|
-
* doc = XML::Document.string('<header><first>hi</first></header>')
|
58
|
-
* expr = XPath::Expression.new('//first')
|
59
|
-
* nodes = doc.find(expr)
|
60
|
-
*/
|
61
|
-
static VALUE rxml_xpath_expression_initialize(VALUE self, VALUE expression)
|
62
|
-
{
|
63
|
-
xmlXPathCompExprPtr compexpr = xmlXPathCompile((const xmlChar*)StringValueCStr(expression));
|
64
|
-
|
65
|
-
if (compexpr == NULL)
|
66
|
-
{
|
67
|
-
xmlErrorPtr xerror = xmlGetLastError();
|
68
|
-
rxml_raise(xerror);
|
69
|
-
}
|
70
|
-
|
71
|
-
DATA_PTR( self) = compexpr;
|
72
|
-
return self;
|
73
|
-
}
|
74
|
-
|
75
|
-
void rxml_init_xpath_expression(void)
|
76
|
-
{
|
77
|
-
cXMLXPathExpression = rb_define_class_under(mXPath, "Expression", rb_cObject);
|
78
|
-
rb_define_alloc_func(cXMLXPathExpression, rxml_xpath_expression_alloc);
|
79
|
-
rb_define_singleton_method(cXMLXPathExpression, "compile", rxml_xpath_expression_compile, 1);
|
80
|
-
rb_define_method(cXMLXPathExpression, "initialize", rxml_xpath_expression_initialize, 1);
|
81
|
-
}
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#include "ruby_libxml.h"
|
4
|
+
#include "ruby_xml_xpath.h"
|
5
|
+
#include "ruby_xml_xpath_expression.h"
|
6
|
+
|
7
|
+
/*
|
8
|
+
* Document-class: LibXML::XML::XPath::Expression
|
9
|
+
*
|
10
|
+
* The XML::XPath::Expression class is used to compile
|
11
|
+
* XPath expressions so they can be parsed only once
|
12
|
+
* but reused multiple times.
|
13
|
+
*
|
14
|
+
* doc = XML::Document.string(IO.read('some xml file'))
|
15
|
+
* expr = XPath::Expression.new('//first')
|
16
|
+
* doc.root.each do |node|
|
17
|
+
* result = node.find(expr) # many, many, many times
|
18
|
+
* # ...
|
19
|
+
* end
|
20
|
+
*/
|
21
|
+
|
22
|
+
VALUE cXMLXPathExpression;
|
23
|
+
|
24
|
+
static void rxml_xpath_expression_free(xmlXPathCompExprPtr expr)
|
25
|
+
{
|
26
|
+
xmlXPathFreeCompExpr(expr);
|
27
|
+
}
|
28
|
+
|
29
|
+
static VALUE rxml_xpath_expression_alloc(VALUE klass)
|
30
|
+
{
|
31
|
+
return Data_Wrap_Struct(cXMLXPathExpression, NULL,
|
32
|
+
rxml_xpath_expression_free, NULL);
|
33
|
+
}
|
34
|
+
|
35
|
+
/* call-seq:
|
36
|
+
* XPath::Expression.compile(expression) -> XPath::Expression
|
37
|
+
*
|
38
|
+
* Compiles an XPatch expression. This improves performance
|
39
|
+
* when an XPath expression is called multiple times.
|
40
|
+
*
|
41
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
42
|
+
* expr = XPath::Expression.new('//first')
|
43
|
+
* nodes = doc.find(expr)
|
44
|
+
*/
|
45
|
+
static VALUE rxml_xpath_expression_compile(VALUE klass, VALUE expression)
|
46
|
+
{
|
47
|
+
VALUE args[] = {expression};
|
48
|
+
return rb_class_new_instance(1, args, cXMLXPathExpression);
|
49
|
+
}
|
50
|
+
|
51
|
+
/* call-seq:
|
52
|
+
* XPath::Expression.new(expression) -> XPath::Expression
|
53
|
+
*
|
54
|
+
* Compiles an XPatch expression. This improves performance
|
55
|
+
* when an XPath expression is called multiple times.
|
56
|
+
*
|
57
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
58
|
+
* expr = XPath::Expression.new('//first')
|
59
|
+
* nodes = doc.find(expr)
|
60
|
+
*/
|
61
|
+
static VALUE rxml_xpath_expression_initialize(VALUE self, VALUE expression)
|
62
|
+
{
|
63
|
+
xmlXPathCompExprPtr compexpr = xmlXPathCompile((const xmlChar*)StringValueCStr(expression));
|
64
|
+
|
65
|
+
if (compexpr == NULL)
|
66
|
+
{
|
67
|
+
xmlErrorPtr xerror = xmlGetLastError();
|
68
|
+
rxml_raise(xerror);
|
69
|
+
}
|
70
|
+
|
71
|
+
DATA_PTR( self) = compexpr;
|
72
|
+
return self;
|
73
|
+
}
|
74
|
+
|
75
|
+
void rxml_init_xpath_expression(void)
|
76
|
+
{
|
77
|
+
cXMLXPathExpression = rb_define_class_under(mXPath, "Expression", rb_cObject);
|
78
|
+
rb_define_alloc_func(cXMLXPathExpression, rxml_xpath_expression_alloc);
|
79
|
+
rb_define_singleton_method(cXMLXPathExpression, "compile", rxml_xpath_expression_compile, 1);
|
80
|
+
rb_define_method(cXMLXPathExpression, "initialize", rxml_xpath_expression_initialize, 1);
|
81
|
+
}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
-
|
3
|
-
#ifndef __RXML_XPATH_EXPRESSION__
|
4
|
-
#define __RXML_XPATH_EXPRESSION__
|
5
|
-
|
6
|
-
extern VALUE cXMLXPathExpression;
|
7
|
-
|
8
|
-
void rxml_init_xpath_expression(void);
|
9
|
-
|
10
|
-
#endif
|
1
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
2
|
+
|
3
|
+
#ifndef __RXML_XPATH_EXPRESSION__
|
4
|
+
#define __RXML_XPATH_EXPRESSION__
|
5
|
+
|
6
|
+
extern VALUE cXMLXPathExpression;
|
7
|
+
|
8
|
+
void rxml_init_xpath_expression(void);
|
9
|
+
|
10
|
+
#endif
|
@@ -50,7 +50,7 @@ static void rxml_xpath_namespace_free(xmlNsPtr xns)
|
|
50
50
|
|
51
51
|
static void rxml_xpath_object_mark(rxml_xpath_object *rxpop)
|
52
52
|
{
|
53
|
-
VALUE doc =
|
53
|
+
VALUE doc = (VALUE)rxpop->xdoc->_private;
|
54
54
|
rb_gc_mark(doc);
|
55
55
|
rb_gc_mark(rxpop->nsnodes);
|
56
56
|
}
|
@@ -59,6 +59,7 @@ VALUE rxml_xpath_object_wrap(xmlDocPtr xdoc, xmlXPathObjectPtr xpop)
|
|
59
59
|
{
|
60
60
|
int i;
|
61
61
|
rxml_xpath_object *rxpop = ALLOC(rxml_xpath_object);
|
62
|
+
|
62
63
|
/* Make sure Ruby's GC can find the array in the stack */
|
63
64
|
VALUE nsnodes = rb_ary_new();
|
64
65
|
rxpop->xdoc =xdoc;
|
@@ -67,7 +68,7 @@ VALUE rxml_xpath_object_wrap(xmlDocPtr xdoc, xmlXPathObjectPtr xpop)
|
|
67
68
|
/* Find all the extra namespace nodes and wrap them. */
|
68
69
|
if (xpop->nodesetval && xpop->nodesetval->nodeNr)
|
69
70
|
{
|
70
|
-
for (i = 0;i < xpop->nodesetval->nodeNr; i++)
|
71
|
+
for (i = 0; i < xpop->nodesetval->nodeNr; i++)
|
71
72
|
{
|
72
73
|
xmlNodePtr xnode = xpop->nodesetval->nodeTab[i];
|
73
74
|
if (xnode != NULL && xnode->type == XML_NAMESPACE_DECL)
|
@@ -332,4 +333,6 @@ void rxml_init_xpath_object(void)
|
|
332
333
|
rb_define_method(cXMLXPathObject, "[]", rxml_xpath_object_aref, 1);
|
333
334
|
rb_define_method(cXMLXPathObject, "string", rxml_xpath_object_string, 0);
|
334
335
|
rb_define_method(cXMLXPathObject, "debug", rxml_xpath_object_debug, 0);
|
336
|
+
rb_define_alias(cXMLXPathObject, "size", "length");
|
337
|
+
|
335
338
|
}
|