如何读取具有相同标记名称的 XML


<?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>

如何使用 QXmlStreamReader 读取具有相同标记"JobName"的 XML 元素

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();
    }
}

相关内容

  • 没有找到相关文章

最新更新