<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE CINEMAS_PROJECT_FILE>
<CinemasProject XMLversion="1">
<Cascade>
<ChildrenIDs>
<JobName>1</JobName>
<JobName>2</JobName>
<JobName>3</JobName>
</ChildrenIDs>
</Cascade>
如何读取XML中具有相同标记的元素&#34; JobName&#34;使用QXmlStreamReader
答案 0 :(得分:1)
QFile* file = new QFile(paths);
if(!file->open(QIODevice::ReadOnly | QIODevice::Text)){
qDebug() << "Failed To Open Xml";
return;
}
QXmlStreamReader* xml = new QXmlStreamReader(file);
while(!xml->atEnd()){
QXmlStreamReader::TokenType token = xml->readNext();
if(token == QXmlStreamReader::StartDocument){
continue;
}
if(xml->name() == "JobName"){
qDebug() << xml->readElementText();
}
}