libxml-ruby 0.7.0-x86-mswin32-60 → 0.8.0-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 +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
data/ext/libxml/ruby_xml_xpath.h
CHANGED
@@ -1,23 +1,22 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath.h
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
#ifndef __RUBY_XML_XPATH__
|
6
|
-
#define __RUBY_XML_XPATH__
|
7
|
-
|
8
|
-
extern VALUE
|
9
|
-
extern VALUE eXMLXPathInvalidPath;
|
10
|
-
|
11
|
-
typedef struct ruby_xml_xpath {
|
12
|
-
VALUE xd;
|
13
|
-
VALUE ctxt;
|
14
|
-
xmlXPathObjectPtr xpop;
|
15
|
-
} ruby_xml_xpath;
|
16
|
-
|
17
|
-
void ruby_xml_xpath_free(ruby_xml_xpath *rxxp);
|
18
|
-
VALUE ruby_xml_xpath_find(VALUE class, VALUE anode, VALUE xpath_expr, VALUE nslist);
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
#endif
|
1
|
+
/* $Id: ruby_xml_xpath.h 418 2008-07-14 16:44:59Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RUBY_XML_XPATH__
|
6
|
+
#define __RUBY_XML_XPATH__
|
7
|
+
|
8
|
+
extern VALUE mXPath;
|
9
|
+
extern VALUE eXMLXPathInvalidPath;
|
10
|
+
|
11
|
+
typedef struct ruby_xml_xpath {
|
12
|
+
VALUE xd;
|
13
|
+
VALUE ctxt;
|
14
|
+
xmlXPathObjectPtr xpop;
|
15
|
+
} ruby_xml_xpath;
|
16
|
+
|
17
|
+
void ruby_xml_xpath_free(ruby_xml_xpath *rxxp);
|
18
|
+
VALUE ruby_xml_xpath_find(VALUE class, VALUE anode, VALUE xpath_expr, VALUE nslist);
|
19
|
+
|
20
|
+
void ruby_init_xml_xpath(void);
|
21
|
+
|
22
|
+
#endif
|
@@ -1,92 +1,94 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath_context.c
|
1
|
+
/* $Id: ruby_xml_xpath_context.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_context.h"
|
7
|
+
#include <st.h>
|
7
8
|
|
8
|
-
VALUE cXMLXPathContext;
|
9
9
|
|
10
10
|
/*
|
11
|
-
*
|
12
|
-
* context.doc -> document
|
11
|
+
* Document-class: LibXML::XML::XPath::Context
|
13
12
|
*
|
14
|
-
*
|
13
|
+
* The XML::XPath::Context class is used to evaluate XPath
|
14
|
+
* expressions. Generally, you should not directly use this class,
|
15
|
+
* but instead use the XML::Document#find and XML::Node#find methods.
|
16
|
+
*
|
17
|
+
* doc = XML::Document.string('<header>content</header>')
|
18
|
+
* context = XPath::Context.new(doc)
|
19
|
+
* context.node = doc.root
|
20
|
+
* context.register_namespaces_from_node(doc.root)
|
21
|
+
* nodes = context.find('/header')
|
15
22
|
*/
|
16
|
-
VALUE
|
17
|
-
ruby_xml_xpath_context_doc_get(VALUE self) {
|
18
|
-
xmlXPathContextPtr ctxt;
|
19
|
-
Data_Get_Struct(self, xmlXPathContext, ctxt);
|
20
|
-
|
21
|
-
return ruby_xml_document_wrap(ctxt->doc);
|
22
|
-
}
|
23
23
|
|
24
|
+
VALUE cXMLXPathContext;
|
24
25
|
|
25
26
|
void
|
26
27
|
ruby_xml_xpath_context_free(xmlXPathContextPtr ctxt) {
|
27
|
-
|
28
|
-
if (ctxt->namespaces != NULL) {
|
29
|
-
xmlFree(ctxt->namespaces);
|
30
|
-
ctxt->namespaces = NULL;
|
31
|
-
}
|
32
|
-
xmlXPathFreeContext(ctxt);
|
33
|
-
ctxt = NULL;
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
|
38
|
-
void
|
39
|
-
ruby_xml_xpath_context_mark(xmlXPathContextPtr ctxt) {
|
40
|
-
if (ctxt == NULL ) return;
|
41
|
-
if (ctxt->doc != NULL && ctxt->doc->_private != NULL)
|
42
|
-
rb_gc_mark((VALUE)ctxt->doc->_private);
|
28
|
+
xmlXPathFreeContext(ctxt);
|
43
29
|
}
|
44
30
|
|
45
31
|
|
46
32
|
VALUE
|
47
|
-
|
33
|
+
ruby_xml_xpath_context_alloc(VALUE klass) {
|
48
34
|
return Data_Wrap_Struct(cXMLXPathContext,
|
49
|
-
|
35
|
+
NULL,
|
50
36
|
ruby_xml_xpath_context_free,
|
51
|
-
|
37
|
+
NULL);
|
52
38
|
}
|
53
39
|
|
54
|
-
|
40
|
+
/* call-seq:
|
41
|
+
* XPath::Context.new(node) -> XPath::Context
|
42
|
+
*
|
43
|
+
* Creates a new XPath context for the specified document. The
|
44
|
+
* context can then be used to evaluate an XPath expression.
|
45
|
+
*
|
46
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
47
|
+
* context = XPath::Context.new(doc)
|
48
|
+
* nodes = XPath::Object.new('//first', context)
|
49
|
+
* nodes.length == 1
|
50
|
+
*/
|
55
51
|
VALUE
|
56
|
-
|
52
|
+
ruby_xml_xpath_context_initialize(VALUE self, VALUE node) {
|
57
53
|
ruby_xml_document_t *rxd;
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
Data_Get_Struct(anode,ruby_xml_document_t,rxd);
|
63
|
-
if (rxd->doc == NULL) return(Qnil);
|
54
|
+
VALUE document;
|
55
|
+
#ifndef LIBXML_XPATH_ENABLED
|
56
|
+
rb_raise(rb_eTypeError, "libxml was not compiled with XPath support.");
|
57
|
+
#endif
|
64
58
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
if (ctxt == NULL) return(Qnil);
|
75
|
-
|
76
|
-
} else {
|
77
|
-
rb_raise(rb_eTypeError,"create context requires a document or node. Supplied a %s?",
|
78
|
-
rb_obj_as_string(anode));
|
59
|
+
if (rb_obj_is_kind_of(node, cXMLNode) == Qtrue)
|
60
|
+
{
|
61
|
+
document = rb_funcall(node, rb_intern("doc"), 0);
|
62
|
+
if NIL_P(document)
|
63
|
+
rb_raise(rb_eTypeError, "Supplied node must belong to a document.");
|
64
|
+
}
|
65
|
+
else if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
|
66
|
+
{
|
67
|
+
document = node;
|
79
68
|
}
|
69
|
+
else
|
70
|
+
{
|
71
|
+
rb_raise(rb_eTypeError, "Supplied argument must be a document or node.");
|
72
|
+
}
|
73
|
+
|
74
|
+
Data_Get_Struct(document, ruby_xml_document_t, rxd);
|
75
|
+
DATA_PTR(self) = xmlXPathNewContext(rxd->doc);
|
76
|
+
|
77
|
+
/* Save the doc as an attribute, this will expose it to Ruby's GC. */
|
78
|
+
rb_iv_set(self, "@doc", document);
|
80
79
|
|
81
|
-
return
|
80
|
+
return self;
|
82
81
|
}
|
83
82
|
|
83
|
+
|
84
84
|
/*
|
85
85
|
* call-seq:
|
86
86
|
* context.register_namespace(prefix, uri) -> (true|false)
|
87
87
|
*
|
88
88
|
* Register the specified namespace URI with the specified prefix
|
89
89
|
* in this context.
|
90
|
+
|
91
|
+
* context.register_namespace('xi', 'http://www.w3.org/2001/XInclude')
|
90
92
|
*/
|
91
93
|
VALUE
|
92
94
|
ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri) {
|
@@ -105,18 +107,177 @@ ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri) {
|
|
105
107
|
}
|
106
108
|
}
|
107
109
|
|
110
|
+
/* call-seq:
|
111
|
+
* context.register_namespaces_from_node(node) -> self
|
112
|
+
*
|
113
|
+
* Helper method to read in namespaces defined on a node.
|
114
|
+
*
|
115
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
116
|
+
* context = XPath::Context.new(doc)
|
117
|
+
* context.register_namespaces_from_node(doc.root)
|
118
|
+
*/
|
119
|
+
VALUE
|
120
|
+
ruby_xml_xpath_context_register_namespaces_from_node(VALUE self, VALUE node) {
|
121
|
+
xmlXPathContextPtr xctxt;
|
122
|
+
xmlNodePtr xnode;
|
123
|
+
xmlNsPtr *xnsArr;
|
124
|
+
|
125
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
126
|
+
|
127
|
+
if (rb_obj_is_kind_of(node, cXMLDocument) == Qtrue)
|
128
|
+
{
|
129
|
+
ruby_xml_document_t *rdoc;
|
130
|
+
Data_Get_Struct(node, ruby_xml_document_t, rdoc);
|
131
|
+
xnode = xmlDocGetRootElement(rdoc->doc);
|
132
|
+
}
|
133
|
+
else if (rb_obj_is_kind_of(node, cXMLNode) == Qtrue)
|
134
|
+
{
|
135
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
136
|
+
}
|
137
|
+
else
|
138
|
+
{
|
139
|
+
rb_raise(rb_eTypeError, "The first argument must be a document or node.");
|
140
|
+
}
|
141
|
+
|
142
|
+
xnsArr = xmlGetNsList(xnode->doc, xnode);
|
143
|
+
|
144
|
+
if (xnsArr)
|
145
|
+
{
|
146
|
+
xmlNsPtr xns = *xnsArr;
|
147
|
+
|
148
|
+
while (xns) {
|
149
|
+
/* If there is no prefix, then this is the default namespace.
|
150
|
+
Skip it for now. */
|
151
|
+
if (xns->prefix)
|
152
|
+
{
|
153
|
+
VALUE prefix = rb_str_new2(xns->prefix);
|
154
|
+
VALUE uri = rb_str_new2(xns->href);
|
155
|
+
ruby_xml_xpath_context_register_namespace(self, prefix, uri);
|
156
|
+
}
|
157
|
+
xns = xns->next;
|
158
|
+
}
|
159
|
+
xmlFree(xnsArr);
|
160
|
+
}
|
161
|
+
|
162
|
+
return self;
|
163
|
+
}
|
164
|
+
|
165
|
+
static int
|
166
|
+
iterate_ns_hash(st_data_t prefix, st_data_t uri, st_data_t self)
|
167
|
+
{
|
168
|
+
ruby_xml_xpath_context_register_namespace(self, prefix, uri);
|
169
|
+
return ST_CONTINUE;
|
170
|
+
}
|
171
|
+
|
172
|
+
|
173
|
+
/*
|
174
|
+
* call-seq:
|
175
|
+
* context.register_namespaces(["prefix:uri"]) -> self
|
176
|
+
*
|
177
|
+
* Register the specified namespaces in this context.
|
178
|
+
*
|
179
|
+
* context.register_namespaces('xi:http://www.w3.org/2001/XInclude')
|
180
|
+
* context.register_namespaces(['xlink:http://www.w3.org/1999/xlink',
|
181
|
+
* 'xi:http://www.w3.org/2001/XInclude')
|
182
|
+
* context.register_namespaces('xlink' => 'http://www.w3.org/1999/xlink',
|
183
|
+
* 'xi' => 'http://www.w3.org/2001/XInclude')
|
184
|
+
*/
|
185
|
+
VALUE
|
186
|
+
ruby_xml_xpath_context_register_namespaces(VALUE self, VALUE nslist) {
|
187
|
+
char *cp;
|
188
|
+
long i;
|
189
|
+
VALUE rprefix, ruri;
|
190
|
+
|
191
|
+
/* Need to loop through the 2nd argument and iterate through the
|
192
|
+
* list of namespaces that we want to allow */
|
193
|
+
switch (TYPE(nslist)) {
|
194
|
+
case T_STRING:
|
195
|
+
cp = strchr(StringValuePtr(nslist), (int)':');
|
196
|
+
if (cp == NULL) {
|
197
|
+
rprefix = nslist;
|
198
|
+
ruri = Qnil;
|
199
|
+
} else {
|
200
|
+
rprefix = rb_str_new(StringValuePtr(nslist), (int)((long)cp - (long)StringValuePtr(nslist)));
|
201
|
+
ruri = rb_str_new2(&cp[1]);
|
202
|
+
}
|
203
|
+
/* Should test the results of this */
|
204
|
+
ruby_xml_xpath_context_register_namespace(self, rprefix, ruri);
|
205
|
+
break;
|
206
|
+
case T_ARRAY:
|
207
|
+
for (i = 0; i < RARRAY(nslist)->len; i++) {
|
208
|
+
ruby_xml_xpath_context_register_namespaces(self, RARRAY(nslist)->ptr[i]);
|
209
|
+
}
|
210
|
+
break;
|
211
|
+
case T_HASH:
|
212
|
+
st_foreach(RHASH(nslist)->tbl, iterate_ns_hash, self);
|
213
|
+
break;
|
214
|
+
default:
|
215
|
+
rb_raise(rb_eArgError, "Invalid argument type, only accept string, array of strings, or an array of arrays");
|
216
|
+
}
|
217
|
+
return self;
|
218
|
+
}
|
219
|
+
|
220
|
+
/*
|
221
|
+
* call-seq:
|
222
|
+
* context.node = node
|
223
|
+
*
|
224
|
+
* Set the current node used by the XPath engine
|
225
|
+
|
226
|
+
* doc = XML::Document.string('<header><first>hi</first></header>')
|
227
|
+
* context.node = doc.root.first
|
228
|
+
*/
|
229
|
+
VALUE
|
230
|
+
ruby_xml_xpath_context_node_set(VALUE self, VALUE node) {
|
231
|
+
xmlXPathContextPtr xctxt;
|
232
|
+
xmlNodePtr xnode;
|
233
|
+
|
234
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
235
|
+
Data_Get_Struct(node, xmlNode, xnode);
|
236
|
+
xctxt->node = xnode;
|
237
|
+
return node;
|
238
|
+
}
|
239
|
+
|
240
|
+
/*
|
241
|
+
* call-seq:
|
242
|
+
* context.find("xpath") -> XML::XPath::Object
|
243
|
+
*
|
244
|
+
* Find nodes matching the specified XPath expression
|
245
|
+
*/
|
246
|
+
VALUE
|
247
|
+
ruby_xml_xpath_context_find(VALUE self, VALUE xpath_expr) {
|
248
|
+
xmlXPathContextPtr xctxt;
|
249
|
+
xmlXPathObjectPtr xobject;
|
250
|
+
VALUE result;
|
251
|
+
|
252
|
+
Data_Get_Struct(self, xmlXPathContext, xctxt);
|
253
|
+
xobject = xmlXPathEval((xmlChar*)StringValuePtr(xpath_expr), xctxt);
|
254
|
+
|
255
|
+
if (xobject == NULL)
|
256
|
+
rb_raise(eXMLXPathInvalidPath,
|
257
|
+
"Invalid XPath expression (expr could not be evaluated)");
|
258
|
+
|
259
|
+
result = ruby_xml_xpath_object_wrap(xobject);
|
260
|
+
rb_iv_set(result, "@context", self);
|
261
|
+
return result;
|
262
|
+
}
|
263
|
+
|
264
|
+
|
108
265
|
// Rdoc needs to know
|
109
266
|
#ifdef RDOC_NEVER_DEFINED
|
110
|
-
|
111
|
-
|
267
|
+
mLibXML = rb_define_module("LibXML");
|
268
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
269
|
+
mXPath = rb_define_module_under(mXML, "XPath");
|
112
270
|
#endif
|
113
271
|
|
114
272
|
void
|
115
273
|
ruby_init_xml_xpath_context(void) {
|
116
|
-
cXMLXPathContext = rb_define_class_under(
|
117
|
-
|
118
|
-
rb_define_method(cXMLXPathContext, "
|
119
|
-
|
120
|
-
rb_define_method(cXMLXPathContext, "
|
121
|
-
|
274
|
+
cXMLXPathContext = rb_define_class_under(mXPath, "Context", rb_cObject);
|
275
|
+
rb_define_alloc_func(cXMLXPathContext, ruby_xml_xpath_context_alloc);
|
276
|
+
rb_define_method(cXMLXPathContext, "initialize", ruby_xml_xpath_context_initialize, 1);
|
277
|
+
rb_define_method(cXMLXPathContext, "register_namespaces", ruby_xml_xpath_context_register_namespaces, 1);
|
278
|
+
rb_define_method(cXMLXPathContext, "register_namespaces_from_node", ruby_xml_xpath_context_register_namespaces_from_node, 1);
|
279
|
+
rb_define_method(cXMLXPathContext, "register_namespace", ruby_xml_xpath_context_register_namespace, 2);
|
280
|
+
rb_define_method(cXMLXPathContext, "node=", ruby_xml_xpath_context_node_set, 1);
|
281
|
+
rb_define_method(cXMLXPathContext, "find", ruby_xml_xpath_context_find, 1);
|
282
|
+
rb_define_attr(cXMLXPathContext, "doc", 1, 0);
|
122
283
|
}
|
@@ -1,20 +1,15 @@
|
|
1
|
-
/* $Id: ruby_xml_xpath_context.h
|
2
|
-
|
3
|
-
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
-
|
5
|
-
#ifndef __RUBY_XML_XPATH_CONTEXT__
|
6
|
-
#define __RUBY_XML_XPATH_CONTEXT__
|
7
|
-
|
8
|
-
extern VALUE cXMLXPathContext;
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
VALUE ruby_xml_xpath_context_new(VALUE anode);
|
17
|
-
VALUE ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri);
|
18
|
-
void ruby_init_xml_xpath_context(void);
|
19
|
-
|
20
|
-
#endif
|
1
|
+
/* $Id: ruby_xml_xpath_context.h 412 2008-07-14 08:02:47Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#ifndef __RUBY_XML_XPATH_CONTEXT__
|
6
|
+
#define __RUBY_XML_XPATH_CONTEXT__
|
7
|
+
|
8
|
+
extern VALUE cXMLXPathContext;
|
9
|
+
void ruby_init_xml_xpath_context(void);
|
10
|
+
|
11
|
+
VALUE ruby_xml_xpath_context_register_namespaces(VALUE self, VALUE nslist);
|
12
|
+
VALUE ruby_xml_xpath_context_register_namespaces_from_node(VALUE self, VALUE node);
|
13
|
+
VALUE ruby_xml_xpath_context_find(VALUE self, VALUE xpath_expr);
|
14
|
+
|
15
|
+
#endif
|
@@ -3,11 +3,10 @@
|
|
3
3
|
#include "ruby_libxml.h"
|
4
4
|
|
5
5
|
/*
|
6
|
-
* Document-class: XML::XPath::Object
|
6
|
+
* Document-class: LibXML::XML::XPath::Object
|
7
7
|
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
* this class/data structure.
|
8
|
+
* A collection of nodes returned from the evaluation of an XML::XPath
|
9
|
+
* or XML::XPointer expression.
|
11
10
|
*
|
12
11
|
*/
|
13
12
|
VALUE cXMLXPathObject;
|
@@ -24,7 +23,7 @@ ruby_xml_xpath_object_tabref(xmlXPathObjectPtr xpop, int apos) {
|
|
24
23
|
|
25
24
|
switch(xpop->nodesetval->nodeTab[apos]->type) {
|
26
25
|
case XML_ATTRIBUTE_NODE:
|
27
|
-
return
|
26
|
+
return ruby_xml_attr_wrap((xmlAttrPtr)xpop->nodesetval->nodeTab[apos]);
|
28
27
|
break;
|
29
28
|
default:
|
30
29
|
return ruby_xml_node2_wrap(cXMLNode,
|
@@ -232,8 +231,27 @@ ruby_xml_xpath_object_length(VALUE self) {
|
|
232
231
|
return INT2NUM(xpop->nodesetval->nodeNr);
|
233
232
|
}
|
234
233
|
|
234
|
+
/*
|
235
|
+
* call-seq:
|
236
|
+
* xpath_object.xpath_type -> int
|
237
|
+
*
|
238
|
+
* Returns the XPath type of the result object.
|
239
|
+
* Possible values are defined as constants
|
240
|
+
* on the XML::XPath class and include:
|
241
|
+
*
|
242
|
+
* * XML::XPath::UNDEFINED
|
243
|
+
* * XML::XPath::NODESET
|
244
|
+
* * XML::XPath::BOOLEAN
|
245
|
+
* * XML::XPath::NUMBER
|
246
|
+
* * XML::XPath::STRING
|
247
|
+
* * XML::XPath::POINT
|
248
|
+
* * XML::XPath::RANGE
|
249
|
+
* * XML::XPath::LOCATIONSET
|
250
|
+
* * XML::XPath::USERS
|
251
|
+
* * XML::XPath::XSLT_TREE
|
252
|
+
*/
|
235
253
|
VALUE
|
236
|
-
|
254
|
+
ruby_xml_xpath_object_get_type(VALUE self)
|
237
255
|
{
|
238
256
|
xmlXPathObjectPtr xpop;
|
239
257
|
|
@@ -242,6 +260,13 @@ ruby_xml_xpath_object_set_type(VALUE self)
|
|
242
260
|
return INT2FIX(xpop->type);
|
243
261
|
}
|
244
262
|
|
263
|
+
|
264
|
+
/*
|
265
|
+
* call-seq:
|
266
|
+
* xpath_object.string -> String
|
267
|
+
*
|
268
|
+
* Returns the original XPath expression as a string.
|
269
|
+
*/
|
245
270
|
VALUE
|
246
271
|
ruby_xml_xpath_object_string(VALUE self)
|
247
272
|
{
|
@@ -255,32 +280,51 @@ ruby_xml_xpath_object_string(VALUE self)
|
|
255
280
|
return rb_str_new2((const char*) xpop->stringval);
|
256
281
|
}
|
257
282
|
|
283
|
+
/*
|
284
|
+
* call-seq:
|
285
|
+
* nodes.debug -> (true|false)
|
286
|
+
*
|
287
|
+
* Dump libxml debugging information to stdout.
|
288
|
+
* Requires Libxml be compiled with debugging enabled.
|
289
|
+
*/
|
290
|
+
VALUE
|
291
|
+
ruby_xml_xpath_object_debug(VALUE self) {
|
292
|
+
xmlXPathObjectPtr xpop;
|
293
|
+
|
294
|
+
#ifndef LIBXML_DEBUG_ENABLED
|
295
|
+
rb_raise(rb_eTypeError, "libxml was not compiled with debug support.");
|
296
|
+
#endif
|
297
|
+
|
298
|
+
Data_Get_Struct(self, xmlXPathObject, xpop);
|
299
|
+
xmlXPathDebugDumpObject(stdout, xpop, 0);
|
300
|
+
return Qnil;
|
301
|
+
}
|
302
|
+
|
303
|
+
|
258
304
|
// Rdoc needs to know
|
259
|
-
#ifdef RDOC_NEVER_DEFINED
|
260
|
-
|
261
|
-
|
262
|
-
|
305
|
+
#ifdef RDOC_NEVER_DEFINED
|
306
|
+
mLibXML = rb_define_module("LibXML");
|
307
|
+
mXML = rb_define_module_under(mLibXML, "XML");
|
308
|
+
mXPath = rb_define_module_under(mXML, "XPath");
|
309
|
+
#endif
|
263
310
|
|
264
311
|
void
|
265
312
|
ruby_init_xml_xpath_object(void) {
|
266
|
-
cXMLXPathObject = rb_define_class_under(
|
267
|
-
|
268
|
-
rb_include_module(cXMLXPathObject, rb_const_get(rb_cObject, rb_intern("Enumerable")));
|
313
|
+
cXMLXPathObject = rb_define_class_under(mXPath, "Object", rb_cObject);
|
314
|
+
rb_include_module(cXMLXPathObject, rb_mEnumerable);
|
269
315
|
|
270
316
|
rb_define_method(cXMLXPathObject, "each", ruby_xml_xpath_object_each, 0);
|
271
|
-
rb_define_method(cXMLXPathObject, "
|
317
|
+
rb_define_method(cXMLXPathObject, "xpath_type", ruby_xml_xpath_object_get_type, 0);
|
272
318
|
rb_define_method(cXMLXPathObject, "empty?", ruby_xml_xpath_object_empty_q, 0);
|
273
319
|
rb_define_method(cXMLXPathObject, "first", ruby_xml_xpath_object_first, 0);
|
274
320
|
rb_define_method(cXMLXPathObject, "length", ruby_xml_xpath_object_length, 0);
|
275
321
|
rb_define_method(cXMLXPathObject, "size", ruby_xml_xpath_object_length, 0);
|
276
322
|
rb_define_method(cXMLXPathObject, "to_a", ruby_xml_xpath_object_to_a, 0);
|
277
323
|
rb_define_method(cXMLXPathObject, "[]", ruby_xml_xpath_object_aref, 1);
|
278
|
-
|
279
324
|
rb_define_method(cXMLXPathObject, "string", ruby_xml_xpath_object_string, 0);
|
280
|
-
|
281
|
-
|
282
|
-
|
325
|
+
rb_define_attr(cXMLXPathObject, "context", 1, 0);
|
326
|
+
rb_define_method(cXMLXPathObject, "debug", ruby_xml_xpath_object_debug, 0);
|
327
|
+
|
283
328
|
/* Give the NodeSet type, but it is pointless */
|
284
329
|
rb_define_method(cXMLXPathObject, "set", ruby_xml_xpath_object_set, 0);
|
285
|
-
|
286
330
|
}
|