Changeset 7714b02d25b8c8852538264cec4a37577d682068
- Timestamp:
- 08/05/07 23:41:01 (17 months ago)
- Author:
- Mark Guzman <segfault@…>
- Parents:
- 44461b23e49dc856ad7b26ea70d01c4b23c56e1f
- Children:
- 353e95b8dce9775aee6b01ec373cb939d4d76baf
- git-committer:
- Mark Guzman <segfault@hasno.info> / 2007-08-06T03:41:01Z+0000
- Message:
-
starting to add hpricot-like features ala (node/"xpath") and FastXml?("my doc info")
git-svn-id: svn://hasno.info/fastxml/trunk@24 b3082176-f867-4bde-be85-e3c57d66f029
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r44461b
|
r7714b0
|
|
| 75 | 75 | xmlXPathInit(); |
| 76 | 76 | VALUE rb_mFastXml = rb_define_module( "FastXml" ); |
| 77 | | rb_define_const( rb_mFastXml, "VERSION", rb_str_new2( "0.1" ) ); |
| | 77 | //rb_define_const( rb_mFastXml, "VERSION", rb_str_new2( "0.1" ) ); |
| 78 | 78 | rb_cFastXmlDoc = rb_define_class_under( rb_mFastXml, "Doc", rb_cObject ); |
| 79 | 79 | rb_cFastXmlNode = rb_define_class_under( rb_mFastXml, "Node", rb_cObject ); |
| 80 | 80 | |
| 81 | 81 | /* Doc */ |
| 82 | | rb_include_module( rb_cFastXmlDoc, rb_mEnumerable ); |
| | 82 | //rb_include_module( rb_cFastXmlDoc, rb_mEnumerable ); |
| 83 | 83 | rb_define_method( rb_cFastXmlDoc, "initialize", fastxml_doc_initialize, 1 ); |
| 84 | 84 | rb_define_method( rb_cFastXmlDoc, "search", fastxml_doc_search, 1 ); |
| … |
… |
|
| 91 | 91 | |
| 92 | 92 | /* Node */ |
| 93 | | rb_include_module( rb_cFastXmlNode, rb_mEnumerable ); |
| | 93 | //rb_include_module( rb_cFastXmlNode, rb_mEnumerable ); |
| 94 | 94 | rb_define_method( rb_cFastXmlNode, "initialize", fastxml_node_initialize, 0 ); |
| 95 | 95 | rb_define_method( rb_cFastXmlNode, "search", fastxml_node_search, 1 ); |
| … |
… |
|
| 105 | 105 | rb_define_method( rb_cFastXmlNode, "prev", fastxml_node_prev, 0 ); |
| 106 | 106 | rb_define_method( rb_cFastXmlNode, "parent", fastxml_node_parent, 0 ); |
| | 107 | |
| | 108 | rb_require( "lib/fastxml_lib" ); |
| 107 | 109 | } |
| 108 | 110 | |
-
|
r79be80
|
r7714b0
|
|
| 3 | 3 | VERSION = "0.1.%s" % "$Rev$".gsub(/\$Rev:\s+/, '').gsub(/\s*\$$/, '') |
| 4 | 4 | end |
| | 5 | |
| | 6 | module FastXml::Common |
| | 7 | def children_of_type(type) |
| | 8 | self.search( "//#{type}" ) |
| | 9 | end |
| | 10 | |
| | 11 | def each_child(&blk) |
| | 12 | self.children.each { |chld| yield chld } |
| | 13 | end |
| | 14 | |
| | 15 | def /(xpath) |
| | 16 | self.search( "/#{xpath.to_s}" ) |
| | 17 | end |
| | 18 | |
| | 19 | alias :to_s :display |
| | 20 | end |
| | 21 | |
| | 22 | class FastXml::Doc |
| | 23 | include FastXml::Common |
| | 24 | |
| | 25 | def doc? |
| | 26 | true |
| | 27 | end |
| | 28 | |
| | 29 | def doctype? |
| | 30 | nil |
| | 31 | end |
| | 32 | end |
| | 33 | |
| | 34 | class FastXml::Node |
| | 35 | include FastXml::Common |
| | 36 | def doc? |
| | 37 | false |
| | 38 | end |
| | 39 | end |
| | 40 | |
| | 41 | |
| | 42 | def FastXml(data=nil, opts = {}, &blk) |
| | 43 | FastXml::Doc.new data |
| | 44 | end |