Modified welcome text file so it shows proper names in the reporsitory
[confmgr] / xmlutil.h
1 #ifndef XMLUTIL_H\r
2 #define XMLUTIL_H\r
3 \r
4 #include <QObject>\r
5 #include <QtXml/QDomElement>\r
6 #include "profile.h"\r
7 \r
8 #define NO_OF_PROFILE_ATTR "NoOfProfiles"\r
9 #define PROFILE_TAG "Profiles"\r
10 #define PROFILE_ELEM_TAG "Profile"\r
11 #define NAME_ATTR "Name"\r
12 #define NO_OF_STEPS_ATTR "NoOfSteps"\r
13 #define STEP_TAG "Step"\r
14 #define VALUE_ATTR "Value"\r
15 #define DELAY_ATTR "Delay"\r
16 \r
17 class Xmlutil : public QObject\r
18 {\r
19     Q_OBJECT\r
20 public:\r
21     explicit Xmlutil(QObject *parent = 0);\r
22 \r
23     static QDomElement addElement(QDomDocument &doc, QDomNode &node,\r
24                            const QString &tag,\r
25                            const QString &value = QString::null);\r
26 \r
27     static QString generateProfileXML(const Profile &profile, int *error = 0,\r
28                                       QDomDocument *doc = 0, QDomElement *elem = 0);\r
29     // returns non-zero on error\r
30     static int degenerateProfileXML(const QString xmlString, Profile &profile,\r
31                                     QDomElement *pElem = 0);\r
32 \r
33 //    QDomElement removeElement\r
34 signals:\r
35 \r
36 public slots:\r
37 \r
38 };\r
39 \r
40 /*\r
41     QDomDocument doc("mydocument");\r
42     QFile file(argv[1]);\r
43     if (!file.open(QIODevice::ReadOnly))\r
44         return -1;\r
45     if (!doc.setContent(&file)) {\r
46         file.close();\r
47         return -1;\r
48     }\r
49     file.close();\r
50 \r
51 // print out the element names of all elements that are direct children\r
52 // of the outermost element.\r
53     QDomElement docElem = doc.namedItem("Profiles").toElement();\r
54     qDebug() << "Main Tag: " << docElem.attribute("NoOfProfiles") << endl;\r
55 \r
56     QDomNode n = docElem.firstChild();\r
57     while(!n.isNull()) {\r
58         QDomElement e = n.toElement(); // try to convert the node to an element.\r
59         if(!e.isNull()) {\r
60             qDebug() << "Name" << qPrintable(e.tagName()) << e.attribute("Name") << endl; // the node really is an element.\r
61             qDebug() << "NoOfSteps" << qPrintable(e.tagName()) << e.attribute("NoOfSteps") << endl; // the node really is an element.\r
62         }\r
63         QDomNode node = n.firstChild();\r
64         for(int i = 0; i < e.attribute("NoOfSteps").toInt(); i++)\r
65         {\r
66             QDomElement elem = node.toElement();\r
67             if(!elem.isNull())\r
68             {\r
69                 qDebug() << "Value" << qPrintable(elem.tagName()) << elem.attribute("Value") << endl; // the node really is an element.\r
70                 qDebug() << "Delay" << qPrintable(elem.tagName()) << elem.attribute("Delay") << endl; // the node really is an element.\r
71             }\r
72             node = node.nextSibling();\r
73         }\r
74         n = n.nextSibling();\r
75     }\r
76 \r
77  */\r
78 \r
79 #endif // XMLUTIL_H\r