bool parser_base::value(pstring& str, bool decode) { char c = cur_char(); if (c != '"') throw malformed_xml_error("value must be quoted"); c = next_char_checked(); size_t first = m_pos; const char* p0 = m_char; for (; c != '"'; c = next_char_checked()) { if (decode && c == '&') { // This value contains one or more encoded characters. cell_buffer& buf = get_cell_buffer(); buf.reset(); buf.append(p0, m_pos-first); value_with_encoded_char(buf, str); return true; } } str = pstring(p0, m_pos-first); // Skip the closing quote. next(); return false; }
void sax_parser<_Handler,_Config>::header() { // we don't handle multi byte encodings so we can just skip bom entry if exists. skip_bom(); blank(); if (!has_char() || cur_char() != '<') throw sax::malformed_xml_error("xml file must begin with '<'."); if (config_type::strict_xml_declaration) { if (next_char_checked() != '?') throw sax::malformed_xml_error("xml file must begin with '<?'."); declaration("xml"); } }
void parser_base::name(pstring& str) { size_t first = m_pos; char c = cur_char(); if (!is_alpha(c)) { ::std::ostringstream os; os << "name must begin with an alphabet, but got this instead '" << c << "'"; throw malformed_xml_error(os.str()); } while (is_alpha(c) || is_numeric(c) || is_name_char(c)) c = next_char_checked(); size_t size = m_pos - first; str = pstring(m_content+first, size); }
void sax_parser<_Handler,_Config>::element() { assert(cur_char() == '<'); const char* pos = m_char; char c = next_char_checked(); switch (c) { case '/': element_close(pos); break; case '!': special_tag(); break; case '?': declaration(NULL); break; default: if (!is_alpha(c)) throw sax::malformed_xml_error("expected an alphabet."); element_open(pos); } }
void sax_parser<_Handler,_Config>::declaration(const char* name_check) { assert(cur_char() == '?'); next_check(); // Get the declaration name first. pstring decl_name; name(decl_name); #if ORCUS_DEBUG_SAX_PARSER cout << "sax_parser::declaration: start name='" << decl_name << "'" << endl; #endif if (name_check && decl_name != name_check) { std::ostringstream os; os << "declaration name of '" << name_check << "' was expected, but '" << decl_name << "' was found instead."; throw sax::malformed_xml_error(os.str()); } m_handler.start_declaration(decl_name); blank(); // Parse the attributes. while (cur_char_checked() != '?') { attribute(); blank(); } if (next_char_checked() != '>') throw sax::malformed_xml_error("declaration must end with '?>'."); m_handler.end_declaration(decl_name); reset_buffer_pos(); next(); #if ORCUS_DEBUG_SAX_PARSER cout << "sax_parser::declaration: end name='" << decl_name << "'" << endl; #endif }