libxml-ruby 0.9.5-x86-mswin32-60 → 0.9.6-x86-mswin32-60
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.
- data/CHANGES +28 -0
- data/README +8 -12
- data/ext/libxml/cbg.c +86 -86
- data/ext/libxml/libxml.c +875 -899
- data/ext/libxml/ruby_libxml.h +91 -65
- data/ext/libxml/ruby_xml_attr.c +485 -485
- data/ext/libxml/ruby_xml_attr.h +3 -3
- data/ext/libxml/ruby_xml_attributes.h +2 -2
- data/ext/libxml/ruby_xml_document.c +124 -307
- data/ext/libxml/ruby_xml_document.h +3 -3
- data/ext/libxml/ruby_xml_dtd.c +119 -119
- data/ext/libxml/ruby_xml_dtd.h +2 -2
- data/ext/libxml/ruby_xml_error.c +1 -1
- data/ext/libxml/ruby_xml_error.h +2 -2
- data/ext/libxml/ruby_xml_html_parser.c +119 -119
- data/ext/libxml/ruby_xml_html_parser.h +3 -3
- data/ext/libxml/ruby_xml_input.c +13 -11
- data/ext/libxml/ruby_xml_input.h +3 -3
- data/ext/libxml/ruby_xml_input_cbg.c +197 -197
- data/ext/libxml/ruby_xml_namespace.c +158 -0
- data/ext/libxml/ruby_xml_namespace.h +12 -0
- data/ext/libxml/ruby_xml_namespaces.c +303 -0
- data/ext/libxml/{ruby_xml_ns.h → ruby_xml_namespaces.h} +4 -5
- data/ext/libxml/ruby_xml_node.c +88 -293
- data/ext/libxml/ruby_xml_node.h +4 -4
- data/ext/libxml/ruby_xml_parser.c +152 -152
- data/ext/libxml/ruby_xml_parser.h +3 -3
- data/ext/libxml/ruby_xml_parser_context.c +630 -657
- data/ext/libxml/ruby_xml_parser_context.h +3 -3
- data/ext/libxml/ruby_xml_reader.c +899 -904
- data/ext/libxml/ruby_xml_reader.h +2 -2
- data/ext/libxml/ruby_xml_relaxng.h +2 -2
- data/ext/libxml/ruby_xml_sax_parser.c +175 -175
- data/ext/libxml/ruby_xml_sax_parser.h +3 -3
- data/ext/libxml/ruby_xml_schema.c +165 -165
- data/ext/libxml/ruby_xml_schema.h +2 -2
- data/ext/libxml/ruby_xml_state.h +2 -2
- data/ext/libxml/ruby_xml_xinclude.c +24 -24
- data/ext/libxml/ruby_xml_xinclude.h +3 -3
- data/ext/libxml/ruby_xml_xpath.c +108 -108
- data/ext/libxml/ruby_xml_xpath.h +3 -3
- data/ext/libxml/ruby_xml_xpath_context.c +84 -35
- data/ext/libxml/ruby_xml_xpath_context.h +3 -3
- data/ext/libxml/ruby_xml_xpath_expression.c +5 -7
- data/ext/libxml/ruby_xml_xpath_expression.h +2 -2
- data/ext/libxml/ruby_xml_xpath_object.c +7 -7
- data/ext/libxml/ruby_xml_xpath_object.h +2 -2
- data/ext/libxml/ruby_xml_xpointer.c +107 -107
- data/ext/libxml/ruby_xml_xpointer.h +3 -3
- data/ext/libxml/version.h +2 -2
- data/ext/mingw/libxml_ruby.dll.a +0 -0
- data/ext/mingw/libxml_ruby.so +0 -0
- data/ext/vc/libxml_ruby.vcproj +13 -5
- data/lib/libxml.rb +4 -1
- data/lib/libxml/document.rb +40 -6
- data/lib/libxml/hpricot.rb +76 -76
- data/lib/libxml/namespace.rb +60 -0
- data/lib/libxml/namespaces.rb +36 -0
- data/lib/libxml/node.rb +90 -26
- data/lib/libxml/ns.rb +20 -0
- data/test/model/bands.xml +5 -0
- data/test/tc_attributes.rb +1 -1
- data/test/tc_document.rb +24 -41
- data/test/tc_document_write.rb +87 -115
- data/test/tc_namespace.rb +59 -0
- data/test/tc_namespaces.rb +174 -0
- data/test/tc_node.rb +41 -33
- data/test/tc_node_copy.rb +1 -1
- data/test/tc_node_edit.rb +6 -0
- data/test/tc_node_write.rb +76 -0
- data/test/tc_xinclude.rb +2 -9
- data/test/tc_xpath.rb +38 -11
- data/test/test_suite.rb +3 -1
- metadata +16 -9
- data/ext/libxml/ruby_xml_ns.c +0 -150
- data/test/ets_copy_bug.rb +0 -21
- data/test/ets_copy_bug3.rb +0 -38
- data/test/model/default_validation_bug.rb +0 -0
- data/test/tc_ns.rb +0 -18
data/ext/libxml/ruby_xml_state.h
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
/* $Id: ruby_xml_xinclude.c 650 2008-11-30 03:40:22Z cfis $ */
|
2
|
-
|
3
|
-
#include "ruby_libxml.h"
|
4
|
-
#include "ruby_xml_xinclude.h"
|
5
|
-
|
6
|
-
VALUE cXMLXInclude;
|
7
|
-
|
8
|
-
/*
|
9
|
-
* Document-class: LibXML::XML::XInclude
|
10
|
-
*
|
11
|
-
* The ruby bindings do not currently expose libxml's
|
12
|
-
* XInclude fuctionality.
|
13
|
-
*/
|
14
|
-
|
15
|
-
// Rdoc needs to know
|
16
|
-
#ifdef RDOC_NEVER_DEFINED
|
17
|
-
mLibXML = rb_define_module("LibXML");
|
18
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
19
|
-
#endif
|
20
|
-
|
21
|
-
void ruby_init_xml_xinclude(void)
|
22
|
-
{
|
23
|
-
cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
|
24
|
-
}
|
1
|
+
/* $Id: ruby_xml_xinclude.c 650 2008-11-30 03:40:22Z cfis $ */
|
2
|
+
|
3
|
+
#include "ruby_libxml.h"
|
4
|
+
#include "ruby_xml_xinclude.h"
|
5
|
+
|
6
|
+
VALUE cXMLXInclude;
|
7
|
+
|
8
|
+
/*
|
9
|
+
* Document-class: LibXML::XML::XInclude
|
10
|
+
*
|
11
|
+
* The ruby bindings do not currently expose libxml's
|
12
|
+
* XInclude fuctionality.
|
13
|
+
*/
|
14
|
+
|
15
|
+
// Rdoc needs to know
|
16
|
+
#ifdef RDOC_NEVER_DEFINED
|
17
|
+
mLibXML = rb_define_module("LibXML");
|
18
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
19
|
+
#endif
|
20
|
+
|
21
|
+
void ruby_init_xml_xinclude(void)
|
22
|
+
{
|
23
|
+
cXMLXInclude = rb_define_class_under(mXML, "XInclude", rb_cObject);
|
24
|
+
}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
/* $Id: ruby_xml_xinclude.h
|
1
|
+
/* $Id: ruby_xml_xinclude.h 666 2008-12-07 00:16:50Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
5
|
-
#ifndef
|
6
|
-
#define
|
5
|
+
#ifndef __RXML_XINCLUDE__
|
6
|
+
#define __RXML_XINCLUDE__
|
7
7
|
|
8
8
|
extern VALUE cXMLXInclude;
|
9
9
|
extern VALUE eXMLXIncludeError;
|
data/ext/libxml/ruby_xml_xpath.c
CHANGED
@@ -1,108 +1,108 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath.c
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
#include "ruby_libxml.h"
|
6
|
-
#include "ruby_xml_xpath.h"
|
7
|
-
#include "ruby_xml_xpath_context.h"
|
8
|
-
|
9
|
-
/*
|
10
|
-
* Document-class: LibXML::XML::XPath
|
11
|
-
*
|
12
|
-
* The XML::XPath module is used to query XML documents. It is
|
13
|
-
* usually accessed via the XML::Document#find or
|
14
|
-
* XML::Node#find methods. For example:
|
15
|
-
*
|
16
|
-
* document.find('/foo', namespaces) -> XML::XPath::Object
|
17
|
-
*
|
18
|
-
* The optional namespaces parameter can be a string, array or
|
19
|
-
* hash table.
|
20
|
-
*
|
21
|
-
* document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
|
22
|
-
* document.find('/foo', ['xlink:http://www.w3.org/1999/xlink',
|
23
|
-
* 'xi:http://www.w3.org/2001/XInclude')
|
24
|
-
* document.find('/foo', 'xlink' => 'http://www.w3.org/1999/xlink',
|
25
|
-
* 'xi' => 'http://www.w3.org/2001/XInclude')
|
26
|
-
*
|
27
|
-
*
|
28
|
-
* === Working With Default Namespaces
|
29
|
-
*
|
30
|
-
* Finding namespaced elements and attributes can be tricky.
|
31
|
-
* Lets work through an example of a document with a default
|
32
|
-
* namespace:
|
33
|
-
*
|
34
|
-
* <?xml version="1.0" encoding="utf-8"?>
|
35
|
-
* <feed xmlns="http://www.w3.org/2005/Atom">
|
36
|
-
* <title type="text">Phil Bogle's Contacts</title>
|
37
|
-
* </feed>
|
38
|
-
*
|
39
|
-
* To find nodes you must define the atom namespace for
|
40
|
-
* libxml. One way to do this is:
|
41
|
-
*
|
42
|
-
* node = doc.find('atom:title', 'atom:http://www.w3.org/2005/Atom')
|
43
|
-
*
|
44
|
-
* Alternatively, you can register the default namespace like this:
|
45
|
-
*
|
46
|
-
* doc.root.
|
47
|
-
* node = doc.find('atom:title')
|
48
|
-
*
|
49
|
-
* === More Complex Namespace Examples
|
50
|
-
*
|
51
|
-
* Lets work through some more complex examples using the
|
52
|
-
* following xml document:
|
53
|
-
*
|
54
|
-
* <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
55
|
-
* <soap:Body>
|
56
|
-
* <getManufacturerNamesResponse xmlns="http://services.somewhere.com">
|
57
|
-
* <IDAndNameList xmlns="http://services.somewhere.com">
|
58
|
-
* <ns1:IdAndName xmlns:ns1="http://domain.somewhere.com"/>
|
59
|
-
* </IDAndNameList>
|
60
|
-
* </getManufacturerNamesResponse>
|
61
|
-
* </soap:Envelope>
|
62
|
-
*
|
63
|
-
* # Since the soap namespace is defined on the root
|
64
|
-
* # node we can directly use it.
|
65
|
-
* doc.find('/soap:Envelope')
|
66
|
-
*
|
67
|
-
* # Since the ns1 namespace is not defined on the root node
|
68
|
-
* # we have to first register it with the xpath engine.
|
69
|
-
* doc.find('//ns1:IdAndName',
|
70
|
-
* 'ns1:http://domain.somewhere.com')
|
71
|
-
*
|
72
|
-
* # Since the getManufacturerNamesResponse element uses a default
|
73
|
-
* # namespace we first have to give it a prefix and register
|
74
|
-
* # it with the xpath engine.
|
75
|
-
* doc.find('//ns:getManufacturerNamesResponse',
|
76
|
-
* 'ns:http://services.somewhere.com')
|
77
|
-
*
|
78
|
-
* # Here is an example showing a complex namespace aware
|
79
|
-
* # xpath expression.
|
80
|
-
* doc.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse/ns0:IDAndNameList/ns1:IdAndName',
|
81
|
-
['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
|
82
|
-
*/
|
83
|
-
|
84
|
-
VALUE mXPath;
|
85
|
-
|
86
|
-
// Rdoc needs to know
|
87
|
-
#ifdef RDOC_NEVER_DEFINED
|
88
|
-
mLibXML = rb_define_module("LibXML");
|
89
|
-
mXML = rb_define_module_under(mLibXML, "XML");
|
90
|
-
#endif
|
91
|
-
|
92
|
-
void ruby_init_xml_xpath(void)
|
93
|
-
{
|
94
|
-
mXPath = rb_define_module_under(mXML, "XPath");
|
95
|
-
|
96
|
-
rb_define_const(mXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
|
97
|
-
rb_define_const(mXPath, "NODESET", INT2NUM(XPATH_NODESET));
|
98
|
-
rb_define_const(mXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
|
99
|
-
rb_define_const(mXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
|
100
|
-
rb_define_const(mXPath, "STRING", INT2NUM(XPATH_STRING));
|
101
|
-
rb_define_const(mXPath, "POINT", INT2NUM(XPATH_POINT));
|
102
|
-
rb_define_const(mXPath, "RANGE", INT2NUM(XPATH_RANGE));
|
103
|
-
rb_define_const(mXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
|
104
|
-
rb_define_const(mXPath, "USERS", INT2NUM(XPATH_USERS));
|
105
|
-
rb_define_const(mXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
|
106
|
-
|
107
|
-
ruby_init_xml_xpath_object();
|
108
|
-
}
|
1
|
+
/* $Id: ruby_xml_xpath.c 666 2008-12-07 00:16:50Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "ruby_libxml.h"
|
6
|
+
#include "ruby_xml_xpath.h"
|
7
|
+
#include "ruby_xml_xpath_context.h"
|
8
|
+
|
9
|
+
/*
|
10
|
+
* Document-class: LibXML::XML::XPath
|
11
|
+
*
|
12
|
+
* The XML::XPath module is used to query XML documents. It is
|
13
|
+
* usually accessed via the XML::Document#find or
|
14
|
+
* XML::Node#find methods. For example:
|
15
|
+
*
|
16
|
+
* document.find('/foo', namespaces) -> XML::XPath::Object
|
17
|
+
*
|
18
|
+
* The optional namespaces parameter can be a string, array or
|
19
|
+
* hash table.
|
20
|
+
*
|
21
|
+
* document.find('/foo', 'xlink:http://www.w3.org/1999/xlink')
|
22
|
+
* document.find('/foo', ['xlink:http://www.w3.org/1999/xlink',
|
23
|
+
* 'xi:http://www.w3.org/2001/XInclude')
|
24
|
+
* document.find('/foo', 'xlink' => 'http://www.w3.org/1999/xlink',
|
25
|
+
* 'xi' => 'http://www.w3.org/2001/XInclude')
|
26
|
+
*
|
27
|
+
*
|
28
|
+
* === Working With Default Namespaces
|
29
|
+
*
|
30
|
+
* Finding namespaced elements and attributes can be tricky.
|
31
|
+
* Lets work through an example of a document with a default
|
32
|
+
* namespace:
|
33
|
+
*
|
34
|
+
* <?xml version="1.0" encoding="utf-8"?>
|
35
|
+
* <feed xmlns="http://www.w3.org/2005/Atom">
|
36
|
+
* <title type="text">Phil Bogle's Contacts</title>
|
37
|
+
* </feed>
|
38
|
+
*
|
39
|
+
* To find nodes you must define the atom namespace for
|
40
|
+
* libxml. One way to do this is:
|
41
|
+
*
|
42
|
+
* node = doc.find('atom:title', 'atom:http://www.w3.org/2005/Atom')
|
43
|
+
*
|
44
|
+
* Alternatively, you can register the default namespace like this:
|
45
|
+
*
|
46
|
+
* doc.root.namespaces.default_prefix = 'atom'
|
47
|
+
* node = doc.find('atom:title')
|
48
|
+
*
|
49
|
+
* === More Complex Namespace Examples
|
50
|
+
*
|
51
|
+
* Lets work through some more complex examples using the
|
52
|
+
* following xml document:
|
53
|
+
*
|
54
|
+
* <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
55
|
+
* <soap:Body>
|
56
|
+
* <getManufacturerNamesResponse xmlns="http://services.somewhere.com">
|
57
|
+
* <IDAndNameList xmlns="http://services.somewhere.com">
|
58
|
+
* <ns1:IdAndName xmlns:ns1="http://domain.somewhere.com"/>
|
59
|
+
* </IDAndNameList>
|
60
|
+
* </getManufacturerNamesResponse>
|
61
|
+
* </soap:Envelope>
|
62
|
+
*
|
63
|
+
* # Since the soap namespace is defined on the root
|
64
|
+
* # node we can directly use it.
|
65
|
+
* doc.find('/soap:Envelope')
|
66
|
+
*
|
67
|
+
* # Since the ns1 namespace is not defined on the root node
|
68
|
+
* # we have to first register it with the xpath engine.
|
69
|
+
* doc.find('//ns1:IdAndName',
|
70
|
+
* 'ns1:http://domain.somewhere.com')
|
71
|
+
*
|
72
|
+
* # Since the getManufacturerNamesResponse element uses a default
|
73
|
+
* # namespace we first have to give it a prefix and register
|
74
|
+
* # it with the xpath engine.
|
75
|
+
* doc.find('//ns:getManufacturerNamesResponse',
|
76
|
+
* 'ns:http://services.somewhere.com')
|
77
|
+
*
|
78
|
+
* # Here is an example showing a complex namespace aware
|
79
|
+
* # xpath expression.
|
80
|
+
* doc.find('/soap:Envelope/soap:Body/ns0:getManufacturerNamesResponse/ns0:IDAndNameList/ns1:IdAndName',
|
81
|
+
['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
|
82
|
+
*/
|
83
|
+
|
84
|
+
VALUE mXPath;
|
85
|
+
|
86
|
+
// Rdoc needs to know
|
87
|
+
#ifdef RDOC_NEVER_DEFINED
|
88
|
+
mLibXML = rb_define_module("LibXML");
|
89
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
90
|
+
#endif
|
91
|
+
|
92
|
+
void ruby_init_xml_xpath(void)
|
93
|
+
{
|
94
|
+
mXPath = rb_define_module_under(mXML, "XPath");
|
95
|
+
|
96
|
+
rb_define_const(mXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
|
97
|
+
rb_define_const(mXPath, "NODESET", INT2NUM(XPATH_NODESET));
|
98
|
+
rb_define_const(mXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
|
99
|
+
rb_define_const(mXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
|
100
|
+
rb_define_const(mXPath, "STRING", INT2NUM(XPATH_STRING));
|
101
|
+
rb_define_const(mXPath, "POINT", INT2NUM(XPATH_POINT));
|
102
|
+
rb_define_const(mXPath, "RANGE", INT2NUM(XPATH_RANGE));
|
103
|
+
rb_define_const(mXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
|
104
|
+
rb_define_const(mXPath, "USERS", INT2NUM(XPATH_USERS));
|
105
|
+
rb_define_const(mXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
|
106
|
+
|
107
|
+
ruby_init_xml_xpath_object();
|
108
|
+
}
|
data/ext/libxml/ruby_xml_xpath.h
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath.h
|
1
|
+
/* $Id: ruby_xml_xpath.h 666 2008-12-07 00:16:50Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
5
|
-
#ifndef
|
6
|
-
#define
|
5
|
+
#ifndef __RXML_XPATH__
|
6
|
+
#define __RXML_XPATH__
|
7
7
|
|
8
8
|
extern VALUE mXPath;
|
9
9
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath_context.c
|
1
|
+
/* $Id: ruby_xml_xpath_context.c 673 2008-12-08 06:33:23Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -48,32 +48,29 @@ static VALUE rxml_xpath_context_initialize(VALUE self, VALUE node)
|
|
48
48
|
{
|
49
49
|
xmlDocPtr xdoc;
|
50
50
|
VALUE document;
|
51
|
-
#ifndef LIBXML_XPATH_ENABLED
|
52
|
-
rb_raise(rb_eTypeError, "libxml was not compiled with XPath support.");
|
53
|
-
#endif
|
54
51
|
|
55
52
|
if (rb_obj_is_kind_of(node, cXMLNode) == Qtrue)
|
56
53
|
{
|
57
54
|
document = rb_funcall(node, rb_intern("doc"), 0);
|
58
|
-
if
|
59
|
-
|
60
|
-
}
|
61
|
-
else if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
|
62
|
-
{
|
63
|
-
|
64
|
-
}
|
65
|
-
else
|
66
|
-
{
|
67
|
-
|
68
|
-
}
|
55
|
+
if (NIL_P(document))
|
56
|
+
rb_raise(rb_eTypeError, "Supplied node must belong to a document.");
|
57
|
+
}
|
58
|
+
else if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
|
59
|
+
{
|
60
|
+
document = node;
|
61
|
+
}
|
62
|
+
else
|
63
|
+
{
|
64
|
+
rb_raise(rb_eTypeError, "Supplied argument must be a document or node.");
|
65
|
+
}
|
69
66
|
|
70
|
-
Data_Get_Struct(document, xmlDoc, xdoc);
|
71
|
-
DATA_PTR(self) = xmlXPathNewContext(xdoc);
|
67
|
+
Data_Get_Struct(document, xmlDoc, xdoc);
|
68
|
+
DATA_PTR(self) = xmlXPathNewContext(xdoc);
|
72
69
|
|
73
|
-
/* Save the doc as an attribute, this will expose it to Ruby's GC. */
|
74
|
-
rb_iv_set(self, "@doc", document);
|
70
|
+
/* Save the doc as an attribute, this will expose it to Ruby's GC. */
|
71
|
+
rb_iv_set(self, "@doc", document);
|
75
72
|
|
76
|
-
return self;
|
73
|
+
return self;
|
77
74
|
}
|
78
75
|
|
79
76
|
/*
|
@@ -85,12 +82,14 @@ return self;
|
|
85
82
|
|
86
83
|
* context.register_namespace('xi', 'http://www.w3.org/2001/XInclude')
|
87
84
|
*/
|
88
|
-
static VALUE rxml_xpath_context_register_namespace(VALUE self, VALUE prefix,
|
89
|
-
VALUE uri)
|
85
|
+
static VALUE rxml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri)
|
90
86
|
{
|
91
87
|
xmlXPathContextPtr ctxt;
|
92
|
-
|
93
88
|
Data_Get_Struct(self, xmlXPathContext, ctxt);
|
89
|
+
|
90
|
+
/* Prefix could be a symbol. */
|
91
|
+
prefix = rb_obj_as_string(prefix);
|
92
|
+
|
94
93
|
if (xmlXPathRegisterNs(ctxt, (xmlChar*) StringValuePtr(prefix),
|
95
94
|
(xmlChar*) StringValuePtr(uri)) == 0)
|
96
95
|
{
|
@@ -149,8 +148,8 @@ static VALUE rxml_xpath_context_register_namespaces_from_node(VALUE self,
|
|
149
148
|
Skip it for now. */
|
150
149
|
if (xns->prefix)
|
151
150
|
{
|
152
|
-
VALUE prefix = rb_str_new2(xns->prefix);
|
153
|
-
VALUE uri = rb_str_new2(xns->href);
|
151
|
+
VALUE prefix = rb_str_new2((const char*)xns->prefix);
|
152
|
+
VALUE uri = rb_str_new2((const char*)xns->href);
|
154
153
|
rxml_xpath_context_register_namespace(self, prefix, uri);
|
155
154
|
}
|
156
155
|
xns = xns->next;
|
@@ -171,7 +170,9 @@ static int iterate_ns_hash(st_data_t prefix, st_data_t uri, st_data_t self)
|
|
171
170
|
* call-seq:
|
172
171
|
* context.register_namespaces(["prefix:uri"]) -> self
|
173
172
|
*
|
174
|
-
* Register the specified namespaces in this context.
|
173
|
+
* Register the specified namespaces in this context. There are
|
174
|
+
* three different forms that libxml accepts. These include
|
175
|
+
* a string, an array of strings, or a hash table:
|
175
176
|
*
|
176
177
|
* context.register_namespaces('xi:http://www.w3.org/2001/XInclude')
|
177
178
|
* context.register_namespaces(['xlink:http://www.w3.org/1999/xlink',
|
@@ -212,7 +213,7 @@ static VALUE rxml_xpath_context_register_namespaces(VALUE self, VALUE nslist)
|
|
212
213
|
}
|
213
214
|
break;
|
214
215
|
case T_HASH:
|
215
|
-
st_foreach(
|
216
|
+
st_foreach(RHASH_TBL(nslist), iterate_ns_hash, self);
|
216
217
|
break;
|
217
218
|
default:
|
218
219
|
rb_raise(
|
@@ -287,19 +288,67 @@ static VALUE rxml_xpath_context_find(VALUE self, VALUE xpath_expr)
|
|
287
288
|
return result;
|
288
289
|
}
|
289
290
|
|
291
|
+
|
292
|
+
/*
|
293
|
+
* call-seq:
|
294
|
+
* context.enable_cache(size = nil)
|
295
|
+
*
|
296
|
+
* Enables an XPath::Context's built-in cache. If the cache is
|
297
|
+
* enabled then XPath objects will be cached internally for reuse.
|
298
|
+
* The size parameter controls sets the maximum number of XPath objects
|
299
|
+
* that will be cached per XPath object type (node-set, string, number,
|
300
|
+
* boolean, and misc objects). Set size to nil to use the default
|
301
|
+
* cache size of 100.
|
302
|
+
*/
|
303
|
+
static VALUE
|
304
|
+
rxml_xpath_context_enable_cache(int argc, VALUE *argv, VALUE self)
|
305
|
+
{
|
306
|
+
xmlXPathContextPtr xctxt;
|
307
|
+
VALUE size;
|
308
|
+
int value = -1;
|
309
|
+
|
310
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
311
|
+
|
312
|
+
if (rb_scan_args(argc, argv, "01", &size) == 1)
|
313
|
+
{
|
314
|
+
value = NUM2INT(size);
|
315
|
+
}
|
316
|
+
|
317
|
+
if (xmlXPathContextSetCache(xctxt, 1, value, 0) == -1)
|
318
|
+
rxml_raise(&xmlLastError);
|
319
|
+
|
320
|
+
return self;
|
321
|
+
}
|
322
|
+
|
323
|
+
/*
|
324
|
+
* call-seq:
|
325
|
+
* context.disable_cache
|
326
|
+
*
|
327
|
+
* Disables an XPath::Context's built-in cache.
|
328
|
+
*/
|
329
|
+
static VALUE
|
330
|
+
rxml_xpath_context_disable_cache(VALUE self) {
|
331
|
+
xmlXPathContextPtr xctxt;
|
332
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
333
|
+
|
334
|
+
if (xmlXPathContextSetCache(xctxt, 0, 0, 0) == -1)
|
335
|
+
rxml_raise(&xmlLastError);
|
336
|
+
|
337
|
+
return self;
|
338
|
+
}
|
339
|
+
|
340
|
+
|
290
341
|
void ruby_init_xml_xpath_context(void)
|
291
342
|
{
|
292
343
|
cXMLXPathContext = rb_define_class_under(mXPath, "Context", rb_cObject);
|
293
344
|
rb_define_alloc_func(cXMLXPathContext, rxml_xpath_context_alloc);
|
294
345
|
rb_define_attr(cXMLXPathContext, "doc", 1, 0);
|
295
|
-
rb_define_method(cXMLXPathContext, "initialize",
|
296
|
-
|
297
|
-
rb_define_method(cXMLXPathContext, "
|
298
|
-
|
299
|
-
rb_define_method(cXMLXPathContext, "register_namespaces_from_node",
|
300
|
-
rxml_xpath_context_register_namespaces_from_node, 1);
|
301
|
-
rb_define_method(cXMLXPathContext, "register_namespace",
|
302
|
-
rxml_xpath_context_register_namespace, 2);
|
346
|
+
rb_define_method(cXMLXPathContext, "initialize", rxml_xpath_context_initialize, 1);
|
347
|
+
rb_define_method(cXMLXPathContext, "register_namespaces", rxml_xpath_context_register_namespaces, 1);
|
348
|
+
rb_define_method(cXMLXPathContext, "register_namespaces_from_node", rxml_xpath_context_register_namespaces_from_node, 1);
|
349
|
+
rb_define_method(cXMLXPathContext, "register_namespace", rxml_xpath_context_register_namespace, 2);
|
303
350
|
rb_define_method(cXMLXPathContext, "node=", rxml_xpath_context_node_set, 1);
|
304
351
|
rb_define_method(cXMLXPathContext, "find", rxml_xpath_context_find, 1);
|
352
|
+
rb_define_method(cXMLXPathContext, "enable_cache", rxml_xpath_context_enable_cache, -1);
|
353
|
+
rb_define_method(cXMLXPathContext, "disable_cache", rxml_xpath_context_disable_cache, 0);
|
305
354
|
}
|