public
Description: ruby libxml library targetting speed and ease of use. provides an hpricot-like interface to xml
Homepage: http://trac.hasno.info/fastxml
Clone URL: git://github.com/segfault/fastxml.git
Search Repo:
fixed a major bug involving xpath search results, was causing a bus err
added some tests to catch that bug
segfault (author)
Sun May 11 22:45:24 -0700 2008
commit  9f39fd9cbbe80b654eafe1440811cb873d09afea
tree    5e5ed27203a3dfff55e4fdc5a31942a5babc6003
parent  93e12c6952c09403787ed9290cfe471f405e3360
...
243
244
245
246
 
247
248
249
...
243
244
245
 
246
247
248
249
0
@@ -243,7 +243,7 @@
0
   if (root->ns != NULL) { // we have a base namespace, this is going to get "interesting"
0
     root_ns = (xmlChar*)root->ns->prefix;
0
     if (root_ns == NULL)
0
- root_ns = (xmlChar*)"myFunkyLittleRootNsNotToBeUseByAnyoneElseIHope";
0
+ root_ns = (xmlChar*)"__myFunkyLittleRootNsNotToBeUseByAnyoneElseIHope__";
0
             // alternatives? how do other xpath processors handle root/default namespaces?
0
 
0
     xmlXPathRegisterNs( xpath_ctx, root_ns, root->ns->href );
...
40
41
42
43
44
 
45
46
47
48
 
 
 
49
50
51
52
53
54
...
71
72
73
74
 
75
76
 
77
78
79
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
83
84
...
88
89
90
91
 
92
93
94
...
40
41
42
 
 
43
44
 
 
 
45
46
47
48
49
50
51
52
53
...
70
71
72
 
73
74
 
75
76
 
 
 
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
...
99
100
101
 
102
103
104
105
0
@@ -40,12 +40,11 @@
0
     dv = rb_iv_get( self, "@lxml_doc" );
0
     Data_Get_Struct( dv, fxml_data_t, data );
0
   
0
- if (data->list_len == -1)
0
- {
0
+ if (data->list_len == EMPTY_NODELIST) {
0
     data->list_len = 0;
0
- cur = data->list;
0
- while (cur != NULL)
0
- {
0
+
0
+ cur = data->list;
0
+ while (cur != NULL) {
0
       data->list_len++;
0
       cur = cur->next;
0
     }
0
0
0
0
@@ -71,14 +70,26 @@
0
 VALUE fastxml_nodeset_obj_to_ary(fxml_data_t *root)
0
 {
0
   VALUE ret;
0
- xmlNodePtr cur = root->xpath_obj->nodesetval->nodeTab;
0
+ xmlNodePtr cur, sub = NULL;
0
   int i;
0
-
0
+
0
    ret = rb_ary_new();
0
- for (i = 0; i < root->list_len; i++) {
0
- rb_ary_push( ret, fastxml_raw_node_to_obj( cur ) );
0
- cur++;
0
+ if (root->xpath_obj->nodesetval->nodeTab != NULL) {
0
+ cur = *root->xpath_obj->nodesetval->nodeTab;
0
+ for (i = 0; i < root->list_len; i++) {
0
+ if (cur->type != XML_ELEMENT_NODE)
0
+ continue;
0
+
0
+ rb_ary_push( ret, fastxml_raw_node_to_obj( cur ) );
0
+ sub = cur->next;
0
+ while (sub != NULL) {
0
+ rb_ary_push( ret, fastxml_raw_node_to_obj( sub ) );
0
+ sub = sub->next;
0
+ }
0
+ cur++;
0
+ }
0
     }
0
+
0
   
0
   return ret;
0
 }
0
@@ -88,7 +99,7 @@
0
   VALUE lst = rb_iv_get( self, "@list" );
0
 
0
   if (lst == Qnil) {
0
- if (data->xpath_obj != NULL) {
0
+ if (data->xpath_obj != NULL) {
0
       lst = fastxml_nodeset_obj_to_ary( data );
0
       rb_iv_set( self, "@list", lst );
0
     } else {
...
4
5
6
 
 
 
 
7
8
9
...
4
5
6
7
8
9
10
11
12
13
0
@@ -4,6 +4,10 @@
0
 
0
 #ifndef fastxml_nodelist_h
0
 #define fastxml_nodelist_h
0
+
0
+#define EMPTY_NODELIST -1
0
+#define EMPTY_NODESET -2
0
+
0
 RUBY_EXTERN VALUE fastxml_nodelist_initialize(VALUE self);
0
 RUBY_EXTERN VALUE fastxml_nodelist_inspect(VALUE self);
0
 RUBY_EXTERN VALUE fastxml_nodelist_length(VALUE self);
...
42
43
44
 
 
 
 
 
 
 
 
 
 
 
 
 
45
46
...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
0
@@ -42,6 +42,19 @@
0
     @list.inspect.should_not be_nil
0
   end
0
   
0
+ it 'should provide a first method' do
0
+ @list.should respond_to( :first )
0
+ @list.first.should_not be_nil
0
+ @list.first.should == @list[0]
0
+ @list.first.to_s.should == @list[0].to_s
0
+ end
0
+
0
+ it 'should provide a last method' do
0
+ @list.should respond_to( :last )
0
+ @list.last.should_not be_nil
0
+ @list.last.should == @list[-1]
0
+ @list.last.to_s.should == @list[-1].to_s
0
+ end
0
 
0
 end

Comments

    No one has commented yet.