libxml-ruby 0.7.0-x86-mswin32-60 → 0.8.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +24 -1
- data/README +48 -3
- data/benchmark/depixelate.rb +632 -0
- data/benchmark/hamlet.xml +9055 -0
- data/benchmark/sock_entries.xml +507 -0
- data/benchmark/throughput.rb +39 -0
- data/benchmark/xml_benchmarks.rb +222 -0
- data/doc/classes/LibXML.html +237 -0
- data/doc/classes/LibXML/XML.html +178 -0
- data/doc/classes/{XML → LibXML/XML}/Attr.html +213 -182
- data/doc/classes/{XML → LibXML/XML}/Attributes.html +126 -54
- data/doc/classes/{XML → LibXML/XML}/Document.html +299 -297
- data/doc/classes/{XML → LibXML/XML}/Dtd.html +10 -10
- data/doc/classes/{XML/XInclude → LibXML/XML}/Error.html +4 -4
- data/doc/classes/{XML → LibXML/XML}/HTMLParser.html +40 -40
- data/doc/classes/{XML → LibXML/XML}/InputCallbacks.html +10 -10
- data/doc/classes/{XML → LibXML/XML}/NS.html +46 -46
- data/doc/classes/{XML → LibXML/XML}/Node.html +935 -788
- data/doc/classes/LibXML/XML/Node/FailedModify.html +111 -0
- data/doc/classes/{XML → LibXML/XML}/Node/Set.html +69 -68
- data/doc/classes/{XML → LibXML/XML}/Node/SetNamespace.html +4 -4
- data/doc/classes/{XML/Node/FailedModify.html → LibXML/XML/Node/UnknownType.html} +4 -4
- data/doc/classes/{XML → LibXML/XML}/Parser.html +426 -389
- data/doc/classes/{XML → LibXML/XML}/Parser/Context.html +208 -208
- data/doc/classes/{XML → LibXML/XML}/Parser/ParseError.html +4 -4
- data/doc/classes/{XML → LibXML/XML}/Reader.html +288 -287
- data/doc/classes/{XML → LibXML/XML}/SaxParser.html +52 -52
- data/doc/classes/{XML/XPath/Context.html → LibXML/XML/Schema.html} +60 -32
- data/doc/classes/{XML → LibXML/XML}/State.html +4 -4
- data/doc/classes/{XML/Node/UnknownType.html → LibXML/XML/Tree.html} +5 -5
- data/doc/classes/{XML → LibXML/XML}/XInclude.html +5 -5
- data/doc/classes/{XML → LibXML/XML/XInclude}/Error.html +5 -5
- data/doc/classes/{XML → LibXML/XML}/XMLParserOptions.html +5 -5
- data/doc/classes/{XML → LibXML/XML}/XPath.html +23 -64
- data/doc/classes/LibXML/XML/XPath/Context.html +403 -0
- data/doc/classes/{XML/XPointer/Context → LibXML/XML/XPath}/InvalidPath.html +4 -4
- data/doc/classes/LibXML/XML/XPath/Object.html +623 -0
- data/doc/classes/{XML → LibXML/XML}/XPointer.html +12 -12
- data/doc/classes/{XML → LibXML/XML}/XPointer/Context.html +5 -5
- data/doc/classes/{XML/XPath → LibXML/XML/XPointer/Context}/InvalidPath.html +5 -5
- data/doc/classes/{XML → LibXML/XML}/XPointer/InvalidExpression.html +4 -4
- data/doc/classes/XML.html +17 -123
- data/doc/created.rid +1 -1
- data/doc/files/CHANGES.html +49 -25
- data/doc/files/LICENSE.html +1 -1
- data/doc/files/README.html +79 -4
- data/doc/files/VERSION.html +2 -2
- data/doc/files/ext/libxml/cbg_c.html +1 -1
- data/doc/files/ext/libxml/libxml_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_attr_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_attributes_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_document_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_dtd_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_html_parser_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_input_cbg_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_node_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_node_set_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_ns_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_parser_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_parser_context_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_reader_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_sax_parser_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_schema_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_state_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xinclude_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xpath_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xpath_context_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xpath_object_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xpointer_c.html +1 -1
- data/doc/files/ext/libxml/ruby_xml_xpointer_context_c.html +1 -1
- data/doc/files/lib/libxml/attr_rb.html +108 -0
- data/doc/files/lib/libxml/attributes_rb.html +108 -0
- data/doc/files/lib/libxml/document_rb.html +108 -0
- data/doc/files/lib/libxml/node_rb.html +108 -0
- data/doc/files/lib/libxml/node_set_rb.html +108 -0
- data/doc/files/lib/libxml/parser_options_rb.html +107 -0
- data/doc/files/{ext/libxml/ruby_xml_tree_c.html → lib/libxml/parser_rb.html} +4 -4
- data/doc/files/lib/libxml/properties_rb.html +108 -0
- data/doc/files/lib/libxml/tree_rb.html +107 -0
- data/doc/files/lib/libxml_rb.html +12 -3
- data/doc/fr_class_index.html +34 -32
- data/doc/fr_file_index.html +9 -1
- data/doc/fr_method_index.html +362 -347
- data/ext/libxml/cbg.c +76 -76
- data/ext/libxml/libxml.c +4 -3
- data/ext/libxml/ruby_libxml.h +1 -1
- data/ext/libxml/ruby_xml_attr.c +4 -3
- data/ext/libxml/ruby_xml_attr.h +16 -16
- data/ext/libxml/ruby_xml_attributes.c +267 -266
- data/ext/libxml/ruby_xml_attributes.h +17 -17
- data/ext/libxml/ruby_xml_document.c +30 -59
- data/ext/libxml/ruby_xml_document.h +27 -27
- data/ext/libxml/ruby_xml_dtd.c +2 -1
- data/ext/libxml/ruby_xml_dtd.h +17 -17
- data/ext/libxml/ruby_xml_html_parser.c +3 -2
- data/ext/libxml/ruby_xml_html_parser.h +29 -29
- data/ext/libxml/ruby_xml_input_cbg.c +2 -1
- data/ext/libxml/ruby_xml_input_cbg.h +20 -20
- data/ext/libxml/ruby_xml_node.c +127 -470
- data/ext/libxml/ruby_xml_node.h +17 -17
- data/ext/libxml/ruby_xml_node_set.c +5 -4
- data/ext/libxml/ruby_xml_node_set.h +20 -20
- data/ext/libxml/ruby_xml_ns.c +3 -2
- data/ext/libxml/ruby_xml_ns.h +12 -12
- data/ext/libxml/ruby_xml_parser.c +20 -48
- data/ext/libxml/ruby_xml_parser.h +31 -31
- data/ext/libxml/ruby_xml_parser_context.c +3 -2
- data/ext/libxml/ruby_xml_parser_context.h +20 -20
- data/ext/libxml/ruby_xml_reader.c +2 -1
- data/ext/libxml/ruby_xml_sax_parser.c +3 -2
- data/ext/libxml/ruby_xml_sax_parser.h +56 -56
- data/ext/libxml/ruby_xml_schema.c +6 -0
- data/ext/libxml/ruby_xml_schema.h +16 -16
- data/ext/libxml/ruby_xml_state.c +13 -12
- data/ext/libxml/ruby_xml_state.h +1 -1
- data/ext/libxml/ruby_xml_xinclude.c +3 -2
- data/ext/libxml/ruby_xml_xinclude.h +13 -13
- data/ext/libxml/ruby_xml_xpath.c +35 -228
- data/ext/libxml/ruby_xml_xpath.h +22 -23
- data/ext/libxml/ruby_xml_xpath_context.c +223 -62
- data/ext/libxml/ruby_xml_xpath_context.h +15 -20
- data/ext/libxml/ruby_xml_xpath_object.c +63 -19
- data/ext/libxml/ruby_xml_xpointer.c +19 -15
- data/ext/libxml/ruby_xml_xpointer.h +27 -27
- data/ext/libxml/ruby_xml_xpointer_context.c +3 -2
- data/ext/libxml/ruby_xml_xpointer_context.h +18 -18
- data/ext/libxml/version.h +9 -9
- data/lib/libxml.rb +16 -128
- data/lib/libxml/attr.rb +45 -0
- data/lib/libxml/attributes.rb +15 -0
- data/lib/libxml/document.rb +54 -0
- data/lib/libxml/node.rb +132 -0
- data/lib/libxml/node_set.rb +27 -0
- data/lib/libxml/parser.rb +42 -0
- data/lib/libxml/parser_options.rb +25 -0
- data/lib/libxml/properties.rb +19 -0
- data/lib/libxml/tree.rb +29 -0
- data/lib/libxml_ruby.so +0 -0
- data/mingw/libxml_ruby.so +0 -0
- data/{work/task/setup → setup.rb} +1585 -1616
- data/test/gc.log +0 -0
- data/test/model/books.xml +147 -0
- data/{work/test/runner.rb → test/model/default_validation_bug.rb} +0 -0
- data/test/model/merge_bug_data.xml +58 -0
- data/test/model/rubynet.xml +78 -0
- data/test/model/rubynet_project +1 -0
- data/test/model/saxtest.xml +5 -0
- data/test/model/shiporder.xml +23 -0
- data/test/model/shiporder.xsd +31 -0
- data/test/model/simple.xml +7 -0
- data/test/model/soap.xml +27 -0
- data/test/model/xinclude.xml +5 -0
- data/test/tc_deprecated_require.rb +13 -0
- data/test/tc_xml_document.rb +57 -16
- data/test/tc_xml_document_write.rb +125 -10
- data/test/tc_xml_dtd.rb +22 -1
- data/test/tc_xml_node.rb +13 -0
- data/test/tc_xml_node_edit.rb +1 -1
- data/test/tc_xml_node_xlink.rb +1 -1
- data/test/tc_xml_parser.rb +64 -7
- data/test/tc_xml_properties.rb +42 -0
- data/test/tc_xml_reader.rb +4 -4
- data/test/tc_xml_sax_parser.rb +50 -50
- data/test/tc_xml_schema.rb +2 -2
- data/test/tc_xml_traversal.rb +220 -0
- data/test/tc_xml_xinclude.rb +12 -15
- data/test/tc_xml_xpath.rb +74 -6
- data/test/tc_xml_xpath_context.rb +72 -0
- data/test/test_suite.rb +6 -4
- data/vc/libxml_ruby.vcproj +1 -9
- metadata +92 -65
- data/doc/classes/XML/SiblingEnum.html +0 -142
- data/doc/classes/XML/Tree.html +0 -224
- data/doc/classes/XML/XPath/Object.html +0 -439
- data/ext/libxml/ruby_xml_tree.c +0 -43
- data/ext/libxml/ruby_xml_tree.h +0 -12
- data/test/ets_copy_bug2.rb +0 -21
- data/test/tc_xml_document_write2.rb +0 -54
- data/test/tc_xml_document_write3.rb +0 -96
- data/test/tc_xml_sax_parser2.rb +0 -51
- data/work/Rakefile +0 -247
- data/work/task/make +0 -26
- data/work/task/memory +0 -37
- data/work/task/rdoc +0 -39
- data/work/task/test +0 -29
- data/work/test/ets_runner.rb +0 -33
- data/work/test/libxml_test.rb +0 -3
- data/work/test/runner_ets.rb +0 -33
@@ -1,16 +1,16 @@
|
|
1
|
-
#ifndef __RUBY_XML_SCHEMA__
|
2
|
-
#define __RUBY_XML_SCHEMA__
|
3
|
-
|
4
|
-
#include <libxml/schemasInternals.h>
|
5
|
-
#include <libxml/xmlschemas.h>
|
6
|
-
|
7
|
-
extern VALUE cXMLSchema;
|
8
|
-
|
9
|
-
typedef struct rxp_schema {
|
10
|
-
xmlSchemaPtr schema; /* Schema interface */
|
11
|
-
} ruby_xml_schema;
|
12
|
-
|
13
|
-
void ruby_init_xml_schema(void);
|
14
|
-
void ruby_schema_free(ruby_xml_schema *rxs);
|
15
|
-
#endif
|
16
|
-
|
1
|
+
#ifndef __RUBY_XML_SCHEMA__
|
2
|
+
#define __RUBY_XML_SCHEMA__
|
3
|
+
|
4
|
+
#include <libxml/schemasInternals.h>
|
5
|
+
#include <libxml/xmlschemas.h>
|
6
|
+
|
7
|
+
extern VALUE cXMLSchema;
|
8
|
+
|
9
|
+
typedef struct rxp_schema {
|
10
|
+
xmlSchemaPtr schema; /* Schema interface */
|
11
|
+
} ruby_xml_schema;
|
12
|
+
|
13
|
+
void ruby_init_xml_schema(void);
|
14
|
+
void ruby_schema_free(ruby_xml_schema *rxs);
|
15
|
+
#endif
|
16
|
+
|
data/ext/libxml/ruby_xml_state.c
CHANGED
@@ -14,21 +14,22 @@ ruby_xml_state_free(int dummy) {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
VALUE
|
17
|
-
ruby_xml_state_alloc() {
|
17
|
+
ruby_xml_state_alloc(VALUE klass) {
|
18
18
|
#ifdef DEBUG
|
19
19
|
fprintf(stderr, "Allocating state");
|
20
20
|
#endif
|
21
21
|
|
22
|
-
xmlInitParser();
|
22
|
+
xmlInitParser();
|
23
23
|
|
24
24
|
return Data_Wrap_Struct(cXMLState,
|
25
25
|
NULL, ruby_xml_state_free,
|
26
26
|
&dummy);
|
27
27
|
}
|
28
28
|
|
29
|
-
// Rdoc needs to know
|
29
|
+
// Rdoc needs to know
|
30
30
|
#ifdef RDOC_NEVER_DEFINED
|
31
|
-
|
31
|
+
mLibXML = rb_define_module("LibXML");
|
32
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
32
33
|
#endif
|
33
34
|
|
34
35
|
void
|
@@ -37,16 +38,16 @@ ruby_init_state(void) {
|
|
37
38
|
cXMLState = rb_define_class_under(mXML, "State", rb_cObject);
|
38
39
|
|
39
40
|
/* Mixin singleton so only one xml state object can be created. */
|
40
|
-
rb_require("singleton");
|
41
|
-
rb_mSingleton = rb_const_get(rb_cObject, rb_intern("Singleton"));
|
42
|
-
rb_include_module(cXMLState, rb_mSingleton);
|
43
|
-
|
44
|
-
rb_define_alloc_func(cXMLState, ruby_xml_state_alloc);
|
45
|
-
|
41
|
+
rb_require("singleton");
|
42
|
+
rb_mSingleton = rb_const_get(rb_cObject, rb_intern("Singleton"));
|
43
|
+
rb_include_module(cXMLState, rb_mSingleton);
|
44
|
+
|
45
|
+
rb_define_alloc_func(cXMLState, ruby_xml_state_alloc);
|
46
|
+
|
46
47
|
/* Create one instance of the state object that is used
|
47
48
|
to initalize and cleanup libxml. Then register it with
|
48
49
|
the garbage collector so its not freed until the process
|
49
50
|
exists.*/
|
50
|
-
LIBXML_STATE = rb_class_new_instance(0, NULL, cXMLState);
|
51
|
-
rb_global_variable(&LIBXML_STATE);
|
51
|
+
LIBXML_STATE = rb_class_new_instance(0, NULL, cXMLState);
|
52
|
+
rb_global_variable(&LIBXML_STATE);
|
52
53
|
}
|
data/ext/libxml/ruby_xml_state.h
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
/* $Id: ruby_xml_xinclude.c
|
1
|
+
/* $Id: ruby_xml_xinclude.c 461 2008-07-15 21:35:56Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
@@ -10,7 +10,8 @@ VALUE eXMLXIncludeError;
|
|
10
10
|
|
11
11
|
// Rdoc needs to know
|
12
12
|
#ifdef RDOC_NEVER_DEFINED
|
13
|
-
|
13
|
+
mLibXML = rb_define_module("LibXML");
|
14
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
14
15
|
#endif
|
15
16
|
|
16
17
|
void
|
@@ -1,13 +1,13 @@
|
|
1
|
-
/* $Id: ruby_xml_xinclude.h 39 2006-02-21 20:40:16Z roscopeco $ */
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
#ifndef __RUBY_XML_XINCLUDE__
|
6
|
-
#define __RUBY_XML_XINCLUDE__
|
7
|
-
|
8
|
-
extern VALUE cXMLXInclude;
|
9
|
-
extern VALUE eXMLXIncludeError;
|
10
|
-
|
11
|
-
void ruby_init_xml_xinclude(void);
|
12
|
-
|
13
|
-
#endif
|
1
|
+
/* $Id: ruby_xml_xinclude.h 39 2006-02-21 20:40:16Z roscopeco $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RUBY_XML_XINCLUDE__
|
6
|
+
#define __RUBY_XML_XINCLUDE__
|
7
|
+
|
8
|
+
extern VALUE cXMLXInclude;
|
9
|
+
extern VALUE eXMLXIncludeError;
|
10
|
+
|
11
|
+
void ruby_init_xml_xinclude(void);
|
12
|
+
|
13
|
+
#endif
|
data/ext/libxml/ruby_xml_xpath.c
CHANGED
@@ -1,19 +1,32 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath.c
|
1
|
+
/* $Id: ruby_xml_xpath.c 461 2008-07-15 21:35:56Z cfis $ */
|
2
2
|
|
3
3
|
/* Please see the LICENSE file for copyright and distribution information */
|
4
4
|
|
5
5
|
#include "ruby_libxml.h"
|
6
6
|
#include "ruby_xml_xpath.h"
|
7
|
+
#include "ruby_xml_xpath_context.h"
|
7
8
|
|
8
9
|
/*
|
9
|
-
* Document-class: XML::XPath
|
10
|
+
* Document-class: LibXML::XML::XPath
|
10
11
|
*
|
11
|
-
* The XML::XPath
|
12
|
-
* via the XML::Document#find
|
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')
|
13
26
|
*
|
14
|
-
* document.find('/foo')
|
15
27
|
*
|
16
28
|
* === Working With Namespaces
|
29
|
+
*
|
17
30
|
* Finding namespaced elements and attributes can be tricky.
|
18
31
|
* Lets work through some examples using the following xml document:
|
19
32
|
*
|
@@ -33,7 +46,7 @@
|
|
33
46
|
* # Since the ns1 namespace is not defined on the root node
|
34
47
|
* # we have to first register it with the xpath engine.
|
35
48
|
* doc.find('//ns1:IdAndName',
|
36
|
-
|
49
|
+
* 'ns1:http://domain.somewhere.com')
|
37
50
|
*
|
38
51
|
* # Since the getManufacturerNamesResponse element uses a default
|
39
52
|
* # namespace we first have to give it a prefix and register
|
@@ -47,236 +60,30 @@
|
|
47
60
|
['ns0:http://services.somewhere.com', 'ns1:http://domain.somewhere.com'])
|
48
61
|
*/
|
49
62
|
|
50
|
-
VALUE
|
63
|
+
VALUE mXPath;
|
51
64
|
VALUE eXMLXPathInvalidPath;
|
52
65
|
|
53
|
-
#ifdef LIBXML_XPATH_ENABLED
|
54
|
-
|
55
|
-
|
56
|
-
/*
|
57
|
-
* call-seq:
|
58
|
-
* xpath.debug -> (true|false)
|
59
|
-
*
|
60
|
-
* Dump libxml debugging information to stdout.
|
61
|
-
* Requires Libxml be compiled with debugging enabled.
|
62
|
-
*/
|
63
|
-
VALUE
|
64
|
-
ruby_xml_xpath_debug(VALUE self) {
|
65
|
-
#ifdef LIBXML_DEBUG_ENABLED
|
66
|
-
ruby_xml_xpath *rxxp;
|
67
|
-
Data_Get_Struct(self, ruby_xml_xpath, rxxp);
|
68
|
-
|
69
|
-
if (rxxp->xpop != NULL) {
|
70
|
-
xmlXPathDebugDumpObject(stdout, rxxp->xpop, 0);
|
71
|
-
return(Qtrue);
|
72
|
-
} else {
|
73
|
-
return(Qfalse);
|
74
|
-
}
|
75
|
-
#else
|
76
|
-
rb_warn("libxml does not have debugging turned on");
|
77
|
-
return(Qfalse);
|
78
|
-
#endif
|
79
|
-
}
|
80
|
-
|
81
|
-
///////////////////////////////////////////////////
|
82
|
-
// TODO xpath_find is throwing TypeError:
|
83
|
-
//
|
84
|
-
// TypeError: can't convert nil into String
|
85
|
-
//
|
86
|
-
// When given a namespace when non exist.
|
87
|
-
void
|
88
|
-
ruby_xml_xpath_register_namespaces(VALUE nslist, VALUE xxpc, int level) {
|
89
|
-
char *cp;
|
90
|
-
long i;
|
91
|
-
VALUE rprefix, ruri;
|
92
|
-
xmlNsPtr xns;
|
93
|
-
|
94
|
-
/* Need to loop through the 2nd argument and iterate through the
|
95
|
-
* list of namespaces that we want to allow */
|
96
|
-
switch (TYPE(nslist)) {
|
97
|
-
case T_STRING:
|
98
|
-
cp = strchr(StringValuePtr(nslist), (int)':');
|
99
|
-
if (cp == NULL) {
|
100
|
-
rprefix = nslist;
|
101
|
-
ruri = Qnil;
|
102
|
-
} else {
|
103
|
-
rprefix = rb_str_new(StringValuePtr(nslist), (int)((long)cp - (long)StringValuePtr(nslist)));
|
104
|
-
ruri = rb_str_new2(&cp[1]);
|
105
|
-
}
|
106
|
-
/* Should test the results of this */
|
107
|
-
ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
|
108
|
-
break;
|
109
|
-
case T_ARRAY:
|
110
|
-
if ( level == 0 ) {
|
111
|
-
for (i = 0; i < RARRAY(nslist)->len; i++) {
|
112
|
-
ruby_xml_xpath_register_namespaces(RARRAY(nslist)->ptr[i],xxpc,1);
|
113
|
-
}
|
114
|
-
}
|
115
|
-
else {
|
116
|
-
// tuples of prefix/uri
|
117
|
-
if (RARRAY(nslist)->len == 2) {
|
118
|
-
rprefix = RARRAY(nslist)->ptr[0];
|
119
|
-
ruri = RARRAY(nslist)->ptr[1];
|
120
|
-
ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
|
121
|
-
} else {
|
122
|
-
rb_raise(rb_eArgError, "nested array must be an array of strings, prefix and href/uri");
|
123
|
-
}
|
124
|
-
}
|
125
|
-
break;
|
126
|
-
default:
|
127
|
-
if (rb_obj_is_kind_of(nslist, cXMLNS) == Qtrue) {
|
128
|
-
Data_Get_Struct(nslist, xmlNs, xns);
|
129
|
-
rprefix = rb_str_new2((const char*)xns->prefix);
|
130
|
-
ruri = rb_str_new2((const char*)xns->href);
|
131
|
-
ruby_xml_xpath_context_register_namespace(xxpc, rprefix, ruri);
|
132
|
-
} else
|
133
|
-
rb_raise(rb_eArgError, "Invalid argument type, only accept string, array of strings, or an array of arrays");
|
134
|
-
}
|
135
|
-
}
|
136
|
-
/*
|
137
|
-
* call-seq:
|
138
|
-
* XML::XPath.find(path, namespaces = [any]) -> xpath
|
139
|
-
*
|
140
|
-
* Find nodes matching the specified xpath (and optionally any of the
|
141
|
-
* supplied namespaces) and return as an XML::Node::Set.
|
142
|
-
*
|
143
|
-
* The optional namespaces argument may take one of
|
144
|
-
* two forms:
|
145
|
-
*
|
146
|
-
* * A string in the form of: "prefix:uri", or
|
147
|
-
* * An array of:
|
148
|
-
* * strings in the form like above
|
149
|
-
* * arrays in the form of ['prefix','uri']
|
150
|
-
*
|
151
|
-
* If not specified, matching nodes from any namespace
|
152
|
-
* will be included.
|
153
|
-
*/
|
154
|
-
VALUE
|
155
|
-
ruby_xml_xpath_find(VALUE class, VALUE anode, VALUE xpath_expr, VALUE nslist) {
|
156
|
-
#ifdef LIBXML_XPATH_ENABLED
|
157
|
-
xmlXPathCompExprPtr comp;
|
158
|
-
xmlXPathObjectPtr xxpop;
|
159
|
-
xmlNodePtr xnode;
|
160
|
-
xmlXPathContextPtr ctxt;
|
161
|
-
ruby_xml_document_t *rdocp;
|
162
|
-
VALUE rnode, xxpc;
|
163
|
-
VALUE rxpop;
|
164
|
-
|
165
|
-
if (rb_obj_is_kind_of(anode, cXMLDocument) == Qtrue) {
|
166
|
-
xxpc = ruby_xml_xpath_context_new(anode);
|
167
|
-
Data_Get_Struct(anode, ruby_xml_document_t, rdocp);
|
168
|
-
#ifdef DEBUG
|
169
|
-
fprintf(stderr,"rdocp=0x%x root=0x%x\n",rdocp,xmlDocGetRootElement(rdocp->doc));
|
170
|
-
#endif
|
171
|
-
rnode=ruby_xml_node2_wrap(cXMLNode,xmlDocGetRootElement(rdocp->doc));
|
172
|
-
#ifdef DEBUG
|
173
|
-
fprintf(stderr,"rnode 0x%x 0x%x\n",rnode,xmlDocGetRootElement(rdocp->doc)->_private);
|
174
|
-
#endif
|
175
|
-
Data_Get_Struct(rnode, xmlNode, xnode);
|
176
|
-
} else if ( rb_obj_is_kind_of(anode, cXMLNode) == Qtrue) {
|
177
|
-
xxpc = ruby_xml_xpath_context_new(anode);
|
178
|
-
Data_Get_Struct(anode, xmlNode, xnode);
|
179
|
-
} else
|
180
|
-
rb_raise(rb_eTypeError, "arg 1 must be XML::Document or XML::Node within a document %s", rb_obj_as_string(anode));
|
181
|
-
|
182
|
-
if (NIL_P(xxpc))
|
183
|
-
return(Qnil);
|
184
|
-
|
185
|
-
Data_Get_Struct(xxpc,xmlXPathContext,ctxt);
|
186
|
-
// XXX Is this legal? Set a subtree to apply xpath?
|
187
|
-
ctxt->node = xnode;
|
188
|
-
|
189
|
-
// XXX is setting ->namespaces used?
|
190
|
-
if (xnode->type == XML_DOCUMENT_NODE) {
|
191
|
-
ctxt->namespaces = xmlGetNsList(xnode->doc,
|
192
|
-
xmlDocGetRootElement(xnode->doc));
|
193
|
-
} else {
|
194
|
-
ctxt->namespaces = xmlGetNsList(xnode->doc, xnode);
|
195
|
-
}
|
196
|
-
|
197
|
-
ctxt->nsNr = 0;
|
198
|
-
if (ctxt->namespaces != NULL) {
|
199
|
-
while (ctxt->namespaces[ctxt->nsNr] != NULL)
|
200
|
-
ctxt->nsNr++;
|
201
|
-
}
|
202
|
-
|
203
|
-
if ( ! NIL_P(nslist) )
|
204
|
-
ruby_xml_xpath_register_namespaces(nslist,xxpc,0);
|
205
|
-
|
206
|
-
comp = xmlXPathCompile((xmlChar*)StringValuePtr(xpath_expr));
|
207
|
-
|
208
|
-
if (comp == NULL) {
|
209
|
-
rb_raise(eXMLXPathInvalidPath,
|
210
|
-
"Invalid XPath expression (expr does not compile)");
|
211
|
-
}
|
212
|
-
xxpop=xmlXPathCompiledEval(comp, ctxt);
|
213
|
-
if ( xxpop == NULL )
|
214
|
-
rb_raise(eXMLXPathInvalidPath,
|
215
|
-
"Invalid XPath expression (expr could not be evaluated)");
|
216
|
-
|
217
|
-
rxpop = ruby_xml_xpath_object_wrap(xxpop);
|
218
|
-
|
219
|
-
#ifdef NODE_DEBUG
|
220
|
-
fprintf(stderr,"xpo 0x%x class=%s\n",
|
221
|
-
rxpop,
|
222
|
-
rb_class2name(rb_obj_class(rxpop)));
|
223
|
-
#endif
|
224
|
-
|
225
|
-
xmlXPathFreeCompExpr(comp);
|
226
|
-
|
227
|
-
if (rxpop == Qnil)
|
228
|
-
rb_raise(eXMLXPathInvalidPath,
|
229
|
-
"Invalid XPath expression for this document");
|
230
|
-
|
231
|
-
return rxpop;
|
232
|
-
#else
|
233
|
-
rb_warn("libxml was compiled without XPath support");
|
234
|
-
return(Qfalse);
|
235
|
-
#endif
|
236
|
-
}
|
237
|
-
|
238
|
-
|
239
|
-
VALUE
|
240
|
-
ruby_xml_xpath_findva(int argc, VALUE *argv, VALUE class) {
|
241
|
-
if ( argc < 2 || argc > 3 )
|
242
|
-
rb_raise(rb_eArgError, "wrong number of arguments (1 or 2)");
|
243
|
-
|
244
|
-
return ruby_xml_xpath_find(class,argv[0],argv[1],(argc==3)?argv[2]:Qnil);
|
245
|
-
}
|
246
|
-
|
247
|
-
VALUE
|
248
|
-
ruby_xml_xpath_find2(VALUE anode, VALUE xpath_expr, VALUE nslist) {
|
249
|
-
return ruby_xml_xpath_find(cXMLXPath, anode, xpath_expr, nslist);
|
250
|
-
}
|
251
|
-
|
252
66
|
// Rdoc needs to know
|
253
67
|
#ifdef RDOC_NEVER_DEFINED
|
254
|
-
|
68
|
+
mLibXML = rb_define_module("LibXML");
|
69
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
255
70
|
#endif
|
256
71
|
|
257
72
|
void
|
258
73
|
ruby_init_xml_xpath(void) {
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
rb_define_const(
|
265
|
-
rb_define_const(
|
266
|
-
rb_define_const(
|
267
|
-
rb_define_const(
|
268
|
-
rb_define_const(
|
269
|
-
rb_define_const(
|
270
|
-
rb_define_const(
|
271
|
-
rb_define_const(
|
272
|
-
rb_define_const(cXMLXPath, "USERS", INT2NUM(XPATH_USERS));
|
273
|
-
rb_define_const(cXMLXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
|
274
|
-
|
275
|
-
rb_define_singleton_method(cXMLXPath, "find", ruby_xml_xpath_findva, -1);
|
276
|
-
|
277
|
-
rb_define_method(cXMLXPath, "debug", ruby_xml_xpath_debug, 0);
|
74
|
+
mXPath = rb_define_module_under(mXML, "XPath");
|
75
|
+
eXMLXPathInvalidPath = rb_define_class_under(mXPath, "InvalidPath", eXMLError);
|
76
|
+
|
77
|
+
rb_define_const(mXPath, "UNDEFINED", INT2NUM(XPATH_UNDEFINED));
|
78
|
+
rb_define_const(mXPath, "NODESET", INT2NUM(XPATH_NODESET));
|
79
|
+
rb_define_const(mXPath, "BOOLEAN", INT2NUM(XPATH_BOOLEAN));
|
80
|
+
rb_define_const(mXPath, "NUMBER", INT2NUM(XPATH_NUMBER));
|
81
|
+
rb_define_const(mXPath, "STRING", INT2NUM(XPATH_STRING));
|
82
|
+
rb_define_const(mXPath, "POINT", INT2NUM(XPATH_POINT));
|
83
|
+
rb_define_const(mXPath, "RANGE", INT2NUM(XPATH_RANGE));
|
84
|
+
rb_define_const(mXPath, "LOCATIONSET", INT2NUM(XPATH_LOCATIONSET));
|
85
|
+
rb_define_const(mXPath, "USERS", INT2NUM(XPATH_USERS));
|
86
|
+
rb_define_const(mXPath, "XSLT_TREE", INT2NUM(XPATH_XSLT_TREE));
|
278
87
|
|
279
88
|
ruby_init_xml_xpath_object();
|
280
89
|
}
|
281
|
-
|
282
|
-
#endif /* ifdef LIBXML_XPATH_ENABLED */
|