Changeset 1285f7e89455bcd74b48cf238879deba2b15b403
- Timestamp:
- 07/18/07 23:18:21 (18 months ago)
- Author:
- Mark Guzman <segfault@…>
- Parents:
- 89a3f8cdc9508c6dea8e60d6aea2dd33ee3a10a7
- Children:
- b9a586225c39677d89f1197d41d2eb7bf357565e
- git-committer:
- Mark Guzman <segfault@hasno.info> / 2007-07-19T03:18:21Z+0000
- Message:
-
added xml attr to node
added xpath accessor to node which will ask a node for it's xpath string
git-svn-id: svn://hasno.info/fastxml/trunk@14 b3082176-f867-4bde-be85-e3c57d66f029
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r595f64
|
r1285f7
|
|
| 38 | 38 | static VALUE fastxml_node_innerxml(VALUE self); |
| 39 | 39 | static VALUE fastxml_node_to_s(VALUE self); |
| | 40 | static VALUE fastxml_node_xpath(VALUE self); |
| | 41 | static VALUE fastxml_node_attr(VALUE self, VALUE attr_name); |
| 40 | 42 | |
| 41 | 43 | |
| … |
… |
|
| 66 | 68 | rb_define_method( rb_cFastXmlNode, "content=", fastxml_node_value_set, 1 ); |
| 67 | 69 | rb_define_method( rb_cFastXmlNode, "inner_xml", fastxml_node_innerxml, 0 ); |
| | 70 | rb_define_method( rb_cFastXmlNode, "xpath", fastxml_node_xpath, 0 ); |
| | 71 | rb_define_method( rb_cFastXmlNode, "attr", fastxml_node_attr, 1 ); |
| 68 | 72 | } |
| 69 | 73 | |
| … |
… |
|
| 96 | 100 | |
| 97 | 101 | return ret; |
| | 102 | } |
| | 103 | |
| | 104 | static VALUE fastxml_node_attr(VALUE self, VALUE attr_name) |
| | 105 | { |
| | 106 | VALUE ret, dv; |
| | 107 | fxml_data_t *data; |
| | 108 | xmlChar *raw_ret, *name_str; |
| | 109 | |
| | 110 | dv = rb_iv_get( self, "@lxml_node" ); |
| | 111 | Data_Get_Struct( dv, fxml_data_t, data ); |
| | 112 | |
| | 113 | name_str = (xmlChar*)StringValuePtr( attr_name ); |
| | 114 | raw_ret = xmlGetProp( data->node, name_str ); |
| | 115 | if (raw_ret == NULL) |
| | 116 | return Qnil; |
| | 117 | |
| | 118 | ret = rb_str_new2( (const char*)raw_ret ); |
| | 119 | xmlFree( raw_ret ); |
| | 120 | |
| | 121 | return ret; |
| | 122 | } |
| | 123 | |
| | 124 | static VALUE fastxml_node_xpath(VALUE self) |
| | 125 | { |
| | 126 | VALUE ret, dv; |
| | 127 | fxml_data_t *data; |
| | 128 | xmlChar *raw_ret; |
| | 129 | |
| | 130 | dv = rb_iv_get( self, "@lxml_node" ); |
| | 131 | Data_Get_Struct( dv, fxml_data_t, data ); |
| | 132 | |
| | 133 | raw_ret = xmlGetNodePath( data->node ); |
| | 134 | if (raw_ret == NULL) |
| | 135 | return Qnil; |
| | 136 | |
| | 137 | ret = rb_str_new2( (const char*)raw_ret ); |
| | 138 | xmlFree( raw_ret ); |
| | 139 | |
| | 140 | return ret; |
| 98 | 141 | } |
| 99 | 142 | |
| … |
… |
|
| 112 | 155 | spec = xmlEncodeSpecialChars( data->doc, ents ); |
| 113 | 156 | |
| 114 | | printf("setting chars: %s\n", spec); |
| | 157 | // printf("setting chars: %s\n", spec); |
| 115 | 158 | xmlNodeSetContent( data->node, spec ); |
| 116 | 159 | xmlFree( ents ); |
| … |
… |
|
| 176 | 219 | |
| 177 | 220 | if (NIL_P(raw_xpath)) { |
| 178 | | printf("got nil\n"); |
| | 221 | //printf("got nil\n"); |
| 179 | 222 | rb_raise(rb_eArgError, "nil passed as xpath"); |
| 180 | 223 | return Qnil; |
| … |
… |
|
| 183 | 226 | xpath_s = rb_obj_as_string( raw_xpath ); |
| 184 | 227 | xpath_expr = (xmlChar*)StringValuePtr( xpath_s ); |
| 185 | | printf("got xpath: %s\n", xpath_expr); |
| | 228 | //printf("got xpath: %s\n", xpath_expr); |
| 186 | 229 | |
| 187 | 230 | dv = rb_iv_get( self, "@lxml_doc" ); |
| … |
… |
|
| 205 | 248 | xmlXPathFreeObject( xpath_obj ); |
| 206 | 249 | xmlXPathFreeContext( xpath_ctx ); |
| 207 | | printf("done\n"); |
| | 250 | //printf("done\n"); |
| 208 | 251 | |
| 209 | 252 | return ret; |
| … |
… |
|
| 220 | 263 | ret = rb_ary_new(); |
| 221 | 264 | size = (nodes) ? nodes->nodeNr : 0; |
| 222 | | printf("size: %d\n", size); |
| | 265 | //printf("size: %d\n", size); |
| 223 | 266 | |
| 224 | 267 | for (i = 0; i < size; i++) { |
| 225 | 268 | cur = nodes->nodeTab[i]; |
| 226 | | printf( "checking node: %s type: %d\n", cur->name, cur->type ); |
| | 269 | //printf( "checking node: %s type: %d\n", cur->name, cur->type ); |
| 227 | 270 | if (cur->type == XML_ELEMENT_NODE) |
| 228 | 271 | continue; |
| … |
… |
|
| 301 | 344 | |
| 302 | 345 | cstr = StringValuePtr( data_s ); |
| 303 | | printf( "cstr: %s\n", cstr ); |
| | 346 | //printf( "cstr: %s\n", cstr ); |
| 304 | 347 | |
| 305 | 348 | xmlInitParser(); |
| … |
… |
|
| 332 | 375 | static void fastxml_data_free( fxml_data_t *data ) |
| 333 | 376 | { |
| 334 | | printf("attempting to free\n"); |
| | 377 | //printf("attempting to free\n"); |
| 335 | 378 | if (data != NULL) |
| 336 | 379 | { |