Question

I need to read the a,b,c values(wheqre a,b,c are the name of some atributes) foreach node and list them in a table, but I don't know how to read the node values. Could you give an example code, please?

Thanks in advance

Was it helpful?

Solution

QFile file("file.xml");
if (file.open(QIODevice::ReadOnly)) {
    QXmlStreamReader reader(file.readAll());
    file.close();
    while(!reader.atEnd()) {
        reader.readNext();
        if (reader.isStartElement()) {
            if (reader.name() == "node_name") {
                foreach(const QXmlStreamAttribute &attr, reader.attributes()) {
                    if (attr.name().toString() == QLatin1String("attribute_name")) {
                        QString attribute_value = attr.value().toString();
                        // do something
                    }
                }
            }
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top