27 #ifndef Common_XmlParser_h
28 #define Common_XmlParser_h
36 #include <initializer_list>
114 const std::initializer_list<std::string> &sub_parsers);
136 virtual void end_element(
const XML_Char *name,
const std::string &content) {};
149 virtual void sub_parse(
const XML_Char *name,
const char *base,
int len) {};
158 static int64_t
content_to_i64(
const std::string &name,
const std::string &content);
167 static int32_t
content_to_i32(
const std::string &name,
const std::string &content);
176 static int16_t
content_to_i16(
const std::string &name,
const std::string &content);
187 static bool content_to_bool(
const std::string &name,
const std::string &content);
199 static const std::string
201 const std::initializer_list<std::string> &valid);
252 void add_text(
const XML_Char *s,
int len);
281 const XML_Char **atts);
320 #endif // Common_XmlParser_h
std::string m_collected_text
Collected element text.
const char * m_base
Pointer to buffer holding content to be parsed.
std::stack< std::string > m_element_stack
Element stack.
int m_sub_parse_base_offset
Raw text offset (from m_base) of beginning of sub parse.
static bool content_to_bool(const std::string &name, const std::string &content)
Helper function to convert content to a boolean value.
static void end_element_handler(void *userdata, const XML_Char *name)
eXpat end element handler.
virtual void end_element(const XML_Char *name, const std::string &content)
End element callback member function.
static int32_t content_to_i32(const std::string &name, const std::string &content)
Helper function to convert content to an int32_t value.
bool open_element(const XML_Char *name)
Determines if element should be parsed or included in a sub parse.
void pop_element()
Pops element from element stack.
void push_element(const XML_Char *name)
Push element onto element stack.
static void character_data_handler(void *userdata, const XML_Char *s, int len)
eXpat character data handler add_text() is called to add len characters starting at s to collected te...
virtual ~XmlParser()
Destructor.
bool close_element(const XML_Char *name)
Checks for and performs sub parse.
int m_length
Length of data at m_base to be parsed.
XmlParser(const char *base, int len)
Constructor.
static int64_t content_to_i64(const std::string &name, const std::string &content)
Helper function to convert content to an int64_t value.
void add_text(const XML_Char *s, int len)
Collects text.
int m_sub_parse_toplevel
Toplevel element of current sub parse.
static int16_t content_to_i16(const std::string &name, const std::string &content)
Helper function to convert content to an int16_t value.
const std::string collected_text()
Returns collected text.
std::vector< std::string > m_sub_parsers
List of element names for which there is a sub-parser.
Base class for XML document parsers.
static const std::string content_to_text(const std::string &name, const std::string &content, const std::initializer_list< std::string > &valid)
Helper function to convert content to one of a set of valid text values.
virtual void start_element(const XML_Char *name, const XML_Char **atts)
Start element callback member function.
XML_Parser m_parser
eXpat parser
static void start_element_handler(void *userdata, const XML_Char *name, const XML_Char **atts)
eXpat start element handler.
virtual void sub_parse(const XML_Char *name, const char *base, int len)
Performs a sub-parse.
std::string m_current_element
Current element being parsed.