Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read iTune xml Library
Forum Updated to NodeBB v4.3 + New Features

Read iTune xml Library

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jaswinder
    wrote on last edited by
    #1

    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,

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rcari
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • J Offline
        J Offline
        Jaswinder
        wrote on last edited by
        #3

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

        }
        @

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rcari
          wrote on last edited by
          #4

          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!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved