/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set et sw=2 ts=2: */ /*************************************************************************** * xmlparser.cc * * Wed Mar 21 09:15:51 CET 2012 * Copyright 2012 Jonas Suhr Christensen * jsc@umbraculum.org ****************************************************************************/ /* * This file is part of Munia. * * Munia is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Munia is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Munia; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "xmlparser.h" #include "stdio.h" #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(); open_tagtype = none; } XmlParser::~XmlParser() { // close file handler fclose(fp); if(task) delete task; } 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::startTag(std::string name, attributes_t &attr) { // printf("start: %s\n", name.c_str()); characterbuf.clear(); if(name == "task") { if(task) delete task; task = new task_t(); task->id = atoi(xml_decode(attr["id"]).c_str()); // task->parent_id = atoi(xml_decode(attr["parent_id"]).c_str()); } } 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; } else if (name == "desc") { if(task) task->desc = characterbuf; // open_tagtype = desc; } // 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); }