QXmlStreamAttributes attributes; attributes.append("id", "123"); attributes.append("name", "John"); if(attributes.hasAttribute("id")) { qDebug() << "Attribute 'id' exists"; }
QXmlStreamReader reader(xmlString); while(!reader.atEnd()) { if(reader.isStartElement()) { QXmlStreamAttributes attributes = reader.attributes(); if(attributes.hasAttribute("type")) { QString type = attributes.value("type").toString(); // do something with the attribute value } } reader.readNext(); }In this example, we use QXmlStreamReader to read an XML document. When we encounter a start element, we get its attributes using the attributes method of QXmlStreamReader. Then, we check if the attribute with the name "type" exists and retrieve its value using the value method of QXmlStreamAttributes. Package Library: Qt.