summaryrefslogtreecommitdiffstats
path: root/src/Common/XmlData.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Common/XmlData.cpp')
-rw-r--r--src/Common/XmlData.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Common/XmlData.cpp b/src/Common/XmlData.cpp
index 4d1da6e..aa3fcdf 100644
--- a/src/Common/XmlData.cpp
+++ b/src/Common/XmlData.cpp
@@ -19,6 +19,9 @@
#include "XmlData.h"
#include "Base64Encoder.h"
+
+#include <cerrno>
+#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -267,6 +270,15 @@ XmlData::XmlData(const Net::Packet &packet) {
entry = new Entry(rootNode);
}
+XmlData::XmlData(const std::string &filename) throw (Core::Exception) {
+ doc = xmlParseFile(filename.c_str());
+ if(!doc)
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ rootNode = xmlDocGetRootElement(doc);
+ entry = new Entry(rootNode);
+}
+
XmlData& XmlData::operator=(const XmlData &o) {
delete entry;
xmlFreeDoc(doc);
@@ -305,5 +317,16 @@ Net::Packet XmlData::toPacket(boost::uint16_t requestId) const {
return packet;
}
+void XmlData::toFile(const std::string &filename) const throw (Core::Exception) {
+ std::FILE *file = std::fopen(filename.c_str(), "w");
+ if(!file)
+ throw Core::Exception(Core::Exception::INTERNAL_ERRNO, errno);
+
+ if(!xmlDocDump(file, doc))
+ throw Core::Exception(Core::Exception::NOT_AVAILABLE);
+
+ std::fclose(file);
+}
+
}
}