Changeset b19646bb6e2ebc2bbc3854e36fd29ca5f91f4481
- Timestamp:
- 10/17/07 00:23:08 (15 months ago)
- Author:
- Mark Guzman <segfault@…>
- Parents:
- ecdb845a0ca9053bc4c21b1ea3560fe344b076a2
- Children:
- 7a0abd0654bc03960da3384f2d96e68aa85c5984
- git-committer:
- Mark Guzman <segfault@hasno.info> / 2007-10-17T04:23:08Z+0000
- Message:
-
adding options to direct the parser
added optional block parameter
git-svn-id: svn://hasno.info/fastxml/trunk@41 b3082176-f867-4bde-be85-e3c57d66f029
- Location:
- ext
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
recdb84
|
rb19646
|
|
| 11 | 11 | VALUE rb_cFastXmlNode; |
| 12 | 12 | VALUE rb_cFastXmlNodeList; |
| | 13 | VALUE rb_sValidateDtd; |
| | 14 | VALUE rb_sForgivingParse; |
| 13 | 15 | ID s_readlines; |
| 14 | 16 | ID s_to_s; |
| … |
… |
|
| 34 | 36 | |
| 35 | 37 | /* Doc */ |
| 36 | | rb_define_method( rb_cFastXmlDoc, "initialize", fastxml_doc_initialize, 1 ); |
| | 38 | rb_sValidateDtd = ID2SYM( rb_intern("validate") ); |
| | 39 | rb_sForgivingParse = ID2SYM( rb_intern("forgiving") ); |
| | 40 | rb_define_method( rb_cFastXmlDoc, "initialize", fastxml_doc_initialize, -1 ); |
| 37 | 41 | rb_define_method( rb_cFastXmlDoc, "search", fastxml_doc_search, 1 ); |
| 38 | 42 | rb_define_method( rb_cFastXmlDoc, "to_s", fastxml_doc_to_s, 0 ); |
| … |
… |
|
| 245 | 249 | |
| 246 | 250 | xpath_obj = xmlXPathCompiledEval( xpath_xpr, xpath_ctx ); |
| 247 | | if(xpath_obj == NULL) { |
| | 251 | if (xpath_obj == NULL) { |
| 248 | 252 | rb_raise( rb_eRuntimeError, "unable to evaluate xpath expression" ); |
| 249 | 253 | xmlXPathFreeCompExpr( xpath_xpr ); |
-
|
recdb84
|
rb19646
|
|
| 39 | 39 | RUBY_EXTERN VALUE rb_cFastXmlNode; |
| 40 | 40 | |
| | 41 | RUBY_EXTERN VALUE rb_sValidateDtd; |
| | 42 | RUBY_EXTERN VALUE rb_sForgivingParse; |
| | 43 | |
| 41 | 44 | RUBY_EXTERN ID s_readlines; |
| 42 | 45 | RUBY_EXTERN ID s_to_s; |
-
|
recdb84
|
rb19646
|
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | | VALUE fastxml_doc_initialize(VALUE self, VALUE xml_doc_str) |
| | 123 | VALUE fastxml_doc_initialize(int argc, VALUE* argv, VALUE self) |
| 124 | 124 | { |
| 125 | | VALUE data_s, dv, lines; |
| | 125 | VALUE data_s, dv, lines, xml_doc_str, opts, blk; |
| 126 | 126 | fxml_data_t *data; |
| 127 | 127 | int parser_opts = XML_PARSE_NOERROR | XML_PARSE_NOWARNING; |
| 128 | | int parse_dtd = XML_PARSE_DTDLOAD | XML_PARSE_DTDATTR | XML_PARSE_DTDVALID; |
| 129 | | int parse_forgiving = XML_PARSE_RECOVER; |
| | 128 | |
| | 129 | if (rb_scan_args( argc, argv, "11&", &xml_doc_str, &opts, &blk ) == 0) |
| | 130 | return Qnil; // error state |
| 130 | 131 | |
| 131 | 132 | if (NIL_P(xml_doc_str)) { |
| 132 | 133 | rb_raise(rb_eArgError, "nil passed as xml document"); |
| 133 | 134 | return Qnil; |
| | 135 | } |
| | 136 | |
| | 137 | if (opts != Qnil) { |
| | 138 | if (rb_hash_aref(opts, rb_sValidateDtd) != Qnil) |
| | 139 | parser_opts = parser_opts | XML_PARSE_DTDLOAD | XML_PARSE_DTDATTR | XML_PARSE_DTDVALID; |
| | 140 | |
| | 141 | if (rb_hash_aref(opts, rb_sForgivingParse) != Qnil) |
| | 142 | parser_opts = parser_opts | XML_PARSE_RECOVER; |
| 134 | 143 | } |
| 135 | 144 | |
| … |
… |
|
| 157 | 166 | rb_iv_set(self, "@lxml_doc", dv ); |
| 158 | 167 | |
| | 168 | if (blk != Qnil) |
| | 169 | rb_yield( self ); |
| | 170 | |
| 159 | 171 | return self; |
| 160 | 172 | } |
-
|
recdb84
|
rb19646
|
|
| 5 | 5 | #ifndef fastxml_doc_h |
| 6 | 6 | #define fastxml_doc_h |
| 7 | | RUBY_EXTERN VALUE fastxml_doc_initialize(VALUE self, VALUE data); |
| | 7 | RUBY_EXTERN VALUE fastxml_doc_initialize(int argc, VALUE* argv, VALUE self); |
| 8 | 8 | RUBY_EXTERN VALUE fastxml_doc_search(VALUE self, VALUE raw_xpath, VALUE blk); |
| 9 | 9 | RUBY_EXTERN VALUE fastxml_doc_to_s(VALUE self); |