Remove dynamic exceptions
[anna.git] / include / anna / xml / DocumentFile.hpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite                           //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
7
8
9 #ifndef anna_xml_DocumentFile_hpp
10 #define anna_xml_DocumentFile_hpp
11
12 #include <anna/config/defines.hpp>
13 #include <anna/xml/Document.hpp>
14 #include <anna/xml/Compiler.hpp>
15
16 namespace anna {
17
18 namespace xml {
19
20 /**
21    Clase para gestionar un documento XML contenido en un archivo.
22 */
23 class DocumentFile : public Document {
24 public:
25   /**
26      Constructor.
27   */
28   DocumentFile() : a_filename("<none>"), a_rootNode(NULL) {;}
29
30   /**
31   * Root node after parsing, or NULL if not analyzed by mean parse()
32   *
33   * @return XML document root node
34   */
35   const Node * getRootNode() const { return a_rootNode; }
36
37   /**
38      Devuelve el contenido asociado al documento XML.
39      \return El contenido asociado al documento XML.
40   */
41   const anna::DataBlock& getContent() const noexcept(false);
42
43   /**
44    * Parse xml document and return root node
45    * \return Root node
46    * \warning Need previous initialization
47    */
48   const Node* parse() noexcept(false) { return (a_rootNode = Document::parse()); }
49
50   /**
51    * Parse xml document with dtd and return root node
52    * \param dtd Validation DTD for XML document
53    * \return Root node
54    * \warning Need previous initialization
55    */
56   const Node* parse(const DTD& dtd) noexcept(false) { return (a_rootNode = Document::parse(dtd)); }
57
58   /**
59    * XML representation from loaded document
60    * \return XML string
61    * \warning Need previous initialization and parsing
62    */
63   std::string asXmlString() const { Compiler c; return (c.apply(a_rootNode)); }
64
65
66 protected:
67   /**
68      Nombre del fichero indicado como parametro al invocar a Document::initialize
69   */
70   std::string a_filename;
71
72 private:
73   const anna::xml::Node * a_rootNode;
74   virtual _xmlDoc* do_initialize(const char* filename) noexcept(false);
75   virtual _xmlDoc* do_initialize(const anna::DataBlock&) noexcept(false);
76 };
77
78 }
79 }
80
81 #endif