From: Myun2 Date: Fri, 24 Sep 2010 11:26:59 +0000 (+0900) Subject: dom2.hpp: elementにget_attributes()追加, operator / 対応 X-Git-Tag: 20111130_shapeup_prev~168 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=b3112ab25375c560c58ee0494f4158bff5a58b18;p=roast%2Froast.git dom2.hpp: elementにget_attributes()追加, operator / 対応 --- diff --git a/roast/include/roast/xml/roast_xml/dom2.hpp b/roast/include/roast/xml/roast_xml/dom2.hpp index 49ec8573..bebea293 100644 --- a/roast/include/roast/xml/roast_xml/dom2.hpp +++ b/roast/include/roast/xml/roast_xml/dom2.hpp @@ -19,6 +19,18 @@ namespace roast { //////////////////////////////////////////////////////////////// + namespace rxpath + { + struct elem_name{ + const char* name; + elem_name(const char* name_in) : name(name_in) {} + }; + + struct aster_{} aster; + } + + //////////////////////////////////////////////////////////////// + struct node { enum node_types_e @@ -55,18 +67,54 @@ namespace roast /////////////////////////////////////////////////// - ::std::vector get_child_elements() + ::std::vector get_child_elements(const char* tagname=NULL) { ::std::vector el; for(size_t i=0; im_node_type == node::TYPE_ELEMENT ) + if ( p->m_node_type == node::TYPE_ELEMENT && + ( !tagname || tagname && ((element*)p)->name == tagname ) ) el.push_back((element*)p); } return el; } + + ::std::vector get_attributes(const char* attrname=NULL) + { + ::std::vector al; + + for(size_t i=0; im_node_type == node::TYPE_ATTRIBUTE && + ( !attrname || attrname && ((attribute*)p)->name == attrname ) ) + al.push_back((attribute*)p); + } + return al; + } + + /////////////////////////////////////////////////// + + //node_list_t select(_RxPath + ::std::vector operator / (const rxpath::elem_name& en) + { + return get_child_elements(en.name); + } + + ::std::vector operator / (const rxpath::aster_&) + { + return get_child_elements(); + } + + ::std::vector operator / (const char* s) + { + if ( s[0] == '*' && s[1] == '\0' ) + return get_child_elements(); + else + return get_child_elements(); + } }; typedef ::std::vector element_list_t;