diff options
-rw-r--r-- | HISTORY.h | 3 | ||||
-rw-r--r-- | lib/xml.c | 91 | ||||
-rw-r--r-- | lib/xml.h | 48 |
3 files changed, 142 insertions, 0 deletions
@@ -19,6 +19,9 @@ /* * ------------------------------------ +2017-03-23 version 1.1.54 (horchi) + - added: New event plugin interface + 2017-03-22 version 1.1.53 (horchi) - change: Removed old patches for vdr < 2.2.0 - added: Patch to extend cEvent with aux field like cTimer diff --git a/lib/xml.c b/lib/xml.c new file mode 100644 index 0000000..2ea13ed --- /dev/null +++ b/lib/xml.c @@ -0,0 +1,91 @@ +/* + * + * xml.h + * + * (c) 2017 Jörg Wendel + * + * This code is distributed under the terms and conditions of the + * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details. + */ + +//*************************************************************************** +// Include +//*************************************************************************** + +#include "xml.h" + +//*************************************************************************** +// ctor +//*************************************************************************** + +cXml::cXml() + : printer(0, yes) +{ + root = 0; +} + +int cXml::create(const char* rootName) +{ + root = doc.NewElement(rootName); + doc.InsertFirstChild(root); + + return success; +} + +int cXml::set(const char* data) +{ + if (doc.Parse(data) != XML_SUCCESS) + return fail; + + root = doc.FirstChild(); + + return root ? success : fail; +} + +//*************************************************************************** +// Append Element +//*************************************************************************** + +XMLNode* cXml::appendElement(const char* name, const char* value, XMLNode* node) +{ + XMLElement* element = doc.NewElement(name); + + element->SetText(value); + node = node ? node : root; + node->InsertEndChild(element); + + return element; +} + +XMLNode* cXml::appendElement(const char* name, int value, XMLNode* node) +{ + XMLElement* element = doc.NewElement(name); + + element->SetText(value); + node = node ? node : root; + node->InsertEndChild(element); + + return element; +} + +//*************************************************************************** +// To Text +//*************************************************************************** + +const char* cXml::toText() +{ + doc.Accept(&printer); + + return printer.CStr(); +} + +XMLElement* cXml::getFirst(XMLNode* node) +{ + node = node ? node : root; + return node->FirstChildElement(); +} + +XMLElement* cXml::getNext(XMLNode* node) +{ + return node->NextSiblingElement(); +} diff --git a/lib/xml.h b/lib/xml.h new file mode 100644 index 0000000..ae4a628 --- /dev/null +++ b/lib/xml.h @@ -0,0 +1,48 @@ +/* + * + * xml.h + * + * (c) 2017 Jörg Wendel + * + * This code is distributed under the terms and conditions of the + * GNU GENERAL PUBLIC LICENSE. See the file COPYING for details. + */ + +//*************************************************************************** +// Include +//*************************************************************************** + +#include <tinyxml2.h> + +#include "common.h" + +using namespace tinyxml2; + +//*************************************************************************** +// Class cXml +//*************************************************************************** + +class cXml +{ + public: + + cXml(); + + int create(const char* rootName); + int set(const char* data); + + XMLNode* appendElement(const char* name, const char* value, XMLNode* node = 0); + XMLNode* appendElement(const char* name, int value, XMLNode* node = 0); + + XMLNode* getRoot() { return root; } + XMLElement* getFirst(XMLNode* node = 0); + XMLElement* getNext(XMLNode* node); + + const char* toText(); + + private: + + XMLDocument doc; + XMLNode* root; + XMLPrinter printer; +}; |