aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-02-15 15:02:21 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-02-15 15:02:21 +0000
commit9fa05f589c6a973d10dbfc3a3fd7f2514cf379f2 (patch)
treed38c55bf7918b59276bd7af9753fbf6324ffbebe /source
parenta04f3f45fe4b03ede4f1f89b7610e50714e347b6 (diff)
downloadqxmpp-9fa05f589c6a973d10dbfc3a3fd7f2514cf379f2.tar.gz
make it possible to get/set QXmppElement value
Diffstat (limited to 'source')
-rw-r--r--source/QXmppElement.cpp22
-rw-r--r--source/QXmppElement.h4
2 files changed, 22 insertions, 4 deletions
diff --git a/source/QXmppElement.cpp b/source/QXmppElement.cpp
index 2dcb87ad..3820f35e 100644
--- a/source/QXmppElement.cpp
+++ b/source/QXmppElement.cpp
@@ -47,11 +47,14 @@ QXmppElement::QXmppElement(const QDomElement &element)
m_attributes.insert(attr.name(), attr.value());
}
- QDomElement childElement = element.firstChildElement();
- while (!childElement.isNull())
+ QDomNode childNode = element.firstChild();
+ while (!childNode.isNull())
{
- m_children.append(QXmppElement(childElement));
- childElement = childElement.nextSiblingElement();
+ if (childNode.isElement())
+ m_children.append(QXmppElement(childNode.toElement()));
+ else if (childNode.isText())
+ m_value += childNode.toText().data();
+ childNode = childNode.nextSibling();
}
}
@@ -95,6 +98,16 @@ void QXmppElement::setTagName(const QString &tagName)
m_tagName = tagName;
}
+QString QXmppElement::value() const
+{
+ return m_value;
+}
+
+void QXmppElement::setValue(const QString &value)
+{
+ m_value = value;
+}
+
void QXmppElement::toXml(QXmlStreamWriter *writer) const
{
if (isNull())
@@ -103,6 +116,7 @@ void QXmppElement::toXml(QXmlStreamWriter *writer) const
writer->writeStartElement(m_tagName);
foreach (const QString &attr, m_attributes.keys())
helperToXmlAddAttribute(writer, attr, m_attributes.value(attr));
+ writer->writeCharacters(m_value);
foreach (const QXmppElement &child, m_children)
child.toXml(writer);
writer->writeEndElement();
diff --git a/source/QXmppElement.h b/source/QXmppElement.h
index 416487cb..d684ddd3 100644
--- a/source/QXmppElement.h
+++ b/source/QXmppElement.h
@@ -47,6 +47,9 @@ public:
QString tagName() const;
void setTagName(const QString &type);
+ QString value() const;
+ void setValue(const QString &text);
+
bool isNull() const;
void toXml(QXmlStreamWriter *writer) const;
@@ -54,6 +57,7 @@ private:
QMap<QString, QString> m_attributes;
QList<QXmppElement> m_children;
QString m_tagName;
+ QString m_value;
};
#endif