Enable xml parsing for DocumentMemory
[anna.git] / include / anna / xml / DocumentMemory.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_DocumentMemory_hpp
10 #define anna_xml_DocumentMemory_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 buffer Cstring.
22 */
23 class DocumentMemory : public Document {
24 public:
25   /**
26      Constructor.
27   */
28   DocumentMemory() : 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 throw() { return a_rootNode; }
36
37   /**
38    * Parse xml document and return root node
39    * \return Root node
40    * \warning Need previous initialization
41    */
42   const Node* parse() throw(RuntimeException) { return (a_rootNode = Document::parse()); }
43
44   /**
45    * Parse xml document with dtd and return root node
46    * \param dtd Validation DTD for XML document
47    * \return Root node
48    * \warning Need previous initialization
49    */
50   const Node* parse(const DTD& dtd) throw(RuntimeException) { return (a_rootNode = Document::parse(dtd)); }
51
52   /**
53    * XML representation from loaded document
54    * \return XML string
55    * \warning Need previous initialization and parsing
56    */
57   std::string asXmlString() const throw() { Compiler c; return (c.apply(a_rootNode)); }
58
59 private:
60   const anna::xml::Node * a_rootNode;
61   virtual _xmlDoc* do_initialize(const char* content) throw(RuntimeException);
62   virtual _xmlDoc* do_initialize(const anna::DataBlock&) throw(RuntimeException);
63 };
64
65 }
66 }
67
68 #endif