Read iTune xml Library
-
Hi,
I wan to read iTune xml Library in qt (windows). I also want to read iTune playlist, podcast etc.
Can some one suggest me the best way to parse this, Is any c++ library to parse this or i need to read this by using QXmlStreamReader.Thanks in advance,
-
Given that the iTunes XML files are actually PLIST files which have a strict "DTD":http://www.apple.com/DTDs/PropertyList-1.0.dtd, you can assume that all those XML files are well-formatted. You can therefore use the very fast and lightweight "QXMLStreamReader":http://qt-project.org/doc/qt-4.8/qxmlstreamreader.html you picked up. It is part of QtCore, thus no need for QtXml.
I don't know of any library that does what you want, however it should be pretty straightforward as these are rather large but very simple documents. -
Hello Rcari,
I read this in this way, is this write way?@
void Project::parseiTuneXML(const QString iTuneFilePath)
{
QFile xmlFile;
xmlFile.setFileName(iTuneFilePath);
if (!xmlFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Load XML File Problem.";
}QXmlStreamReader xmlReader(&xmlFile); while(!xmlReader.atEnd() && !xmlReader.hasError()) { QXmlStreamReader::TokenType token = xmlReader.readNext(); if(token == QXmlStreamReader::StartDocument) { continue; } if(token == QXmlStreamReader::StartElement) { if(xmlReader.name() == "key") { QString NodeName=""; QString NodeValue=""; NodeName=(xmlReader.readElementText()); xmlReader.readNext(); if(xmlReader.name() == "integer") { NodeValue=(xmlReader.readElementText()); } else if(xmlReader.name() == "string") { NodeValue=(xmlReader.readElementText()); } if(NodeName=="Playlists") { return; } else { qDebug()<<NodeName<<" : "<<NodeValue; } } } } xmlFile.close(); xmlReader.clear();
}
@ -
It's one way... The QXmlStreamReader is very useful to write recursive parsers: for each type of start element token you meet, you call a specific function which does what it has to do with that, processes sub elements (by calling their respective handler function) and so on. This allows you to have very limited code in each function as it only has to deal with the proper types it may encounter in the subelements. I hope this is clear enough!