XML Parser

SAX Parser

template <typename _Handler, typename _Config = sax_parser_default_config>
class sax_parser : public orcus::sax::parser_base

Template-based sax parser that doesn’t use function pointer for callbacks for better performance, especially on large XML streams.

Public Types

typedef _Handler handler_type
typedef _Config config_type

Public Functions

sax_parser(const char *content, const size_t size, handler_type &handler)
~sax_parser()
void parse()
template <typename _Handler>
class sax_ns_parser

SAX based XML parser with proper namespace handling.

Public Types

typedef _Handler handler_type

Public Functions

sax_ns_parser(const char *content, const size_t size, xmlns_context &ns_cxt, handler_type &handler)
~sax_ns_parser()
void parse()
template <typename _Handler>
class sax_token_parser

XML parser that tokenizes element and attribute names while parsing.

Public Types

typedef _Handler handler_type

Public Functions

sax_token_parser(const char *content, const size_t size, const tokens &_tokens, xmlns_context &ns_cxt, handler_type &handler)
~sax_token_parser()
void parse()

Namespace

class xmlns_repository

Central XML namespace repository that stores all namespaces that are used in the current session.

Public Functions

xmlns_repository()
~xmlns_repository()
void add_predefined_values(const xmlns_id_t *predefined_ns)

Add a set of predefined namespace values to the repository.

Parameters
  • predefined_ns: predefined set of namespace values. This is a null-terminated array of xmlns_id_t. This xmlns_repository instance will assume that the instances of these xmlns_id_t values will be available throughout its life cycle; caller needs to ensure that they won’t get deleted before the corresponding xmlns_repository instance is deleted.

xmlns_context create_context()
xmlns_id_t get_identifier(size_t index) const

Get XML namespace identifier from its numerical index.

Return
valid namespace identifier, or XMLNS_UNKNOWN_ID if not found.
Parameters
  • index: numeric index of namespace.

std::string get_short_name(xmlns_id_t ns_id) const
std::string get_short_name(size_t index) const
class xmlns_context

XML namespace context. A new context should be used for each xml stream since the namespace keys themselves are not interned. Don’t hold an instance of this class any longer than the life cycle of the xml stream it is used in.

An empty key value is associated with a default namespace.

Public Functions

xmlns_context(const xmlns_context &r)
~xmlns_context()
xmlns_id_t push(const pstring &key, const pstring &uri)
void pop(const pstring &key)
xmlns_id_t get(const pstring &key) const

Get the currnet namespace identifier for a specified namespace alias.

Return
current namespace identifier associated with the alias.
Parameters
  • key: namespace alias to get the current namespace identifier for.

size_t get_index(xmlns_id_t ns_id) const

Get a unique index value associated with a specified identifier. An index value is guaranteed to be unique regardless of contexts.

Return
index value associated with the identifier.
Parameters
  • ns_id: a namespace identifier to obtain index for.

std::string get_short_name(xmlns_id_t ns_id) const

Get a ‘short’ name associated with a specified identifier. A short name is a string value conveniently short enough for display purposes, but still guaranteed to be unique to the identifier it is associated with.

Note that the xmlns_repository class has method of the same name, and that method works identically to this method.

Return
short name for the specified identifier.
Parameters
  • ns_id: a namespace identifier to obtain short name for.

pstring get_alias(xmlns_id_t ns_id) const

Get an alias currently associated with a given namespace identifier.

Return
alias name currently associted with the given namespace identifier, or an empty string if the given namespace is currently not associated with any aliases.
Parameters
  • ns_id: namespace identifier.

std::vector<xmlns_id_t> get_all_namespaces() const
void dump(std::ostream &os) const