summaryrefslogtreecommitdiff
path: root/src/xmlparser.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmlparser.cc')
-rw-r--r--src/xmlparser.cc83
1 files changed, 30 insertions, 53 deletions
diff --git a/src/xmlparser.cc b/src/xmlparser.cc
index 97a8bdb..112ea00 100644
--- a/src/xmlparser.cc
+++ b/src/xmlparser.cc
@@ -31,73 +31,50 @@
#include "xml_encode_decode.h"
-XmlParser::XmlParser(std::string filename) {
- // open file handler
- fp = fopen(filename.c_str(), "r");
- if(!fp) {
- fprintf(stderr, "Could not open file\n");
- }
-
- task = NULL;
- tasklist.clear();
+#define NOID 0xffffffff
- open_tagtype = none;
+XmlParser::XmlParser(TaskTree *t) : tree(t)
+{
}
-XmlParser::~XmlParser() {
- // close file handler
- fclose(fp);
- if(task) delete task;
+XmlParser::~XmlParser()
+{
}
-void XmlParser::characterData(std::string& data) {
- characterbuf += data;
-
- /*
- switch(open_tagtype) {
- case title:
- // task->title += xml_decode(data);
- break;
- case desc:
- // task->desc += xml_decode(data);
- break;
- default:
- break;
- }
- */
+void XmlParser::characterData(const std::string &data)
+{
+ cdata += data;
}
-void XmlParser::startTag(std::string name, attributes_t &attr) {
- // printf("start: %s\n", name.c_str());
- characterbuf.clear();
+void XmlParser::startTag(std::string name, attributes_t &attr)
+{
if(name == "task") {
- if(task) delete task;
+ taskid_t id = atoi(xml_decode(attr["id"]).c_str());
+
+ node_t* parent = NULL;
+ if(parents.size() != 0) parent = tree->id2node.at(parents.top());
+
+ node = tree->createNode(id);
+ tree->insertChild(parent, node);
+ }
- task = new task_t();
- task->id = atoi(xml_decode(attr["id"]).c_str());
- // task->parent_id = atoi(xml_decode(attr["parent_id"]).c_str());
+ if(name == "children") {
+ parents.push(node->id);
}
+ cdata = "";
}
-void XmlParser::endTag(std::string name) {
- // printf("end: %s\n", name.c_str());
- if (name == "task") {
- // if(task) tasklist.push_back(*task);
- }
- else if (name == "title") {
- if(task) task->title = characterbuf;
- // open_tagtype = title;
+void XmlParser::endTag(std::string name)
+{
+ if(name == "task") {
}
- else if (name == "desc") {
- if(task) task->desc = characterbuf;
- // open_tagtype = desc;
+
+ if(name == "children") {
+ parents.pop();
}
- // open_tagtype = none;
-}
-int XmlParser::readData(char* data, size_t size) {
- if(!fp) return 0; // Could not read file
-
- return fread(data, 1, size, fp);
+ if (name == "title") {
+ node->data.title = cdata;
+ }
}