test.cpp

Go to the documentation of this file.
00001 
00012 #include "xmlNode.h"
00013 
00014 #include <stdio.h>
00015 
00016 #include <fstream>
00017 
00018 using namespace std;
00019 using namespace sxml;
00020 
00024 int main(int argc, char* argv)
00025 {
00026         ifstream fin("test.xml");
00027         
00028         printf("\n");
00029         
00030         if (!fin.good()) {
00031                 printf("Cannot open test.xml!\n");
00032                 exit(1);
00033                 
00034         }
00035         
00036         XmlNode* xmlNode = new XmlNode();
00037         
00038         try {
00039                 xmlNode->readFromStream(fin);
00040                 fin.close();
00041                 
00042         } catch (sxml::Exception e) {
00043                 printf("Error parsing XML file: exception %d\n", (int) e);
00044                 fin.close();
00045                 exit(1);
00046                 
00047         }
00048         
00049         XmlNode* treasures = xmlNode->findFirst("treasures");
00050         if (treasures != NULL) {
00051                 NodeSearch* ns = treasures->findInit("treasure");
00052                 XmlNode* tnode = treasures->findNext(ns);
00053                 while (tnode != NULL) {
00054                         XmlNode* msgNode = tnode->findFirst("message");
00055                         if (msgNode->children.size() > 0 && 
00056                                 msgNode->children[0]->type == ntTextNode) 
00057                         {
00058                                 printf("%s: %s...\n", 
00059                                         tnode->attributes["name"].c_str(), 
00060                                         msgNode->children[0]->name.substr(0, 60).c_str());
00061                                 
00062                         }
00063                         
00064                         tnode = treasures->findNext(ns); 
00065                         
00066                 }
00067                 
00068         
00069         } else {
00070                 printf("Node 'treasures' not found.\n");
00071                 exit(1);
00072                 
00073         }
00074         
00075         printf("\n");
00076         
00077 }

Generated on Sun Dec 10 18:47:09 2006 for XmlNode by  doxygen 1.4.6