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
all current tests pass
added some caching to next/prev


git-svn-id: svn://hasno.info/fastxml/trunk@37 
b3082176-f867-4bde-be85-e3c57d66f029
segfault (author)
Wed Aug 29 20:01:28 -0700 2007
commit  e14948cc589e60846362ba0d38693b97ce1a0e16
tree    8913ebfe563ef32ec0dd949510bbcf2a9453daa3
parent  0bc9bb7d2cbeaf9d97450dc107d4cd15313cf3a7
...
147
148
149
150
151
152
 
153
154
155
...
147
148
149
 
 
 
150
151
152
153
0
@@ -147,9 +147,7 @@ VALUE fastxml_nodelist_to_obj(xmlNodePtr root, int len)
0
 VALUE fastxml_nodeset_to_obj(xmlXPathObjectPtr xpath_obj, fxml_data_t *data)
0
 {
0
     xmlNodeSetPtr nodes = xpath_obj->nodesetval;
0
- xmlNodePtr list = xmlCopyNodeList( nodes->nodeTab );
0
- //xmlNodePtr list = xmlDocCopyNodeList( data->doc, nodes->nodeTab );
0
-
0
+ xmlNodePtr list = xmlDocCopyNodeList( data->doc, nodes->nodeTab );
0
 
0
   return fastxml_nodelist_to_obj( list, (nodes) ? nodes->nodeNr : 0 );
0
 }
...
34
35
36
37
 
 
 
 
 
 
 
 
 
 
 
 
38
39
40
41
42
 
43
44
45
...
47
48
49
 
 
 
 
 
 
50
51
 
52
53
54
55
56
 
57
58
59
...
61
62
63
 
 
 
 
 
 
64
65
 
66
67
68
...
34
35
36
 
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
53
54
55
56
...
58
59
60
61
62
63
64
65
66
67
 
68
69
70
71
72
 
73
74
75
76
...
78
79
80
81
82
83
84
85
86
87
 
88
89
90
91
0
@@ -34,12 +34,23 @@ VALUE fastxml_node_initialize(VALUE self)
0
 
0
 VALUE fastxml_node_innerxml(VALUE self)
0
 {
0
- return Qnil;
0
+ VALUE dv, ret;
0
+ fxml_data_t *data;
0
+ xmlBufferPtr buf = xmlBufferCreate();
0
+
0
+ dv = rb_iv_get( self, "@lxml_doc" );
0
+ Data_Get_Struct( dv, fxml_data_t, data );
0
+
0
+ xmlNodeDump( buf, data->doc, data->node, 0, 0 );
0
+ ret = rb_str_new2( (char*)xmlBufferContent( buf ) );
0
+ xmlBufferFree( buf );
0
+
0
+ return ret;
0
 }
0
 
0
 VALUE fastxml_node_next(VALUE self)
0
 {
0
- VALUE dv;
0
+ VALUE dv, next;
0
     fxml_data_t *data;
0
 
0
     dv = rb_iv_get( self, "@lxml_doc" );
0
@@ -47,13 +58,19 @@ VALUE fastxml_node_next(VALUE self)
0
 
0
   if (data->node == NULL || (data->node != NULL && data->node->next == NULL))
0
     return Qnil;
0
+
0
+ next = rb_iv_get( self, "@next" );
0
+ if (next == Qnil) {
0
+ next = fastxml_raw_node_to_obj( data->node->next );
0
+ rb_iv_set( self, "@next", next );
0
+ }
0
   
0
- return fastxml_raw_node_to_obj( data->node->next );
0
+ return next;
0
 }
0
 
0
 VALUE fastxml_node_prev(VALUE self)
0
 {
0
- VALUE dv;
0
+ VALUE dv, prev;
0
     fxml_data_t *data;
0
 
0
     dv = rb_iv_get( self, "@lxml_doc" );
0
@@ -61,8 +78,14 @@ VALUE fastxml_node_prev(VALUE self)
0
 
0
   if (data->node == NULL || (data->node != NULL && data->node->prev == NULL))
0
     return Qnil;
0
+
0
+ prev = rb_iv_get( self, "@prev" );
0
+ if (prev == Qnil) {
0
+ prev = fastxml_raw_node_to_obj( data->node->prev );
0
+ rb_iv_set( self, "@prev", prev );
0
+ }
0
   
0
- return fastxml_raw_node_to_obj( data->node->prev );
0
+ return prev;
0
 }
0
 
0
 VALUE fastxml_node_parent(VALUE self)
...
48
49
50
 
 
 
 
 
 
 
 
51
52
53
...
48
49
50
51
52
53
54
55
56
57
58
59
60
61
0
@@ -48,6 +48,14 @@ class FastXml::NodeList
0
   def [](idx)
0
     self.entry(idx)
0
   end
0
+
0
+ def first
0
+ self.entry(0)
0
+ end
0
+
0
+ def last
0
+ self.entry(-1)
0
+ end
0
 end
0
 
0
 
...
54
55
56
57
 
58
59
...
54
55
56
 
57
58
59
0
@@ -54,6 +54,6 @@ describe FastXml::Doc, " functionality" do
0
   
0
   it 'should provide an at method' do
0
     @doc.should respond_to( :at )
0
- @doc.at( "feed" ).should_not be_nil
0
+ @doc.at( "/feed" ).should_not be_nil
0
   end
0
 end
...
55
56
57
58
 
 
59
60
61
62
63
64
 
 
 
65
66
67
...
85
86
87
88
 
89
90
91
...
55
56
57
 
58
59
60
61
62
63
 
 
64
65
66
67
68
69
...
87
88
89
 
90
91
92
93
0
@@ -55,13 +55,15 @@ describe FastXml::Node, ' functionality' do
0
   
0
   it 'should provide a next method' do
0
     @node.should respond_to( :next )
0
- @node.next.should_not be_nil
0
+ first_chld = @node.children.first
0
+ first_chld.next.should_not be_nil
0
   end
0
   
0
   it 'should provide a prev method' do
0
     @node.should respond_to( :prev )
0
- @node.prev.should be_nil
0
- @node.next.prev.should_not be_nil
0
+ first_chld = @node.children.first
0
+ first_chld.prev.should be_nil
0
+ first_chld.next.prev.should_not be_nil
0
   end
0
   
0
   it 'should provide an xpath method returning the xpath to the node' do
0
@@ -85,6 +87,6 @@ describe FastXml::Node, ' functionality' do
0
   
0
   it 'should provide an at method' do
0
     @node.should respond_to( :at )
0
- @node.at( "feed" ).should_not be_nil
0
+ @node.at( "entry" ).should_not be_nil
0
   end
0
 end
0
\ No newline at end of file

Comments

    No one has commented yet.