<?xml version="1.0" encoding="UTF-8"?>
<downloadedBook allBookNum="37"> <bookName>003271794096_t.jpg.jpg</bookName> <bookName>007059792749_t.jpg.jpg</bookName> <bookName>014782664314_t.jpg.jpg</bookName> <bookName>028327044903_t.png.jpg</bookName> <bookName>043266992248_t.jpg.jpg</bookName> <bookName>050052879366_t.jpg.jpg</bookName> <bookName>051133103264_t.jpg.jpg</bookName> <bookName>052772634943_t.jpg.jpg</bookName> <bookName>053216658523_t.jpg.jpg</bookName> <bookName>053718215004_t.jpg.jpg</bookName> <bookName>086808583621_t.png.jpg</bookName> <bookName>092597316988_t.jpg.jpg</bookName> <bookName>101422595689_t.jpg.jpg</bookName> <bookName>171815348127_t.jpg.jpg</bookName> <bookName>173685292211_t.png.jpg</bookName> <bookName>174317764122_t.jpg.jpg</bookName> <bookName>175781233893_t.jpg.jpg</bookName> <bookName>384697615314_t.jpg.jpg</bookName> <bookName>429771120927_t.jpg.jpg</bookName> <bookName>802271493020_t.jpg.jpg</bookName> <bookName>803866642622_t.jpg.jpg</bookName> <bookName>804044529735_t.jpg.jpg</bookName> <bookName>805091931174_t.jpg.jpg</bookName> <bookName>827063938015_t.jpg.jpg</bookName> <bookName>860638063899_t.jpg.jpg</bookName> <bookName>863599631138_t.png.jpg</bookName> <bookName>864336326832_t.jpg.jpg</bookName> <bookName>864557036019_t.jpg.jpg</bookName> <bookName>895527473037_t.jpg.jpg</bookName> <bookName>900335760282_t.jpg.jpg</bookName> <bookName>902097564977_t.jpg.jpg</bookName> <bookName>902772546962_t.jpg.jpg</bookName> <bookName>903320076724_t.jpg.jpg</bookName> <bookName>921319568134_t.jpg.jpg</bookName> <bookName>925263473461_t.jpg.jpg</bookName> <bookName>926891195920_t.jpg.jpg</bookName> <bookName>938512030731_t.jpg.jpg</bookName></downloadedBook>//读取上面的XML文件如下
QFile file("downloadedBookXMl/downloaded_book.xml");//xml文件所在的路径
QXmlStreamReader read;//定义读取的对象 if(file.open(QIODevice::ReadOnly | QIODevice::Text)) { read.setDevice(&file); read.readNext(); while(!read.atEnd()) { if(read.isStartElement()) { if(read.name()=="downloadedBook")//这个是根节点 {}
if (read.name()=="bookName")//这个是子节点 { QString bookName=read.readElementText();//读取节点上的内容,字符串 } } else if(read.isEndElement()) { if(read.name()=="downloadedBook") { break; }}
read.readNext(); } else { qDebug("read file error"); } file.close();