From 5a764007436eac8416a2d567bbc5e0a56ffc4240 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Fri, 12 Feb 2010 09:21:28 +0000 Subject: add support for nest QXmppElements --- source/QXmppElement.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source/QXmppElement.cpp') 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::children() const +{ + return m_children; +} + +void QXmppElement::setChildren(QList &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(); } -- cgit v1.2.3