1 #ifndef XML_PARSER_CLASS
2 #define XML_PARSER_CLASS
4 /*****************************************************************************\
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 2007-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include <basis/contracts.h>
21 #include <basis/astring.h>
22 #include <structures/string_table.h>
26 //! Parses XML input and invokes a callback for the different syntactic pieces.
31 xml_parser(const basis::astring &to_parse);
32 virtual ~xml_parser();
34 DEFINE_CLASS_NAME("xml_parser");
36 //! the possible ways that operations here can complete.
38 OKAY = basis::common::OKAY
42 static const char *outcome_name(const basis::outcome &to_name);
43 //!< reports the string version of "to_name".
45 void reset(const basis::astring &to_parse);
46 //!< throws out any accumulated information and uses "to_parse" instead.
48 basis::outcome parse();
49 //!< starts the parsing process on the current string.
50 /*!< this will cause callbacks to be invoked for each of the xml syntactic
53 virtual basis::outcome header_callback(basis::astring &header_name,
54 structures::string_table &attributes);
55 //!< invoked when a well-formed xml header is seen in the input stream.
56 /*!< the following applies to all of the callbacks: the derived method must
57 return an outcome, which will be used by the parser. if the outcome is
58 OKAY, then parsing will continue. any other outcome will cause parsing
59 to stop and will become the return value of the parse() method. */
61 virtual basis::outcome tag_open_callback(basis::astring &tag_name,
62 structures::string_table &attributes);
63 //!< an xml tag has been opened in the input stream.
65 virtual basis::outcome tag_close_callback(basis::astring &tag_name);
66 //!< an xml tag was closed in the input stream.
68 virtual basis::outcome content_callback(basis::astring &content);
69 //!< invoked when plain text content is found inside an opened tag.
72 basis::astring *_xml_stream; // the stringful of xml information.