2 * libxml++ and this file are copyright (C) 2000 by Ari Johnson, and
3 * are covered by the GNU Lesser General Public License, which should be
4 * included with libxml++ as the file COPYING.
7 #ifndef __LIBXMLPP_PARSERS_DOMPARSER_H
8 #define __LIBXMLPP_PARSERS_DOMPARSER_H
10 #include <libxml++/parsers/parser.h>
11 #include <libxml++/document.h>
16 * DOM = Document Object Model
18 class DomParser : public Parser
21 /** Create a parser with an empty document.
22 * @throws xmlpp::internal_error If an empty document can't be created.
26 /** Instantiate the parser and parse a document immediately.
27 * @param filename The path to the file.
28 * @param validate Whether the parser should validate the XML.
29 * @throws xmlpp::internal_error
30 * @throws xmlpp::parse_error
31 * @throws xmlpp::validity_error
33 explicit DomParser(const std::string& filename, bool validate = false);
34 ~DomParser() override;
36 /** Parse an XML document from a file.
37 * If the parser already contains a document, that document and all its nodes
39 * @param filename The path to the file.
40 * @throws xmlpp::internal_error
41 * @throws xmlpp::parse_error
42 * @throws xmlpp::validity_error
44 void parse_file(const std::string& filename) override;
46 /** Parse an XML document from a string.
47 * If the parser already contains a document, that document and all its nodes
49 * @param contents The XML document as a string.
50 * @throws xmlpp::internal_error
51 * @throws xmlpp::parse_error
52 * @throws xmlpp::validity_error
54 void parse_memory(const Glib::ustring& contents) override;
56 /** Parse an XML document from raw memory.
57 * If the parser already contains a document, that document and all its nodes
59 * @param contents The XML document as an array of bytes.
60 * @param bytes_count The number of bytes in the @a contents array.
61 * @throws xmlpp::internal_error
62 * @throws xmlpp::parse_error
63 * @throws xmlpp::validity_error
65 void parse_memory_raw(const unsigned char* contents, size_type bytes_count) override;
67 /** Parse an XML document from a stream.
68 * If the parser already contains a document, that document and all its nodes
70 * @param in The stream.
71 * @throws xmlpp::internal_error
72 * @throws xmlpp::parse_error
73 * @throws xmlpp::validity_error
75 void parse_stream(std::istream& in) override;
77 /** Test whether a document has been parsed.
79 operator bool() const;
81 /** Get the parsed document.
82 * @returns A pointer to the parsed document, or <tt>nullptr</tt>.
84 Document* get_document();
86 /** Get the parsed document.
87 * @returns A pointer to the parsed document, or <tt>nullptr</tt>.
89 const Document* get_document() const;
94 void release_underlying() override;
101 #endif //__LIBXMLPP_PARSERS_DOMPARSER_H