.b4s playlist parser WINAMP XML PlaylistFormat

More info on this file format is at http://filext.com/file-extension/B4S
This can be parsed using following xml based parser application.

/* .b4s parser Application */
/*Author:chandrashekar bs*/
/*email:buggs.cancerion@gmail.com/chandragoan@gmail.com*/


/* I have not added <> for including files because of in google blogs since <> are interprested as htnl syntaxes and content within thos are not appeared*/

#include iostream
#include string.h
#include libxml/parser.h
#include libxml/xinclude.h
#include libxml/tree.h
#include libxml/xmlIO.h

int main(int argc, char **argv)
{


    xmlDocPtr doc;
    xmlNodePtr nodePtr;
    xmlNodePtr rootnodePtr;
    xmlChar *xmlbuff;
    int loopcount1, loopcount2, loopcount3, loopcount4;
   
    loopcount1=loopcount2=loopcount3=loopcount4=0;


    if(argc !=2)
    {
        printf("Usage %s: Enter valid b4s playlist file",argv[1]);
    }
    char *filename = (char *)argv[1];
    doc = xmlParseFile((const char*)filename);
    rootnodePtr = xmlDocGetRootElement(doc);
    if(rootnodePtr != NULL)
    {
        //Parse complete child nodes
        xmlNodePtr nextnodePtr, childrenNodePtr;
        xmlbuff = xmlNodeGetContent(rootnodePtr);
        printf("rootnodePtr->name = %s\n", rootnodePtr->name);   
        childrenNodePtr = rootnodePtr;
        if(!childrenNodePtr)
        {
            printf("There is no child node for root node\n");
            exit(-1);   
        }
            printf("childrenNodePtr-name = %s\n", childrenNodePtr->name);   
            nextnodePtr = childrenNodePtr;
        if(nextnodePtr)
        {
            loopcount1++;   
            if(childrenNodePtr != NULL)   
            {
                    loopcount2++;
               
                if(childrenNodePtr->xmlChildrenNode == NULL)
                    childrenNodePtr = childrenNodePtr->next;
                else
                    childrenNodePtr = childrenNodePtr->xmlChildrenNode;
               
                while(childrenNodePtr != NULL)
                {
                    loopcount3++;

                    xmlOutputBufferPtr buf;
                                        xmlNodePtr temp1 = childrenNodePtr;
                    printf("childrenNodePtr-name3 = %s\n", childrenNodePtr->name);
                    if(!xmlStrcmp(childrenNodePtr->name, (const xmlChar *) "playlist"))
                    {   
                        xmlChar* key;   
                        key = xmlGetProp(childrenNodePtr, (const xmlChar*)"num_entries");   
                        printf("key %s\n",key);
                        key = xmlGetProp(childrenNodePtr, (const xmlChar*)"label");   
                        printf("key %s\n",key);
                    }

                    childrenNodePtr = childrenNodePtr->xmlChildrenNode;
                    while(childrenNodePtr != NULL)
                    {
                        xmlNodePtr temp2;
                        loopcount4++;
                           
                                            printf("childrenNodePtr-name4 = %s\n", childrenNodePtr->name);
                        if(!xmlStrcmp(childrenNodePtr->name, (const xmlChar *) "entry"))
                        {
                            xmlChar* key;   
                            key = xmlGetProp(childrenNodePtr, (const xmlChar*)"Playstring");   
                            printf("key %s\n",key);
                        }
                        temp2 = childrenNodePtr;
                           
                            childrenNodePtr = childrenNodePtr->xmlChildrenNode;
                        while(childrenNodePtr != NULL)
                        {
                           
                                                printf("childrenNodePtr-name5 = %s\n", childrenNodePtr->name);
                            xmlbuff = xmlNodeGetContent(childrenNodePtr);
                            printf("childrenNodePtr content %s\n",xmlbuff);
                            childrenNodePtr = childrenNodePtr->next;
                        }
                        childrenNodePtr = temp2->next;
                    }   
                    childrenNodePtr = temp1->next;   
                   
                }
            }   
       
        }
    }
    else
    {
        printf("There is no root child node\n");
    }
return 0;

Comments

Popular posts from this blog

Getting backtrace during stack corruption

Analyzing Crash dumps in Linux using GDB