Enable xml parsing for DocumentMemory
authorEduardo Ramos Testillano (eramedu) <eduardo.ramos.testillano@ericsson.com>
Tue, 28 Apr 2020 09:04:22 +0000 (11:04 +0200)
committerEduardo Ramos Testillano (eramedu) <eduardo.ramos.testillano@ericsson.com>
Tue, 28 Apr 2020 09:04:22 +0000 (11:04 +0200)
include/anna/xml/DocumentMemory.hpp

index f67611c..06123a1 100644 (file)
@@ -9,7 +9,9 @@
 #ifndef anna_xml_DocumentMemory_hpp
 #define anna_xml_DocumentMemory_hpp
 
+#include <anna/config/defines.hpp>
 #include <anna/xml/Document.hpp>
+#include <anna/xml/Compiler.hpp>
 
 namespace anna {
 
@@ -23,11 +25,41 @@ public:
   /**
      Constructor.
   */
-  DocumentMemory() {;}
+  DocumentMemory() : a_rootNode(NULL) {;}
+
+  /**
+  * Root node after parsing, or NULL if not analyzed by mean parse()
+  *
+  * @return XML document root node
+  */
+  const Node * getRootNode() const throw() { return a_rootNode; }
+
+  /**
+   * Parse xml document and return root node
+   * \return Root node
+   * \warning Need previous initialization
+   */
+  const Node* parse() throw(RuntimeException) { return (a_rootNode = Document::parse()); }
+
+  /**
+   * Parse xml document with dtd and return root node
+   * \param dtd Validation DTD for XML document
+   * \return Root node
+   * \warning Need previous initialization
+   */
+  const Node* parse(const DTD& dtd) throw(RuntimeException) { return (a_rootNode = Document::parse(dtd)); }
+
+  /**
+   * XML representation from loaded document
+   * \return XML string
+   * \warning Need previous initialization and parsing
+   */
+  std::string asXmlString() const throw() { Compiler c; return (c.apply(a_rootNode)); }
 
 private:
+  const anna::xml::Node * a_rootNode;
   virtual _xmlDoc* do_initialize(const char* content) throw(RuntimeException);
-  virtual _xmlDoc* do_initialize(const anna::DataBlock& content) throw(RuntimeException);
+  virtual _xmlDoc* do_initialize(const anna::DataBlock&) throw(RuntimeException);
 };
 
 }