aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-02-12 09:21:28 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-02-12 09:21:28 +0000
commit5a764007436eac8416a2d567bbc5e0a56ffc4240 (patch)
tree4d3ebf51d9e57ecd29f1228cb07dc728f5e8432d /source
parent6c1eb5edcf0b301d2b30c9a649a23fc79148f5e6 (diff)
downloadqxmpp-5a764007436eac8416a2d567bbc5e0a56ffc4240.tar.gz
add support for nest QXmppElements
Diffstat (limited to 'source')
-rw-r--r--source/QXmppElement.cpp24
-rw-r--r--source/QXmppElement.h8
2 files changed, 31 insertions, 1 deletions
diff --git a/source/QXmppElement.cpp b/source/QXmppElement.cpp
index 21571417..7dac43e6 100644
--- a/source/QXmppElement.cpp
+++ b/source/QXmppElement.cpp
@@ -39,6 +39,18 @@ QXmppElement::QXmppElement(const QDomElement &element)
QDomAttr attr = attributes.item(i).toAttr();
m_attributes.insert(attr.name(), attr.value());
}
+
+ QDomElement childElement = element.firstChildElement();
+ while (!childElement.isNull())
+ {
+ m_children.append(QXmppElement(childElement));
+ childElement = childElement.nextSiblingElement();
+ }
+}
+
+QStringList QXmppElement::attributeNames() const
+{
+ return m_attributes.keys();
}
QString QXmppElement::attribute(const QString &name) const
@@ -51,6 +63,16 @@ void QXmppElement::setAttribute(const QString &name, const QString &value)
m_attributes.insert(name, value);
}
+QList<QXmppElement> QXmppElement::children() const
+{
+ return m_children;
+}
+
+void QXmppElement::setChildren(QList<QXmppElement> &children)
+{
+ m_children = children;
+}
+
QString QXmppElement::tagName() const
{
return m_tagName;
@@ -66,6 +88,8 @@ void QXmppElement::toXml(QXmlStreamWriter *writer) const
writer->writeStartElement(m_tagName);
foreach (const QString &attr, m_attributes.keys())
helperToXmlAddAttribute(writer, attr, m_attributes.value(attr));
+ foreach (const QXmppElement &child, m_children)
+ child.toXml(writer);
writer->writeEndElement();
}
diff --git a/source/QXmppElement.h b/source/QXmppElement.h
index ca1159ba..74f8150c 100644
--- a/source/QXmppElement.h
+++ b/source/QXmppElement.h
@@ -25,7 +25,7 @@
#define QXMPPELEMENT_H
#include <QMap>
-#include <QString>
+#include <QStringList>
#include <QXmlStreamWriter>
class QDomElement;
@@ -36,9 +36,14 @@ public:
QXmppElement();
QXmppElement(const QDomElement &element);
+ QStringList attributeNames() const;
+
QString attribute(const QString &name) const;
void setAttribute(const QString &name, const QString &value);
+ QList<QXmppElement> children() const;
+ void setChildren(QList<QXmppElement> &children);
+
QString tagName() const;
void setTagName(const QString &type);
@@ -46,6 +51,7 @@ public:
private:
QMap<QString, QString> m_attributes;
+ QList<QXmppElement> m_children;
QString m_tagName;
};