#include "xmlBase/IFile.h"
#include <string>
#include <iostream>
Go to the source code of this file.
Functions | |
void | lookFor (xmlBase::IFile *ifile, const char *section, const char *item) |
Test program for IFile facility within xmlBase package. | |
int | main () |
void lookFor | ( | xmlBase::IFile * | ifile, | |
const char * | section, | |||
const char * | item | |||
) |
Test program for IFile facility within xmlBase package.
Definition at line 58 of file test_IFile.cxx.
References xmlBase::IFile::contains(), xmlBase::IFile::getDouble(), xmlBase::IFile::getInt(), and xmlBase::IFile::getString().
Referenced by main().
00058 { 00059 bool haveItem = ifile->contains(section, item); 00060 std::cout << "Item " << item << " in section " << section; 00061 00062 if (haveItem) { 00063 std::cout << " was found." << std::endl; 00064 // try writing in various formats 00065 const char* charRep = ifile->getString(section, item); 00066 std::cout << "..as a string = " << charRep << std::endl; 00067 00068 try { 00069 int intRep = ifile->getInt(section, item); 00070 std::cout << "..as an int = " << intRep << std::endl; 00071 } 00072 catch (xmlBase::IFileException toCatch) { 00073 std::cout << "**ERROR** int conversion failed " 00074 << std::endl << std::endl; 00075 } 00076 00077 try { 00078 double doubleRep = ifile->getDouble(section, item); 00079 std::cout << "..as a double = " << doubleRep << std::endl; 00080 } 00081 catch (xmlBase::IFileException toCatch) { 00082 std::cout << " **ERROR** double conversion failed " 00083 << std::endl << std::endl; 00084 } 00085 00086 } 00087 else std::cout << " was NOT found." << std::endl; 00088 }
int main | ( | ) |
Definition at line 11 of file test_IFile.cxx.
References check_raw_filter::filename, lookFor(), and deljobs::string.
00011 { 00012 00013 std::string filename("$(XMLBASEROOT)/xml/myIFile.xml"); 00014 xmlBase::IFile* ifile = 0; 00015 00016 ifile = new xmlBase::IFile(filename.c_str()); 00017 // fetch some stuff 00018 00019 if (ifile) { 00020 00021 lookFor(ifile, "section1", "section1-val1"); 00022 lookFor(ifile, "section1", "section1-val2"); 00023 lookFor(ifile, "subsection","subsectionItem"); 00024 lookFor(ifile, "section2","subsectionItem"); 00025 lookFor(ifile, "section2","bad-int"); 00026 } 00027 else std::cout << "Unable to read file " << ifile << std::endl; 00028 00029 00030 // Now do it again for IFile referencing schema rather than dtd 00031 std::string filename2("$(XMLBASEROOT)/xml/mySchemaIFile.xml"); 00032 00033 std::cout << std::endl << std::endl; 00034 std::cout << "And for my next trick: process an IFile using XML Schema."; 00035 std::cout << std::endl; 00036 std::cout << 00037 "This file should be flagged bad; it doesn't follow schema content model." 00038 << std::endl << std::endl; 00039 00040 xmlBase::IFile* ifile2 = 0; 00041 00042 ifile2 = new xmlBase::IFile(filename2.c_str()); 00043 // fetch some stuff 00044 00045 if (ifile2) { 00046 00047 lookFor(ifile2, "section1", "section1-val1"); 00048 lookFor(ifile2, "section1", "section1-val2"); 00049 lookFor(ifile2, "subsection","subsectionItem"); 00050 lookFor(ifile2, "section2","subsectionItem"); 00051 lookFor(ifile2, "section2","bad-int"); 00052 } 00053 else std::cout << "Unable to read file " << ifile2 << std::endl; 00054 00055 return(0); 00056 }