Imported Upstream version 2.91.2
[platform/upstream/libxml++.git] / libxml++ / parsers / domparser.h
1 /* domparser.h
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.
5  */
6
7 #ifndef __LIBXMLPP_PARSERS_DOMPARSER_H
8 #define __LIBXMLPP_PARSERS_DOMPARSER_H
9
10 #include <libxml++/parsers/parser.h>
11 #include <libxml++/document.h>
12
13 namespace xmlpp {
14
15 /** DOM XML parser.
16  * DOM = Document Object Model
17  */
18 class DomParser : public Parser
19 {
20 public:
21   /** Create a parser with an empty document.
22    * @throws xmlpp::internal_error If an empty document can't be created.
23    */
24   DomParser();
25
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
32    */
33   explicit DomParser(const std::string& filename, bool validate = false);
34   ~DomParser() override;
35
36   /** Parse an XML document from a file.
37    * If the parser already contains a document, that document and all its nodes
38    * are deleted.
39    * @param filename The path to the file.
40    * @throws xmlpp::internal_error
41    * @throws xmlpp::parse_error
42    * @throws xmlpp::validity_error
43    */
44   void parse_file(const std::string& filename) override;
45
46   /** Parse an XML document from a string.
47    * If the parser already contains a document, that document and all its nodes
48    * are deleted.
49    * @param contents The XML document as a string.
50    * @throws xmlpp::internal_error
51    * @throws xmlpp::parse_error
52    * @throws xmlpp::validity_error
53    */
54   void parse_memory(const Glib::ustring& contents) override;
55   
56   /** Parse an XML document from raw memory.
57    * If the parser already contains a document, that document and all its nodes
58    * are deleted.
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
64    */
65   void parse_memory_raw(const unsigned char* contents, size_type bytes_count) override;
66
67   /** Parse an XML document from a stream.
68    * If the parser already contains a document, that document and all its nodes
69    * are deleted.
70    * @param in The stream.
71    * @throws xmlpp::internal_error
72    * @throws xmlpp::parse_error
73    * @throws xmlpp::validity_error
74    */
75   void parse_stream(std::istream& in) override;
76
77   /** Test whether a document has been parsed.
78    */
79   operator bool() const;
80   
81   /** Get the parsed document.
82    * @returns A pointer to the parsed document, or <tt>nullptr</tt>.
83    */
84   Document* get_document();
85
86   /** Get the parsed document.
87    * @returns A pointer to the parsed document, or <tt>nullptr</tt>.
88    */
89   const Document* get_document() const;
90   
91 protected:
92   void parse_context();
93
94   void release_underlying() override;
95   
96   Document* doc_;
97 };
98
99 } // namespace xmlpp
100
101 #endif //__LIBXMLPP_PARSERS_DOMPARSER_H