QXmpp::Xml::Element Class

class QXmpp::Xml::Element

A generic, recursive representation of an XML element. More...

Header: #include <QXmppXmlElement.h>
Since: QXmpp 1.16

Public Functions

Element()
Element(QString tag, QString xmlns = {})
void addChild(QXmpp::Xml::Element child)
std::optional<QString> attribute(QStringView name) const
const std::vector<QXmpp::Xml::Attribute> &attributes() const
const std::vector<QXmpp::Xml::Element> &children() const
void removeAttribute(QStringView name)
void setAttribute(const QString &name, const QString &value)
void setAttributes(std::vector<QXmpp::Xml::Attribute> attributes)
void setChildren(std::vector<QXmpp::Xml::Element> children)
void setTag(QString tag)
void setText(QString text)
void setXmlns(QString xmlns)
const QString &tag() const
const QString &text() const
void toXml(QXmpp::Private::XmlWriter &writer) const
const QString &xmlns() const

Static Public Members

QXmpp::Xml::Element fromDom(const QDomElement &el)

Detailed Description

Element holds a tag name, an optional XML namespace, a list of attributes, a list of child elements and a simple text content. It is a value type meant to eventually replace the older QXmppElement.

Mixed content (text interleaved with child elements) is not supported; only a single text value is kept.

Member Function Documentation

[constexpr noexcept default] Element::Element()

Default-constructs an instance of Element.

[explicit] Element::Element(QString tag, QString xmlns = {})

Constructs an element with the given tag name tag and (optional) namespace xmlns.

void Element::addChild(QXmpp::Xml::Element child)

Appends the child element child.

std::optional<QString> Element::attribute(QStringView name) const

Returns the value of the attribute named name, if it exists.

See also setAttribute().

const std::vector<QXmpp::Xml::Attribute> &Element::attributes() const

Returns the list of attributes.

See also setAttributes().

const std::vector<QXmpp::Xml::Element> &Element::children() const

Returns the list of child elements.

See also setChildren().

[static] QXmpp::Xml::Element Element::fromDom(const QDomElement &el)

Recursively builds an Element from the QDomElement el.

The DOM element is expected to be parsed with namespace processing enabled.

void Element::removeAttribute(QStringView name)

Removes the attribute named name, if it exists.

void Element::setAttribute(const QString &name, const QString &value)

Sets the attribute name to value, replacing an existing one with the same name.

See also attribute().

void Element::setAttributes(std::vector<QXmpp::Xml::Attribute> attributes)

Replaces all attributes with attributes.

See also attributes().

void Element::setChildren(std::vector<QXmpp::Xml::Element> children)

Replaces all child elements with children.

See also children().

void Element::setTag(QString tag)

Sets the tag name of the element to tag.

See also tag().

void Element::setText(QString text)

Sets the text content of the element to text.

See also text().

void Element::setXmlns(QString xmlns)

Sets the XML namespace of the element to xmlns.

See also xmlns().

const QString &Element::tag() const

Returns the tag name of the element.

See also setTag().

const QString &Element::text() const

Returns the text content of the element.

See also setText().

void Element::toXml(QXmpp::Private::XmlWriter &writer) const

Recursively serializes the element to writer.

const QString &Element::xmlns() const

Returns the XML namespace of the element (may be empty).

See also setXmlns().