dir2xml

前端之家收集整理的这篇文章主要介绍了dir2xml前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
void FileList2XML::on_generateXml_clicked() { QDir pDir(ui->DirPath->text()); m_doc = QDomDocument(pDir.dirName()); QDomElement root = m_doc.createElement(QObject::tr("%1").arg(pDir.dirName())); m_doc.appendChild(root); GenerateXML(pDir,root); QString xml = m_doc.toString(); QFile file(ui->xmlPath->text()); file.open(QIODevice::WriteOnly); file.write(xml.toLatin1().data()); file.close(); } void FileList2XML::GenerateXML(QDir pDir,QDomElement &root) { QFileInfoList folderList = pDir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries); int count = folderList.count(); for(int i=0; i<count;i++) { QString fileName = folderList.at(i).fileName(); if(folderList.at(i).isDir()) { QDir subDir(folderList.at(i).filePath()); QDomElement tag = m_doc.createElement(fileName); root.appendChild(tag); GenerateXML(subDir,tag); } else { root.appendChild(m_doc.createTextNode(fileName.append("\n"))); } } } 原文链接:https://www.f2er.com/xml/296764.html

猜你在找的XML相关文章