00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef XML_PARSERBASIC_XML_ELEMENT_PARSER_H
00021 #define XML_PARSERBASIC_XML_ELEMENT_PARSER_H
00022
00023
00024 namespace xml_parser {
00025
00035 template< typename E, typename A >
00036 class basic_xml_element_parser : public grammar_to_parser::basic_non_terminal<E,A>
00037 {
00038 public:
00039 typedef typename grammar_to_parser::basic_parser<E>::parser_list
00040 parser_list;
00041 typedef typename grammar_to_parser::basic_parser<E>::parser_list_iterator
00042 parser_list_iterator;
00043 typedef typename basic_xml_attribute_list_parser<E>::attributes_parsers_list
00044 attributes_parsers_list;
00045 typedef typename std::basic_string<E> std_string;
00046
00047 enum xml_special_chars {
00048 left_bracket = '<',
00049 right_bracket = '>',
00050 end_tag_char = '/'
00051 };
00052
00053 basic_xml_element_parser(std::basic_string<E> tag_name) :
00054 m_begin_left_bracket(std_string(1,left_bracket)),
00055 m_begin_tag_name(tag_name),
00056 m_begin_right_bracket(std_string(1,right_bracket)),
00057 m_end_left_bracket(std_string(1,left_bracket)),
00058 m_end_char(std_string(1,end_tag_char)),
00059 m_end_tag_name(tag_name),
00060 m_end_right_bracket(std_string(1,right_bracket)),
00061 grammar_to_parser::basic_non_terminal<E,A>() {};
00062
00063 protected:
00064 grammar_to_parser::basic_pattern_parser<E> m_begin_left_bracket;
00065 grammar_to_parser::basic_pattern_parser<E> m_begin_tag_name;
00066
00067
00068 basic_xml_attribute_list_parser<E> m_attribute_list_parser;
00069 grammar_to_parser::basic_pattern_parser<E> m_begin_right_bracket;
00070
00071
00072 grammar_to_parser::basic_pattern_parser<E> m_end_left_bracket;
00073 grammar_to_parser::basic_pattern_parser<E> m_end_char;
00074 grammar_to_parser::basic_pattern_parser<E> m_end_tag_name;
00075 grammar_to_parser::basic_pattern_parser<E> m_end_right_bracket;
00076
00077 virtual void prepare_symbols()
00078 {
00079 if( !m_symbols_valid )
00080 {
00081 m_symbols.push_back(&m_begin_left_bracket);
00082 m_symbols.push_back(&m_begin_tag_name);
00083
00084
00085 attributes_parsers_list attributes_parsers;
00086 get_valid().push_attributes_parsers(attributes_parsers);
00087 m_attribute_list_parser.assign_attributes_parsers(attributes_parsers);
00088 m_symbols.push_back(&m_attribute_list_parser);
00089
00090 m_symbols.push_back(&m_begin_right_bracket);
00091 get_valid().push_parsers(m_symbols);
00092 m_symbols.push_back(&m_end_left_bracket);
00093 m_symbols.push_back(&m_end_char);
00094 m_symbols.push_back(&m_end_tag_name);
00095 m_symbols.push_back(&m_end_right_bracket);
00096 m_symbols_valid = true;
00097 }
00098
00099 }
00100 };
00101
00102
00103
00108 template<typename A>
00109 class xml_element_parser : public basic_xml_element_parser<char,A>
00110 {
00111 public:
00112
00113 xml_element_parser<A>(std::string tag_name) :
00114 basic_xml_element_parser<char,A>(tag_name) {};
00115 };
00116
00121 template<typename A>
00122 class wxml_element_parser : public basic_xml_element_parser<wchar_t,A>
00123 {
00124 public:
00125 wxml_element_parser<A>(std::wstring tag_name) :
00126 basic_xml_element_parser<wchar_t,A>(tag_name) {};
00127 };
00128
00129
00130 };
00131
00132 #endif