Download NHK English news podcast automatically. XML Parser "spxml" is used. This application requires mpod mother board. See also http://mbed.org/users/geodenx/notebook/mpod/

Dependencies:   BlinkLed HTTPClient EthernetInterface FatFileSystemCpp MSCFileSystem spxml mbed-rtos mbed

Fork of mpod_nhk_english by Satoshi Togawa

Download NHK English news podcast automatically.
XML Parser "spxml" is used.
This application requires mpod mother board.
See also http://mbed.org/users/geodenx/notebook/mpod/

Revision:
4:7dae52cf560f
Parent:
3:07562878d3c3
Child:
5:e87211ff9c23
--- a/main.cpp	Sun Aug 19 15:57:55 2012 +0000
+++ b/main.cpp	Mon Aug 20 13:27:17 2012 +0000
@@ -4,9 +4,9 @@
 #include "HTTPClient.h"
 #include "HTTPFile.h"
 #include "BlinkLed.h"
-#include "tinyxml2.h"
-
-using namespace tinyxml2;
+#include "spdomparser.hpp"
+#include "spxmlnode.hpp"
+#include "spxmlhandle.hpp"
 
 int GetFile(const char *path, const char *url);
 
@@ -40,31 +40,50 @@
     eth.connect();
     
     // Obtain original lastBuildDate
+    
     char lastBuildDateOriginal[128] = {0};
     {
-        XMLDocument docOriginal;
-        if(XML_SUCCESS != docOriginal.LoadFile(rssPath))
-        {
-            strcpy(lastBuildDateOriginal, "No original english.xml in USB memory");
-        }
-        else
+    FILE * fp = fopen ( rssPath, "r" );
+    if( NULL == fp ) {
+        printf( "cannot not open %s\n", rssPath );
+        sprintf(lastBuildDateOriginal, "cannot not open original %s", rssPath );
+    }
+    else
+    {
+        fseek(fp, 0, SEEK_END); // seek to end of file
+        unsigned int size = ftell(fp);
+        fseek(fp, 0, SEEK_SET); // seek to head of file
+        
+        char * source = NULL;
+        source = ( char * ) malloc ( size + 1 );
+        fread ( source, size, sizeof ( char ), fp );
+        fclose ( fp );
+        source[ size ] = 0;
+        
+        SP_XmlDomParser parser;
+        parser.append( source, strlen( source ) );
+        free( source );
+        
+        SP_XmlHandle rootHandle( parser.getDocument()->getRootElement() );
+        
+        SP_XmlCDataNode * lastBuildDateNode = rootHandle.getChild( "channel" ).getChild( "lastBuildDate" ).getChild(0).toCData();
+        if( NULL != lastBuildDateNode )
         {
-            XMLElement* lastBuildDateOriginalElement = docOriginal.FirstChildElement("rss")->FirstChildElement("channel")->FirstChildElement("lastBuildDate");
-            if(NULL == lastBuildDateOriginalElement)
-            {
-                strcpy(lastBuildDateOriginal, "No \"lastBuildDate\" element in original RSS");
-            }
-            else
-            {
-                strcpy(lastBuildDateOriginal, lastBuildDateOriginalElement->GetText());
-            }
+            printf( "Find /rss/channel/lastBuildDate/text()\n");
+            printf("text() of lastBuildDate: %s\n", lastBuildDateNode->getText());
+            strcpy(lastBuildDateOriginal, lastBuildDateNode->getText());
+        } else {
+            printf( "Cannot found /rss/channel/lastBuildDate/text()\n" );
+            sprintf(lastBuildDateOriginal, "Cannot found /rss/channel/lastBuildDate/text()");
         }
     }
+    }
     printf("\nlastBuildDate (original): %s\n", lastBuildDateOriginal);
     
     // Download RSS
     GetFile(rssPath, rssUrl);
     
+    #if 0
     // Obtain current lastBuildDate 
     char lastBuildDateCurrent[128] = {0};
     char mp3Url[256] = {0};
@@ -129,6 +148,7 @@
     {
         GetFile(mp3Path, mp3Url);
     }
+    #endif
     
     // Wait for the completion of writing to USB Mass Storage Device.
     wait(1);