/usr/include/libxml++-2.6/libxml++/parsers/saxparser.h is in libxml++2.6-dev 2.34.1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | /* saxparser.h
* libxml++ and this file are copyright (C) 2000 by Ari Johnson, and
* are covered by the GNU Lesser General Public License, which should be
* included with libxml++ as the file COPYING.
*/
#ifndef __LIBXMLPP_PARSERS_SAXPARSER_H
#define __LIBXMLPP_PARSERS_SAXPARSER_H
#include <libxml++/parsers/parser.h>
#include <list>
#include <deque>
#include <memory>
#include "libxml++/document.h"
#ifndef DOXYGEN_SHOULD_SKIP_THIS
extern "C" {
struct _xmlSAXHandler;
struct _xmlEntity;
}
#endif //DOXYGEN_SHOULD_SKIP_THIS
namespace xmlpp {
/** SAX XML parser.
* Derive your own class and override the on_*() methods.
*/
class SaxParser : public Parser
{
public:
/**
* Simple structure used in the start_element callback, in which
* the attributes are a list of name/value pairs.
*/
struct Attribute
{
Glib::ustring name;
Glib::ustring value;
Attribute(Glib::ustring const & n, Glib::ustring const & v)
: name(n), value(v)
{
}
};
typedef std::deque< Attribute > AttributeList;
/** This functor is a helper to find an attribute by name in an
* AttributeList using the standard algorithm std::find_if
*
* Example:@n
* <code>
* Glib::ustring name = "foo";@n
* AttributeList::const_iterator attribute = std::find_if(attributes.begin(), attributes.end(), AttributeHasName(name));
* </code>
*/
struct AttributeHasName
{
Glib::ustring const & name;
AttributeHasName(Glib::ustring const & n)
: name(n)
{
}
bool operator()(Attribute const & attribute)
{
return attribute.name == name;
}
};
/**
* @param use_get_entity Set this to true if you will override on_get_entity().
* In theory, if you do not override on_get_entity() the parser should behave exactly the same
* whether you use true or false here. But the default implementation of on_get_entity(), needed
* if you override on_get_entity() might not have the same behaviour as the underlying default
* behaviour of libxml, so the libxml implementation is the default here.
*/
SaxParser(bool use_get_entity = false);
virtual ~SaxParser();
/** Parse an XML document from a file.
* @throw exception
* @param filename The path to the file.
*/
virtual void parse_file(const Glib::ustring& filename);
/** Parse an XML document from a string.
* @throw exception
* @param contents The XML document as a string.
*/
virtual void parse_memory(const Glib::ustring& contents);
/** Parse an XML document from raw memory.
* @throw exception
* @param contents The XML document as an array of bytes.
* @param bytes_count The number of bytes in the @a contents array.
*/
void parse_memory_raw(const unsigned char* contents, size_type bytes_count);
/** Parse an XML document from a stream.
* @throw exception
* @param in The stream.
*/
virtual void parse_stream(std::istream& in);
/** Parse a chunk of data.
*
* This lets you pass a document in small chunks, e.g. from a network
* connection. The on_* virtual functions are called each time the chunks
* provide enough information to advance the parser.
*
* The first call to parse_chunk will setup the parser. When the last chunk
* has been parsed, call finish_chunk_parsing() to finish the parse.
*
* @throw exception
* @param chunk The next piece of the XML document.
*/
virtual void parse_chunk(const Glib::ustring& chunk);
/** Parse a chunk of data.
*
* @newin{2,24}
*
* This lets you pass a document in small chunks, e.g. from a network
* connection. The on_* virtual functions are called each time the chunks
* provide enough information to advance the parser.
*
* The first call to parse_chunk will setup the parser. When the last chunk
* has been parsed, call finish_chunk_parsing() to finish the parse.
*
* @throw exception
* @param contents The next piece of the XML document as an array of bytes.
* @param bytes_count The number of bytes in the @a contents array.
*/
void parse_chunk_raw(const unsigned char* contents, size_type bytes_count);
/** Finish a chunk-wise parse.
*
* Call this after the last call to parse_chunk(). Don't use this function with
* the other parsing methods.
*/
virtual void finish_chunk_parsing();
protected:
virtual void on_start_document();
virtual void on_end_document();
virtual void on_start_element(const Glib::ustring& name, const AttributeList& attributes);
virtual void on_end_element(const Glib::ustring& name);
virtual void on_characters(const Glib::ustring& characters);
virtual void on_comment(const Glib::ustring& text);
virtual void on_warning(const Glib::ustring& text);
virtual void on_error(const Glib::ustring& text);
virtual void on_fatal_error(const Glib::ustring& text);
virtual void on_cdata_block(const Glib::ustring& text);
/** Override this to receive information about the document's DTD and any entity declarations.
*/
virtual void on_internal_subset(const Glib::ustring& name, const Glib::ustring& publicId, const Glib::ustring& systemId);
/** Override this method to resolve entities references in your derived parser, instead of using the default entity resolution,
* or to be informed when entity references are encountered.
*
* If you override this function then you must also specify true for use_get_entity constructor parameter.
* You will probably need to override on_entity_declaration() as well so that you can use that information when
* resolving the entity reference.
*
* This is known to be difficult, because it requires both an understanding of the W3C specifications and knowledge of the
* libxml internals. Entity resolution is easier with the DomParser.
*
* Call this method in this base class for default processing. For instance, if you just want to know about the existence of
* an entity reference, without affecting the normal substitution, just override and call the base class.
*
* Unlike the DomParser, the SaxParser will also tell you about entity references for the 5 predefined entities.
*
* @param name The entity reference name.
* @returns The resolved xmlEntity for the entity reference. You must include libxml/parser.h in order to use this C struct.
* This instance will not be freed by the caller.
*/
virtual _xmlEntity* on_get_entity(const Glib::ustring& name);
/** Override this to receive information about every entity declaration.
* If you override this function, and you want normal entity substitution to work, then you must call the base class in your override.
*
* This would be useful when overriding on_get_entity().
*/
virtual void on_entity_declaration(const Glib::ustring& name, XmlEntityType type, const Glib::ustring& publicId, const Glib::ustring& systemId, const Glib::ustring& content);
virtual void release_underlying();
private:
virtual void parse();
std::auto_ptr<_xmlSAXHandler> sax_handler_;
// A separate xmlpp::Document that is just used for entity resolution,
// and never seen in the API:
xmlpp::Document entity_resolver_doc_;
friend struct SaxParserCallback;
};
} // namespace xmlpp
#endif //__LIBXMLPP_PARSERS_SAXPARSER_H
|