Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6341737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:05:51+00:00 2026-05-24T20:05:51+00:00

I am writing a class to parse Itunes Libray File using QXmlQuery and QT-XSLT.

  • 0

I am writing a class to parse Itunes Libray File using QXmlQuery and QT-XSLT.

Here’s my sample code:

ItunesLibParser::ItunesLibParser()
{
    pathToLib = QString("/Users/rakesh/temp/itunes_xslt/itunes_music_library.xml");
}

void ItunesLibParser::createXSLFile(QFile &inFile)
{
    if (inFile.exists()) {
        inFile.remove();
    }

    inFile.open(QIODevice::WriteOnly);
    QTextStream out(&inFile);

    out << QString("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
    out << QString("<xsl:stylesheet version=\"2.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">");
    out << QString("<xsl:output method=\"text\" />");


    out << QString("<xsl:template name=\"playlistNames\">");
    out << QString("<xsl:value-of select=\"child::integer[preceding-sibling::key[1]='Playlist ID']\"/>");
    out << QString("<xsl:text>&#xa;</xsl:text>");
    out << QString("<xsl:value-of select=\"child::string[preceding-sibling::key[1]='Name']\"/>");
    out << QString("<xsl:text>&#xa;</xsl:text>");
    out << QString("</xsl:template>");


    out << QString("<xsl:template match=\"/\">");
    out << QString("<xsl:for-each select=\"plist/dict/array/dict\">");
    out << QString("<xsl:call-template name=\"playlistNames\"/>");
    out << QString("</xsl:for-each>");
    out << QString("</xsl:template>");

    out << QString("</xsl:stylesheet>");

    inFile.close();

    return;

}

void ItunesLibParser::dumpPlayList()
{

    QXmlQuery query(QXmlQuery::XSLT20);
    query.setFocus(QUrl(pathToLib));

    QFile xslFile("plist.xsl");
    createXSLFile(xslFile);

    query.setQuery(QUrl("plist.xsl"));

    QStringList* outDump = new QStringList();

    query.evaluateTo(outDump);


    if(outDump != NULL) {

        QStringList::iterator iter = (*outDump).begin();
        for (; iter != (*outDump).end();
               ++iter)
            //code flow doesn't come here. It means being() == end()
            std::cout << (*iter).toLocal8Bit().constData() << std::endl;
    }

    return;
}

OutDump here doesn’t contain data. While in Shell (xmlpatterns-4.7 mystlye.xsl itunes_music_library.xml ), If I run my Query I get proper output.

Is there anything, wrong I am doing while calling it programatically? I checked out plist.xsl is created properly, but my doubt is whether “/Users/rakesh/temp/itunes_xslt/itunes_music_library.xml” this is getting loaded or not? Or there might be another reasons, I am confused. Is there any experts to throw some light onto problem, I will be glad.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:05:53+00:00Added an answer on May 24, 2026 at 8:05 pm

    Intead from reading from the file, I read the file into buffer and converted that int string as passed to setquery. That solved the problem.

    Here’s sample code for those who could face similar problem in future.

    void ITunesMlibParser::parsePlayListItemXml(int plistId)
    {
    
        QXmlQuery xQuery(QXmlQuery::XSLT20);
        QFile inFile("/Users/rakesh/temp/itunes_xslt/itunes_music_library.xml");
    
        if (!inFile.open(QIODevice::ReadOnly)) {
            return;
        }
    
        QByteArray bArray;
        while (!inFile.atEnd()) {
            bArray += inFile.readLine();
        }
    
        QBuffer xOriginalContent(&bArray);
        xOriginalContent.open(QBuffer::ReadWrite);
        xOriginalContent.reset();
    
    
        if (xQuery.setFocus(&xOriginalContent))
             std::cout << "File Loaded" << std::endl;
    
    //.. 
    //..
    
    }
    

    Thanks
    Rakesh

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a test for a file parser class. The parse method receives a
I am writing some simple code to parse a file and return the number
I am writing a .NET class that needs to parse the command line of
I'm writing a class in C++ that I cannot debug by using F5. The
I am writing a file that can parse rdf and owl files. I am
i was writing a program and using double.Try Parse to check if a string
I'm writing a python class to parse XML and pull out tag names and
I'm using Android to read a document off the net, surprise I'm writing here
We're using OpenCSV to parse a CSV file and bind its values directly to
I'm writing an asynchronous server and client with C#. I took sample code from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.