5 #include <QtXml/QDomElement>
\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
17 class Xmlutil : public QObject
\r
21 explicit Xmlutil(QObject *parent = 0);
\r
23 static QDomElement addElement(QDomDocument &doc, QDomNode &node,
\r
25 const QString &value = QString::null);
\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
33 // QDomElement removeElement
\r
41 QDomDocument doc("mydocument");
\r
42 QFile file(argv[1]);
\r
43 if (!file.open(QIODevice::ReadOnly))
\r
45 if (!doc.setContent(&file)) {
\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
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
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
63 QDomNode node = n.firstChild();
\r
64 for(int i = 0; i < e.attribute("NoOfSteps").toInt(); i++)
\r
66 QDomElement elem = node.toElement();
\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
72 node = node.nextSibling();
\r
74 n = n.nextSibling();
\r