void AST::parse_xml(string filename) { using namespace tinyxml2; XMLDocument doc; doc.LoadFile(filename.c_str()); XMLNode* code = doc.FirstChildElement("code"); statements = process_node(code->FirstChild()); }
bool cSDL2DSceneManager::loadFromXMLFile(std::string Filename) { XMLDocument doc(Filename.c_str()); std::list<c2DLayer*> List; if(doc.LoadFile(Filename.c_str()) == XML_NO_ERROR) { //Find resources node XMLNode* ResourceTree = doc.RootElement(); if(ResourceTree) { //Enumerate resource objects for(XMLNode* child = ResourceTree->FirstChild(); child; child = child->NextSibling()) { XMLElement *Element = child->ToElement(); if(Element) { c2DLayer *Layer = new c2DLayer(); Layer->m_ZOrder = m_Layers.size(); for(XMLAttribute* ElementAttrib = const_cast<XMLAttribute*>(Element->FirstAttribute()); ElementAttrib; ElementAttrib = const_cast<XMLAttribute*>(ElementAttrib->Next())) { //Examine layers std::string AttribName = ElementAttrib->Name(); std::string AttribValue = ElementAttrib->Value(); //Detect resource type. Graphic? Audio? Text? if(AttribName=="name") { Layer->m_Name=AttribValue; continue; } if(AttribName=="posx") { Layer->m_PosX = atof(AttribValue.c_str()); } if(AttribName=="posy") { Layer->m_PosY = atof(AttribValue.c_str()); } if(AttribName=="visible") { if(AttribValue=="true") Layer->m_bVisible=true; else Layer->m_bVisible=false; } } m_Layers.push_back(Layer); //Cycle through layer objects for(XMLNode* objs = child->FirstChild(); objs; objs = objs->NextSibling()) { if(std::string(objs->Value())=="objects") { for(XMLNode* obj = objs->FirstChild(); obj; obj = obj->NextSibling()) { XMLElement *ObjElement = obj->ToElement(); addLayerObjects(Layer, ObjElement); } } } } } sortLayers(); return true; } } return false; }
PluginChipFactory::PluginChipFactory() { XMLDocument doc; FILE * f = fopen("atanua.xml", "rb"); if (doc.LoadFile(f)) { fclose(f); return; } fclose(f); // Load config XMLNode *root; for (root = doc.FirstChild(); root != 0; root = root->NextSibling()) { if (root->ToElement()) { if (stricmp(root->Value(), "AtanuaConfig")==0) { XMLNode *part; for (part = root->FirstChild(); part != 0; part = part->NextSibling()) { if (part->ToElement()) { if (stricmp(part->Value(), "Plugin") == 0) { const char *dll = ((XMLElement*)part)->Attribute("dll"); DLLHANDLETYPE h = opendll(dll); if (h) { getatanuadllinfoproc getdllinfo = (getatanuadllinfoproc)getdllproc(h, "getatanuadllinfo"); if (getdllinfo) { atanuadllinfo *dllinfo = new atanuadllinfo; getdllinfo(dllinfo); if (dllinfo->mDllVersion <= ATANUA_PLUGIN_DLL_VERSION) { mDllInfo.push_back(dllinfo); mDllHandle.push_back(h); } else { char temp[512]; sprintf(temp, "Plug-in \"%s\" version is incompatible \n" "with the current version of Atanua.\n" "\n" "Try to use it anyway?", dll); if (okcancel(temp)) { mDllInfo.push_back(dllinfo); mDllHandle.push_back(h); } } } } } } } } } } }
void AtanuaConfig::load() { XMLDocument doc; XMLDeclaration *pDec; XMLElement *pRoot; XMLElement *pElement; FILE * f = fopen("atanua.xml", "rb"); if (!f) { // Save config pDec = doc.NewDeclaration(); doc.InsertEndChild(pDec); pRoot = doc.NewElement("AtanuaConfig"); pRoot->SetAttribute("GeneratedWith",TITLE); doc.InsertEndChild(pRoot); pElement = doc.NewElement("PropagateInvalidState"); pElement->SetAttribute("value", mPropagateInvalidState == PINSTATE_PROPAGATE_INVALID); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("CustomCursors"); pElement->SetAttribute("value", mCustomCursors); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("PerformanceIndicators"); pElement->SetAttribute("value", mPerformanceIndicators); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("SwapShiftAndCtrl"); pElement->SetAttribute("value", mSwapShiftAndCtrl); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("WireFry"); pElement->SetAttribute("value", mWireFry); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("AudioEnable"); pElement->SetAttribute("value", mAudioEnable); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("ToolkitWidth"); pElement->SetAttribute("value", mToolkitWidth); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("MaxPhysicsMs"); pElement->SetAttribute("value", mMaxPhysicsMs); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("InitialWindow"); pElement->SetAttribute("width", mWindowWidth); pElement->SetAttribute("height", mWindowHeight); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("TooltipDelay"); pElement->SetAttribute("value", mTooltipDelay); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("LinePickTolerance"); pElement->SetAttribute("value", mLinePickTolerance); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("LineEndTolerance"); pElement->SetAttribute("value", mLineEndTolerance); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("LineSplitDragDistance"); pElement->SetAttribute("value", mLineSplitDragDistance); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("ChipCloneDragDistance"); pElement->SetAttribute("value", mChipCloneDragDistance); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("User"); pElement->SetAttribute("name", "[No user name set]"); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("FontSystem"); pElement->SetAttribute("CacheKeys", mFontCacheMax); pElement->SetAttribute("VBO", mUseVBOs); pElement->SetAttribute("SafeMode", mUseOldFontSystem); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("PerformanceOptions"); pElement->SetAttribute("Blending", mUseBlending); pElement->SetAttribute("AntialiasedLines", mAntialiasedLines); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("Limits"); pElement->SetAttribute("MaxBoxes", mMaxActiveBoxes); pElement->SetAttribute("PhysicsKHz", mPhysicsKHz); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("LED"); pElement->SetAttribute("Samples", mLEDSamples); pRoot->InsertEndChild(pElement); pElement = doc.NewElement("Autosave"); pElement->SetAttribute("Directory", ""); pElement->SetAttribute("Enable", "0"); pElement->SetAttribute("SaveCount", "10"); pElement->SetAttribute("Interval", "1"); pRoot->InsertEndChild(pElement); f = fopen("atanua.xml", "wb"); doc.SaveFile(f); fclose(f); } else { if (doc.LoadFile(f)) { fclose(f); return; } fclose(f); // Load config XMLNode *root; for (root = doc.FirstChild(); root != 0; root = root->NextSibling()) { if (root->ToElement()) { if (stricmp(root->Value(), "AtanuaConfig")==0) { XMLNode *part; for (part = root->FirstChild(); part != 0; part = part->NextSibling()) { if (part->ToElement()) { if (stricmp(part->Value(), "FontSystem") == 0) { ((XMLElement*)part)->QueryIntAttribute("CacheKeys", &mFontCacheMax); ((XMLElement*)part)->QueryIntAttribute("VBO", &mUseVBOs); ((XMLElement*)part)->QueryIntAttribute("SafeMode", &mUseOldFontSystem); } else if (stricmp(part->Value(), "PerformanceOptions") == 0) { ((XMLElement*)part)->QueryIntAttribute("AntialiasedLines", &mAntialiasedLines); ((XMLElement*)part)->QueryIntAttribute("Blending", &mUseBlending); } else if (stricmp(part->Value(), "PropagateInvalidState") == 0) { int propagate; ((XMLElement*)part)->QueryIntAttribute("value", &propagate); if (propagate) mPropagateInvalidState = PINSTATE_PROPAGATE_INVALID; else mPropagateInvalidState = PINSTATE_HIGHZ; } else if (stricmp(part->Value(), "CustomCursors") == 0) { ((XMLElement*)part)->QueryIntAttribute("value", &mCustomCursors); } else if (stricmp(part->Value(), "PerformanceIndicators") == 0) { ((XMLElement*)part)->QueryIntAttribute("value", &mPerformanceIndicators); } else if (stricmp(part->Value(), "SwapShiftAndCtrl") == 0) { ((XMLElement*)part)->QueryIntAttribute("value", &mSwapShiftAndCtrl); } else if (stricmp(part->Value(), "WireFry") == 0) { ((XMLElement*)part)->QueryIntAttribute("value", &mWireFry); } else if (stricmp(part->Value(), "AudioEnable") == 0) { ((XMLElement*)part)->QueryIntAttribute("value", &mAudioEnable); } else if (stricmp(part->Value(), "ToolkitWidth") == 0) { ((XMLElement*)part)->QueryIntAttribute("value", &mToolkitWidth); } else if (stricmp(part->Value(), "MaxPhysicsMs") == 0) { ((XMLElement*)part)->QueryIntAttribute("value", &mMaxPhysicsMs); } else if (stricmp(part->Value(), "InitialWindow") == 0) { ((XMLElement*)part)->QueryIntAttribute("width", &mWindowWidth); ((XMLElement*)part)->QueryIntAttribute("height", &mWindowHeight); } else if (stricmp(part->Value(), "TooltipDelay") == 0) { ((XMLElement*)part)->QueryIntAttribute("value", &mTooltipDelay); } else if (stricmp(part->Value(), "LinePickTolerance") == 0) { ((XMLElement*)part)->QueryFloatAttribute("value", &mLinePickTolerance); } else if (stricmp(part->Value(), "LineEndTolerance") == 0) { ((XMLElement*)part)->QueryFloatAttribute("value", &mLineEndTolerance); } else if (stricmp(part->Value(), "LineSplitDragDistance") == 0) { ((XMLElement*)part)->QueryFloatAttribute("value", &mLineSplitDragDistance); } else if (stricmp(part->Value(), "ChipCloneDragDistance") == 0) { ((XMLElement*)part)->QueryFloatAttribute("value", &mChipCloneDragDistance); } else if (stricmp(part->Value(), "Limits") == 0) { ((XMLElement*)part)->QueryIntAttribute("MaxBoxes", &mMaxActiveBoxes); ((XMLElement*)part)->QueryIntAttribute("PhysicsKHz", &mPhysicsKHz); } else if (stricmp(part->Value(), "LED") == 0) { ((XMLElement*)part)->QueryIntAttribute("Samples", &mLEDSamples); if (mLEDSamples <= 0) mLEDSamples = 1; if (mLEDSamples > 10000) mLEDSamples = 10000; } else if (stricmp(part->Value(), "User") == 0) { const char *t = ((XMLElement*)part)->Attribute("name"); if (t && strlen(t) > 0) { delete[] mUserInfo; mUserInfo = mystrdup(t); } } if (stricmp(part->Value(), "Autosave") == 0) { ((XMLElement*)part)->QueryIntAttribute("Enable", &mAutosaveEnable); ((XMLElement*)part)->QueryIntAttribute("SaveCount", &mAutosaveCount); ((XMLElement*)part)->QueryIntAttribute("Interval", &mAutosaveInterval); const char * dir = ((XMLElement*)part)->Attribute("Directory"); if (dir) { int len = strlen(dir); if (dir[len] == '/' || dir[len] == '\\') { mAutosaveDir = mystrdup(dir); } else { char temp[1024]; sprintf(temp, "%s/", dir); mAutosaveDir = mystrdup(temp); } } else { mAutosaveDir = mystrdup(""); } } } } } } } } }
int main() { // CURL* curl; //our curl object // // struct BufferStruct output; // Create an instance of out BufferStruct to accept LCs output // output.buffer = NULL; // output.size = 0; // // curl_global_init(CURL_GLOBAL_ALL); //pretty obvious // curl = curl_easy_init(); // // curl_easy_setopt(curl, CURLOPT_URL, "http://www.findyourfate.com/rss/horoscope-astrology-feed.asp?mode=view&todate=8/20/2015"); // curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteMemoryCallback); // curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&output); // curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); //tell curl to output its progress // // curl_easy_perform(curl); // curl_easy_cleanup(curl); // // FILE * fp; // fp = fopen( "example.xml","w"); // cout<<"HEILL!"; // if( !fp ) // return 1; // fprintf(fp, output.buffer ); // fclose( fp ); // // if( output.buffer ) // { // free ( output.buffer ); // output.buffer = 0; // output.size = 0; // } // // cin.get(); XMLDocument doc; doc.LoadFile("example.xml"); cout<< "ERROR ID: "<<doc.ErrorName()<<endl; XMLNode * pRoot = doc.FirstChild(); if (pRoot ==NULL) cout<<"ERROR!!!"<<endl; XMLNode* SiblingNode = pRoot->NextSibling(); XMLNode* ChildNode = SiblingNode->FirstChild(); XMLElement *ChildElmt = ChildNode->ToElement(); string strTagName = ChildElmt->Name(); cout<<strTagName<<endl; XMLNode* Child_2_Node = ChildNode->FirstChild(); XMLElement *Child_2_NodeElmt = Child_2_Node->ToElement(); strTagName = Child_2_NodeElmt->Name(); cout<<strTagName<<endl; strTagName = Child_2_NodeElmt->GetText(); cout<<strTagName<<endl; XMLNode* secSibling = Child_2_Node->NextSibling(); XMLElement *Sib_2_NodeElmt = secSibling->ToElement(); strTagName = Sib_2_NodeElmt->Name(); cout<<strTagName<<endl; strTagName = Sib_2_NodeElmt->GetText(); cout<<strTagName<<endl; //XMLElement* pElement = pRoot->ToElement(); //if (pElement ==NULL) // cout<<"ERROR"<<endl; // XMLElement * pElement = pRoot->FirstChildElement("rss")->FirstChildElement("channel"); // if (pElement ==NULL) // cout<<"ERROR"<<endl; // if (pElement ==NULL) // cout<<"ERROR"<<endl; // const char* title = pElement->GetText(); // printf( "Name of play (1): %s\n", title ); // cout << endl << pElement->GetText() << endl; //cin.get(); //curl_global_cleanup(); return 0; }
int main() { bool soundFlag = false; std::string headlines[3000]; int strCount = 0; bool storyExists = false; int pageSwitch = 0; while (true){ std::ofstream a_file ( "ESPN_NEWS.txt", std::ios::app ); CURL *curl; FILE *fp; CURLcode res; if (pageSwitch==0){ char *url = "http://sports.espn.go.com/espn/rss/news"; char outfilename[FILENAME_MAX] = "input3.xml"; curl = curl_easy_init(); if (curl) { fp = fopen(outfilename,"wb"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); res = curl_easy_perform(curl); curl_easy_cleanup(curl); fclose(fp); } } else if(pageSwitch==1){ char *url = "http://sports.espn.go.com/espn/rss/nfl/news"; char outfilename[FILENAME_MAX] = "input3.xml"; curl = curl_easy_init(); if (curl) { fp = fopen(outfilename,"wb"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); res = curl_easy_perform(curl); curl_easy_cleanup(curl); fclose(fp); } } else if(pageSwitch==2){ char *url = "http://sports.espn.go.com/espn/rss/nba/news"; char outfilename[FILENAME_MAX] = "input3.xml"; curl = curl_easy_init(); if (curl) { fp = fopen(outfilename,"wb"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); res = curl_easy_perform(curl); curl_easy_cleanup(curl); fclose(fp); } } else{ char *url = "http://sports.espn.go.com/espn/rss/espnu/news"; char outfilename[FILENAME_MAX] = "input3.xml"; curl = curl_easy_init(); if (curl) { fp = fopen(outfilename,"wb"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); res = curl_easy_perform(curl); curl_easy_cleanup(curl); fclose(fp); } } //////////////////////////////////////////////////////////////// bool loopFlag = true; bool bigLoop = true; tinyxml2::XMLDocument doc; doc.LoadFile( "input3.xml" ); XMLNode *rootnode = doc.FirstChild(); ////////////////////////////// rootnode = rootnode->NextSibling(); rootnode = rootnode->FirstChild();////////////hard code to get past the xml header into <ITEM> </ITEM portion rootnode = rootnode->FirstChild(); rootnode = rootnode->NextSibling(); /////////////////////////////////// while(loopFlag==true){ if(std::strcmp(rootnode->Value(),"item") != 0){ rootnode = rootnode->NextSibling(); } else loopFlag=false; } while(bigLoop==true){ XMLHandle safe = rootnode; if(safe.ToNode()==NULL) bigLoop=false; else{ NewsEntry *story = new NewsEntry(); rootnode = rootnode->FirstChild(); rootnode = rootnode->NextSibling(); rootnode = rootnode->FirstChild(); story->setTitle(rootnode->Value()); for(int x=0; x<strCount; x++){ if(story->getTitle().compare(headlines[x])==0){ storyExists = true; } } if(storyExists==false){ if(soundFlag==true){ PlaySound(TEXT("sportscenter.wav"), NULL, SND_FILENAME | SND_ASYNC); } std::cout<< story->getTitle() <<std::endl; a_file << story->getTitle(); a_file << "\n"; headlines[strCount] = story->getTitle(); strCount++; } rootnode = rootnode->Parent(); rootnode = rootnode->NextSibling(); rootnode = rootnode->FirstChild(); story->setDescription(rootnode->Value()); if(storyExists==false){ std::cout<< story->getDescription() <<std::endl; a_file << story->getDescription(); a_file << "\n"; } rootnode = rootnode->Parent(); rootnode = rootnode->NextSibling(); rootnode = rootnode->FirstChild(); story->setPubDate(rootnode->Value()); if(storyExists==false){ std::cout << story->getPubdate() <<std::endl; a_file << story->getPubdate(); a_file << "\n"; } rootnode = rootnode->Parent(); rootnode = rootnode->NextSibling(); rootnode = rootnode->FirstChild(); story->setLink(rootnode->Value()); if(storyExists==false){ //std::cout<< story->getLink() << std::endl; a_file << story->getLink(); a_file << "\n"; a_file << "\n"; printf("\n"); } rootnode = rootnode->Parent(); rootnode = rootnode->Parent(); rootnode = rootnode->NextSibling(); delete story; storyExists = false; } } pageSwitch++; if(pageSwitch>3){ pageSwitch = 0; soundFlag=true; } a_file.close(); Sleep(100000); } return 0; }