libxml-ruby 0.6.0-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +122 -0
- data/LICENSE +23 -0
- data/README +144 -0
- data/ext/libxml/cbg.c +76 -0
- data/ext/libxml/extconf.rb +308 -0
- data/ext/libxml/libxml.c +62 -0
- data/ext/libxml/ruby_libxml.h +93 -0
- data/ext/libxml/ruby_xml_attr.c +405 -0
- data/ext/libxml/ruby_xml_attr.h +19 -0
- data/ext/libxml/ruby_xml_document.c +1111 -0
- data/ext/libxml/ruby_xml_document.h +27 -0
- data/ext/libxml/ruby_xml_dtd.c +168 -0
- data/ext/libxml/ruby_xml_dtd.h +17 -0
- data/ext/libxml/ruby_xml_html_parser.c +449 -0
- data/ext/libxml/ruby_xml_html_parser.h +29 -0
- data/ext/libxml/ruby_xml_input_cbg.c +158 -0
- data/ext/libxml/ruby_xml_input_cbg.h +20 -0
- data/ext/libxml/ruby_xml_node.c +2410 -0
- data/ext/libxml/ruby_xml_node.h +27 -0
- data/ext/libxml/ruby_xml_node_set.c +170 -0
- data/ext/libxml/ruby_xml_node_set.h +20 -0
- data/ext/libxml/ruby_xml_ns.c +153 -0
- data/ext/libxml/ruby_xml_ns.h +21 -0
- data/ext/libxml/ruby_xml_parser.c +1425 -0
- data/ext/libxml/ruby_xml_parser.h +31 -0
- data/ext/libxml/ruby_xml_parser_context.c +750 -0
- data/ext/libxml/ruby_xml_parser_context.h +22 -0
- data/ext/libxml/ruby_xml_reader.c +900 -0
- data/ext/libxml/ruby_xml_reader.h +14 -0
- data/ext/libxml/ruby_xml_sax_parser.c +485 -0
- data/ext/libxml/ruby_xml_sax_parser.h +56 -0
- data/ext/libxml/ruby_xml_schema.c +146 -0
- data/ext/libxml/ruby_xml_schema.h +16 -0
- data/ext/libxml/ruby_xml_state.c +113 -0
- data/ext/libxml/ruby_xml_state.h +12 -0
- data/ext/libxml/ruby_xml_tree.c +43 -0
- data/ext/libxml/ruby_xml_tree.h +12 -0
- data/ext/libxml/ruby_xml_xinclude.c +20 -0
- data/ext/libxml/ruby_xml_xinclude.h +13 -0
- data/ext/libxml/ruby_xml_xpath.c +243 -0
- data/ext/libxml/ruby_xml_xpath.h +23 -0
- data/ext/libxml/ruby_xml_xpath_context.c +118 -0
- data/ext/libxml/ruby_xml_xpath_context.h +20 -0
- data/ext/libxml/ruby_xml_xpath_object.c +293 -0
- data/ext/libxml/ruby_xml_xpath_object.h +28 -0
- data/ext/libxml/ruby_xml_xpointer.c +100 -0
- data/ext/libxml/ruby_xml_xpointer.h +27 -0
- data/ext/libxml/ruby_xml_xpointer_context.c +21 -0
- data/ext/libxml/ruby_xml_xpointer_context.h +18 -0
- data/ext/libxml/sax_parser_callbacks.inc +213 -0
- data/ext/libxml/version.h +9 -0
- data/lib/libxml.rb +125 -0
- data/lib/libxml_ruby.so +0 -0
- data/lib/xml/libxml.rb +5 -0
- data/mingw/libiconv-2.dll +0 -0
- data/mingw/libxml2-2.dll +0 -0
- data/mingw/libxml_ruby.so +0 -0
- data/mingw/mingw.rake +36 -0
- data/test/dtd-test.rb +24 -0
- data/test/etc_doc_to_s.rb +19 -0
- data/test/ets_copy_bug.rb +21 -0
- data/test/ets_copy_bug2.rb +32 -0
- data/test/ets_copy_bug3.rb +38 -0
- data/test/ets_doc_file.rb +15 -0
- data/test/ets_doc_to_s.rb +21 -0
- data/test/ets_gpx.rb +26 -0
- data/test/ets_node_gc.rb +21 -0
- data/test/ets_test.xml +2 -0
- data/test/ets_tsr.rb +9 -0
- data/test/gc.log +0 -0
- data/test/merge_bug.rb +55 -0
- data/test/schema-test.rb +74 -0
- data/test/tc_well_formed.rb +11 -0
- data/test/tc_xml_document.rb +52 -0
- data/test/tc_xml_document_write.rb +24 -0
- data/test/tc_xml_document_write2.rb +54 -0
- data/test/tc_xml_document_write3.rb +96 -0
- data/test/tc_xml_html_parser.rb +63 -0
- data/test/tc_xml_node.rb +59 -0
- data/test/tc_xml_node2.rb +25 -0
- data/test/tc_xml_node3.rb +27 -0
- data/test/tc_xml_node4.rb +86 -0
- data/test/tc_xml_node5.rb +52 -0
- data/test/tc_xml_node6.rb +27 -0
- data/test/tc_xml_node7.rb +35 -0
- data/test/tc_xml_node8.rb +32 -0
- data/test/tc_xml_node9.rb +32 -0
- data/test/tc_xml_node_copy.rb +40 -0
- data/test/tc_xml_node_set.rb +24 -0
- data/test/tc_xml_node_set2.rb +37 -0
- data/test/tc_xml_node_text.rb +17 -0
- data/test/tc_xml_node_xlink.rb +28 -0
- data/test/tc_xml_parser.rb +190 -0
- data/test/tc_xml_parser2.rb +16 -0
- data/test/tc_xml_parser3.rb +23 -0
- data/test/tc_xml_parser4.rb +33 -0
- data/test/tc_xml_parser5.rb +27 -0
- data/test/tc_xml_parser6.rb +23 -0
- data/test/tc_xml_parser7.rb +28 -0
- data/test/tc_xml_parser8.rb +32 -0
- data/test/tc_xml_parser9.rb +11 -0
- data/test/tc_xml_parser_context.rb +88 -0
- data/test/tc_xml_reader.rb +112 -0
- data/test/tc_xml_sax_parser.rb +104 -0
- data/test/tc_xml_sax_parser2.rb +51 -0
- data/test/tc_xml_xinclude.rb +30 -0
- data/test/tc_xml_xpath.rb +38 -0
- data/test/tc_xml_xpath2.rb +14 -0
- data/test/tc_xml_xpointer.rb +78 -0
- data/vc/libxml.sln +20 -0
- data/vc/libxml.vcproj +389 -0
- data/work/Rakefile +247 -0
- data/work/task/make +26 -0
- data/work/task/memory +37 -0
- data/work/task/rdoc +39 -0
- data/work/task/setup +1616 -0
- data/work/task/test +29 -0
- data/work/test/ets_runner.rb +33 -0
- data/work/test/libxml_test.rb +3 -0
- data/work/test/runner.rb +0 -0
- data/work/test/runner_ets.rb +33 -0
- data/work/vc/debug/libxml.exp +0 -0
- data/work/vc/debug/libxml.ilk +0 -0
- data/work/vc/debug/libxml.lib +0 -0
- data/work/vc/debug/libxml.pdb +0 -0
- data/work/vc/debug/libxml.so +0 -0
- metadata +224 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
/* $Id: ruby_xml_xpath.h 207 2007-11-14 07:51:46Z danj $ */
|
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 cXMLXPath;
|
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
|
+
VALUE ruby_xml_xpath_find2(VALUE anode, VALUE xpath_expr, VALUE nslist);
|
20
|
+
|
21
|
+
void ruby_init_xml_xpath(void);
|
22
|
+
|
23
|
+
#endif
|
@@ -0,0 +1,118 @@
|
|
1
|
+
/* $Id: ruby_xml_xpath_context.c 300 2008-07-01 19:14:15Z cfis $ */
|
2
|
+
|
3
|
+
/* Please see the LICENSE file for copyright and distribution information */
|
4
|
+
|
5
|
+
#include "ruby_libxml.h"
|
6
|
+
#include "ruby_xml_xpath_context.h"
|
7
|
+
|
8
|
+
VALUE cXMLXPathContext;
|
9
|
+
|
10
|
+
/*
|
11
|
+
* call-seq:
|
12
|
+
* context.doc => document
|
13
|
+
*
|
14
|
+
* Obtain the XML::Document associated with this XPath.
|
15
|
+
*/
|
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
|
+
|
24
|
+
|
25
|
+
void
|
26
|
+
ruby_xml_xpath_context_free(xmlXPathContextPtr ctxt) {
|
27
|
+
if (ctxt != NULL) {
|
28
|
+
xmlXPathFreeContext(ctxt);
|
29
|
+
ctxt = NULL;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
|
34
|
+
void
|
35
|
+
ruby_xml_xpath_context_mark(xmlXPathContextPtr ctxt) {
|
36
|
+
if (ctxt == NULL ) return;
|
37
|
+
if (ctxt->doc != NULL && ctxt->doc->_private != NULL)
|
38
|
+
rb_gc_mark((VALUE)ctxt->doc->_private);
|
39
|
+
}
|
40
|
+
|
41
|
+
|
42
|
+
VALUE
|
43
|
+
ruby_xml_xpath_context_wrap(xmlXPathContextPtr ctxt) {
|
44
|
+
return Data_Wrap_Struct(cXMLXPathContext,
|
45
|
+
ruby_xml_xpath_context_mark,
|
46
|
+
ruby_xml_xpath_context_free,
|
47
|
+
ctxt);
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
VALUE
|
52
|
+
ruby_xml_xpath_context_new(VALUE anode) {
|
53
|
+
ruby_xml_document_t *rxd;
|
54
|
+
ruby_xml_node *node;
|
55
|
+
xmlXPathContextPtr ctxt;
|
56
|
+
|
57
|
+
if (rb_obj_is_kind_of(anode,cXMLDocument) == Qtrue ) {
|
58
|
+
Data_Get_Struct(anode,ruby_xml_document_t,rxd);
|
59
|
+
if (rxd->doc == NULL) return(Qnil);
|
60
|
+
|
61
|
+
ctxt = xmlXPathNewContext(rxd->doc);
|
62
|
+
if (ctxt == NULL) return(Qnil);
|
63
|
+
|
64
|
+
} else if (rb_obj_is_kind_of(anode,cXMLNode) == Qtrue ) {
|
65
|
+
Data_Get_Struct(anode, ruby_xml_node, node);
|
66
|
+
if (node->node->doc == NULL)
|
67
|
+
rb_raise(rb_eTypeError,"Supplied node must be part of a document");
|
68
|
+
|
69
|
+
ctxt = xmlXPathNewContext(node->node->doc);
|
70
|
+
if (ctxt == NULL) return(Qnil);
|
71
|
+
|
72
|
+
} else {
|
73
|
+
rb_raise(rb_eTypeError,"create context requires a document or node. Supplied a %s?",
|
74
|
+
rb_obj_as_string(anode));
|
75
|
+
}
|
76
|
+
|
77
|
+
return ruby_xml_xpath_context_wrap(ctxt);
|
78
|
+
}
|
79
|
+
|
80
|
+
/*
|
81
|
+
* call-seq:
|
82
|
+
* context.register_namespace(prefix, uri) => (true|false)
|
83
|
+
*
|
84
|
+
* Register the specified namespace URI with the specified prefix
|
85
|
+
* in this context.
|
86
|
+
*/
|
87
|
+
VALUE
|
88
|
+
ruby_xml_xpath_context_register_namespace(VALUE self, VALUE prefix, VALUE uri) {
|
89
|
+
xmlXPathContextPtr ctxt;
|
90
|
+
|
91
|
+
Data_Get_Struct(self, xmlXPathContext, ctxt);
|
92
|
+
if (xmlXPathRegisterNs(ctxt,
|
93
|
+
(xmlChar*)StringValuePtr(prefix),
|
94
|
+
(xmlChar*)StringValuePtr(uri))
|
95
|
+
== 0) {
|
96
|
+
return(Qtrue);
|
97
|
+
} else {
|
98
|
+
/* Should raise an exception, IMHO (whose?, why shouldnt it? -danj)*/
|
99
|
+
rb_warning("register namespace failed");
|
100
|
+
return(Qfalse);
|
101
|
+
}
|
102
|
+
}
|
103
|
+
|
104
|
+
// Rdoc needs to know
|
105
|
+
#ifdef RDOC_NEVER_DEFINED
|
106
|
+
mXML = rb_define_module("XML");
|
107
|
+
cXMLXPath = rb_define_class_under(mXML, "XPath", rb_cObject);
|
108
|
+
#endif
|
109
|
+
|
110
|
+
void
|
111
|
+
ruby_init_xml_xpath_context(void) {
|
112
|
+
cXMLXPathContext = rb_define_class_under(cXMLXPath, "Context", rb_cObject);
|
113
|
+
|
114
|
+
rb_define_method(cXMLXPathContext, "register_namespace",
|
115
|
+
ruby_xml_xpath_context_register_namespace, 2);
|
116
|
+
rb_define_method(cXMLXPathContext, "doc",
|
117
|
+
ruby_xml_xpath_context_doc_get, 0);
|
118
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/* $Id: ruby_xml_xpath_context.h 207 2007-11-14 07:51:46Z danj $ */
|
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
|
+
typedef struct ruby_xml_xpath_context {
|
11
|
+
VALUE xd;
|
12
|
+
xmlXPathContextPtr ctxt;
|
13
|
+
} ruby_xml_xpath_context;
|
14
|
+
|
15
|
+
VALUE ruby_xml_xpath_context_wrap(xmlXPathContextPtr ctxt);
|
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
|
@@ -0,0 +1,293 @@
|
|
1
|
+
/* $Id: $ */
|
2
|
+
|
3
|
+
#include "ruby_libxml.h"
|
4
|
+
|
5
|
+
/*
|
6
|
+
* Document-class: XML::XPath::Object
|
7
|
+
*
|
8
|
+
* All XPath and XPointer evals result in this type.
|
9
|
+
* nodeset should become entirely virtual and refer back to
|
10
|
+
* this class/data structure.
|
11
|
+
*
|
12
|
+
*/
|
13
|
+
VALUE cXMLXPathObject;
|
14
|
+
|
15
|
+
|
16
|
+
static VALUE
|
17
|
+
ruby_xml_xpath_object_tabref(xmlXPathObjectPtr xpop, int apos) {
|
18
|
+
|
19
|
+
if (apos < 0 )
|
20
|
+
apos=xpop->nodesetval->nodeNr+apos;
|
21
|
+
|
22
|
+
if (apos < 0 || apos+1 > xpop->nodesetval->nodeNr )
|
23
|
+
return Qnil;
|
24
|
+
|
25
|
+
switch(xpop->nodesetval->nodeTab[apos]->type) {
|
26
|
+
case XML_ATTRIBUTE_NODE:
|
27
|
+
return ruby_xml_attr_wrap(cXMLAttr,
|
28
|
+
(xmlAttrPtr)xpop->nodesetval->nodeTab[apos]);
|
29
|
+
break;
|
30
|
+
default:
|
31
|
+
return ruby_xml_node2_wrap(cXMLNode,
|
32
|
+
xpop->nodesetval->nodeTab[apos]);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
void
|
37
|
+
ruby_xml_xpath_object_mark(xmlXPathObjectPtr xpop)
|
38
|
+
{
|
39
|
+
void * xnp;
|
40
|
+
int i;
|
41
|
+
|
42
|
+
if ( xpop->type == XPATH_NODESET && xpop->nodesetval != NULL ) {
|
43
|
+
for (i=0; i<xpop->nodesetval->nodeNr; i++) {
|
44
|
+
xnp=xpop->nodesetval->nodeTab[i]->_private;
|
45
|
+
if (xnp != NULL)
|
46
|
+
rb_gc_mark((VALUE)xnp);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
void
|
52
|
+
ruby_xml_xpath_object_free(xmlXPathObjectPtr xpop)
|
53
|
+
{
|
54
|
+
xmlXPathFreeObject(xpop);
|
55
|
+
}
|
56
|
+
|
57
|
+
VALUE
|
58
|
+
ruby_xml_xpath_object_wrap(xmlXPathObjectPtr xpop)
|
59
|
+
{
|
60
|
+
VALUE rval;
|
61
|
+
|
62
|
+
if ( xpop==NULL )
|
63
|
+
return Qnil;
|
64
|
+
|
65
|
+
switch(xpop->type) {
|
66
|
+
case XPATH_NODESET:
|
67
|
+
rval = Data_Wrap_Struct(cXMLXPathObject,
|
68
|
+
ruby_xml_xpath_object_mark,
|
69
|
+
ruby_xml_xpath_object_free,
|
70
|
+
xpop);
|
71
|
+
|
72
|
+
if (xpop->type == XPATH_NODESET && !((xpop->nodesetval == NULL) || (xpop->nodesetval->nodeNr == 0))) {
|
73
|
+
int i;
|
74
|
+
for (i = 0; i < xpop->nodesetval->nodeNr; i++) {
|
75
|
+
ruby_xml_xpath_object_tabref(xpop, i);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
break;
|
79
|
+
case XPATH_BOOLEAN:
|
80
|
+
if (xpop->boolval != 0)
|
81
|
+
rval=Qtrue;
|
82
|
+
else
|
83
|
+
rval=Qfalse;
|
84
|
+
|
85
|
+
xmlXPathFreeObject(xpop);
|
86
|
+
break;
|
87
|
+
case XPATH_NUMBER:
|
88
|
+
rval=rb_float_new(xpop->floatval);
|
89
|
+
|
90
|
+
xmlXPathFreeObject(xpop);
|
91
|
+
break;
|
92
|
+
case XPATH_STRING:
|
93
|
+
rval=rb_str_new2(xpop->stringval);
|
94
|
+
|
95
|
+
xmlXPathFreeObject(xpop);
|
96
|
+
break;
|
97
|
+
default:
|
98
|
+
xmlXPathFreeObject(xpop);
|
99
|
+
rval=Qnil;
|
100
|
+
}
|
101
|
+
return rval;
|
102
|
+
}
|
103
|
+
|
104
|
+
|
105
|
+
/*
|
106
|
+
* call-seq:
|
107
|
+
* xpath_object.to_a => [node, ..., node]
|
108
|
+
*
|
109
|
+
* Obtain an array of the nodes in this set.
|
110
|
+
*/
|
111
|
+
VALUE
|
112
|
+
ruby_xml_xpath_object_to_a(VALUE self)
|
113
|
+
{
|
114
|
+
VALUE set_ary, nodeobj;
|
115
|
+
xmlXPathObjectPtr xpop;
|
116
|
+
int i;
|
117
|
+
|
118
|
+
Data_Get_Struct(self,xmlXPathObject,xpop);
|
119
|
+
|
120
|
+
set_ary = rb_ary_new();
|
121
|
+
if (!((xpop->nodesetval == NULL) || (xpop->nodesetval->nodeNr == 0))) {
|
122
|
+
for (i = 0; i < xpop->nodesetval->nodeNr; i++) {
|
123
|
+
nodeobj = ruby_xml_xpath_object_tabref(xpop, i);
|
124
|
+
rb_ary_push(set_ary, nodeobj);
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
return(set_ary);
|
129
|
+
}
|
130
|
+
|
131
|
+
/*
|
132
|
+
* call-seq:
|
133
|
+
* xpath_object.set => Node::Set
|
134
|
+
*
|
135
|
+
* Obtain the previous type object which is really
|
136
|
+
* just a proxy back to this object. Unless the
|
137
|
+
* type is not a NODESET, in which case it is nil.
|
138
|
+
*/
|
139
|
+
VALUE
|
140
|
+
ruby_xml_xpath_object_set(VALUE self)
|
141
|
+
{
|
142
|
+
xmlXPathObjectPtr xpop;
|
143
|
+
VALUE r;
|
144
|
+
|
145
|
+
Data_Get_Struct(self,xmlXPathObject,xpop);
|
146
|
+
r=Qnil;
|
147
|
+
|
148
|
+
if (xpop->type == XPATH_NODESET)
|
149
|
+
r=ruby_xml_node_set_new2(self);
|
150
|
+
|
151
|
+
return r;
|
152
|
+
}
|
153
|
+
|
154
|
+
/*
|
155
|
+
* call-seq:
|
156
|
+
* xpath_object.empty? => (true|false)
|
157
|
+
*
|
158
|
+
* Determine whether this nodeset is empty (contains no nodes).
|
159
|
+
*/
|
160
|
+
VALUE
|
161
|
+
ruby_xml_xpath_object_empty_q(VALUE self) {
|
162
|
+
xmlXPathObjectPtr xpop;
|
163
|
+
|
164
|
+
Data_Get_Struct(self,xmlXPathObject,xpop);
|
165
|
+
|
166
|
+
if (xpop->type != XPATH_NODESET)
|
167
|
+
return Qnil;
|
168
|
+
|
169
|
+
return ( xpop->nodesetval == NULL || xpop->nodesetval->nodeNr <= 0 ) ? Qtrue : Qfalse;
|
170
|
+
}
|
171
|
+
|
172
|
+
/*
|
173
|
+
* call-seq:
|
174
|
+
* xpath_object.each { |node| ... } => self
|
175
|
+
*
|
176
|
+
* Call the supplied block for each node in this set.
|
177
|
+
*/
|
178
|
+
VALUE
|
179
|
+
ruby_xml_xpath_object_each(VALUE self)
|
180
|
+
{
|
181
|
+
xmlXPathObjectPtr xpop;
|
182
|
+
int i;
|
183
|
+
|
184
|
+
if ( ruby_xml_xpath_object_empty_q(self) == Qtrue )
|
185
|
+
return Qnil;
|
186
|
+
|
187
|
+
Data_Get_Struct(self,xmlXPathObject,xpop);
|
188
|
+
|
189
|
+
for (i = 0; i < xpop->nodesetval->nodeNr; i++) {
|
190
|
+
rb_yield(ruby_xml_xpath_object_tabref(xpop,i));
|
191
|
+
}
|
192
|
+
return(self);
|
193
|
+
}
|
194
|
+
|
195
|
+
/*
|
196
|
+
* call-seq:
|
197
|
+
* xpath_object.first => node
|
198
|
+
*
|
199
|
+
* Returns the first node in this node set, or nil if none exist.
|
200
|
+
*/
|
201
|
+
VALUE
|
202
|
+
ruby_xml_xpath_object_first(VALUE self) {
|
203
|
+
if ( ruby_xml_xpath_object_empty_q(self) == Qtrue )
|
204
|
+
return Qnil;
|
205
|
+
|
206
|
+
return ruby_xml_xpath_object_tabref((xmlXPathObjectPtr)DATA_PTR(self),0);
|
207
|
+
}
|
208
|
+
|
209
|
+
/*
|
210
|
+
* call-seq:
|
211
|
+
* xpath_object[i] => node
|
212
|
+
*
|
213
|
+
* array index into set of nodes
|
214
|
+
*/
|
215
|
+
VALUE
|
216
|
+
ruby_xml_xpath_object_aref(VALUE self, VALUE aref) {
|
217
|
+
if ( ruby_xml_xpath_object_empty_q(self) == Qtrue )
|
218
|
+
return Qnil;
|
219
|
+
|
220
|
+
return ruby_xml_xpath_object_tabref((xmlXPathObjectPtr)DATA_PTR(self),
|
221
|
+
NUM2INT(aref));
|
222
|
+
}
|
223
|
+
|
224
|
+
/*
|
225
|
+
* call-seq:
|
226
|
+
* xpath_object.length => num
|
227
|
+
*
|
228
|
+
* Obtain the length of the nodesetval node list.
|
229
|
+
*/
|
230
|
+
VALUE
|
231
|
+
ruby_xml_xpath_object_length(VALUE self) {
|
232
|
+
xmlXPathObjectPtr xpop;
|
233
|
+
|
234
|
+
if ( ruby_xml_xpath_object_empty_q(self) == Qtrue )
|
235
|
+
return INT2FIX(0);
|
236
|
+
|
237
|
+
Data_Get_Struct(self,xmlXPathObject,xpop);
|
238
|
+
|
239
|
+
return INT2NUM(xpop->nodesetval->nodeNr);
|
240
|
+
}
|
241
|
+
|
242
|
+
VALUE
|
243
|
+
ruby_xml_xpath_object_set_type(VALUE self)
|
244
|
+
{
|
245
|
+
xmlXPathObjectPtr xpop;
|
246
|
+
|
247
|
+
Data_Get_Struct(self,xmlXPathObject,xpop);
|
248
|
+
|
249
|
+
return INT2FIX(xpop->type);
|
250
|
+
}
|
251
|
+
|
252
|
+
VALUE
|
253
|
+
ruby_xml_xpath_object_string(VALUE self)
|
254
|
+
{
|
255
|
+
xmlXPathObjectPtr xpop;
|
256
|
+
|
257
|
+
Data_Get_Struct(self,xmlXPathObject,xpop);
|
258
|
+
|
259
|
+
if (xpop->stringval == NULL)
|
260
|
+
return Qnil;
|
261
|
+
|
262
|
+
return rb_str_new2((const char*) xpop->stringval);
|
263
|
+
}
|
264
|
+
|
265
|
+
// Rdoc needs to know
|
266
|
+
#ifdef RDOC_NEVER_DEFINED
|
267
|
+
mXML = rb_define_module("XML");
|
268
|
+
cXMLXPath = rb_define_class_under(mXML, "XPath", rb_cObject);
|
269
|
+
#endif
|
270
|
+
|
271
|
+
void
|
272
|
+
ruby_init_xml_xpath_object(void) {
|
273
|
+
cXMLXPathObject = rb_define_class_under(cXMLXPath, "Object", rb_cObject);
|
274
|
+
|
275
|
+
rb_include_module(cXMLXPathObject, rb_const_get(rb_cObject, rb_intern("Enumerable")));
|
276
|
+
|
277
|
+
rb_define_method(cXMLXPathObject, "each", ruby_xml_xpath_object_each, 0);
|
278
|
+
rb_define_method(cXMLXPathObject, "set_type", ruby_xml_xpath_object_set_type, 0);
|
279
|
+
rb_define_method(cXMLXPathObject, "empty?", ruby_xml_xpath_object_empty_q, 0);
|
280
|
+
rb_define_method(cXMLXPathObject, "first", ruby_xml_xpath_object_first, 0);
|
281
|
+
rb_define_method(cXMLXPathObject, "length", ruby_xml_xpath_object_length, 0);
|
282
|
+
rb_define_method(cXMLXPathObject, "size", ruby_xml_xpath_object_length, 0);
|
283
|
+
rb_define_method(cXMLXPathObject, "to_a", ruby_xml_xpath_object_to_a, 0);
|
284
|
+
rb_define_method(cXMLXPathObject, "[]", ruby_xml_xpath_object_aref, 1);
|
285
|
+
|
286
|
+
rb_define_method(cXMLXPathObject, "string", ruby_xml_xpath_object_string, 0);
|
287
|
+
|
288
|
+
rb_include_module(cXMLNodeSet, rb_const_get(rb_cObject, rb_intern("Enumerable")));
|
289
|
+
|
290
|
+
/* Give the NodeSet type, but it is pointless */
|
291
|
+
rb_define_method(cXMLXPathObject, "set", ruby_xml_xpath_object_set, 0);
|
292
|
+
|
293
|
+
}
|