How to read XML which have same tag name

227 Views Asked by At
<?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>

How to read the elements in XML which is having same tag "JobName" using QXmlStreamReader

1

There are 1 best solutions below

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