// // Programmer: Craig Stuart Sapp // Creation Date: Tue Jun 7 14:54:28 PDT 2011 // Last Modified: Tue Jun 7 14:54:30 PDT 2011 // Filename: ...sig/examples/all/xmlparse2.cpp // Web Address: http://sig.sapp.org/examples/museinfo/xml/xmlparse.cpp // Syntax: C++; museinfo // // Description: Very simple parse of the contents of an XML file using the // XmlFileBasic class. This class is used to load the text // content of an XML file, but does not parse the content // of the file beyond identifying tags (items surrounded // by square brackets), text, and whitespace separating tags // from non-whitespace text. // #include #include "humdrum.h" #ifndef OLDCPP #include #include #else #include #include using namespace std; #endif #include "XmlFileBasic.h" // function declarations: void checkOptions (Options& opts, int argc, char** argv); void example (void); void usage (const char* command); // User interface variables: Options options; ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { // process the command-line options checkOptions(options, argc, argv); XmlFileBasic xmlfile; int i; if (options.getArgCount() >= 1) { for (i=1; i<=options.getArgCount(); i++) { xmlfile.read(options.getArg(i).c_str()); cout << xmlfile; } } else { xmlfile.read(cin); cout << "ORIGINAL FILE:" << endl; cout << xmlfile; Array texting; texting.setSize(4); texting[0] = 'a'; texting[1] = 'b'; texting[2] = 'c'; texting[3] = '\n'; xmlfile.insertItem(texting, 3); cout << "========================" << endl; cout << "AFTER INSERTING AN ITEM BEFORE ITEM 3:" << endl; cout << xmlfile; xmlfile.deleteItem(3); xmlfile.deleteItem(3); cout << "========================" << endl; cout << "AFTER DELETING TWO ITEMS STARTING AT ITEM 3:" << endl; cout << xmlfile; } return 0; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // checkOptions -- // void checkOptions(Options& opts, int argc, char* argv[]) { opts.define("author=b", "author of program"); opts.define("version=b", "compilation info"); opts.define("example=b", "example usages"); opts.define("help=b", "short description"); opts.process(argc, argv); // handle basic options: if (opts.getBoolean("author")) { cout << "Written by Craig Stuart Sapp, " << "craig@ccrma.stanford.edu, June 2011" << endl; exit(0); } else if (opts.getBoolean("version")) { cout << argv[0] << ", version: 2 Jan 2011" << endl; cout << "compiled: " << __DATE__ << endl; cout << MUSEINFO_VERSION << endl; exit(0); } else if (opts.getBoolean("help")) { usage(opts.getCommand().c_str()); exit(0); } else if (opts.getBoolean("example")) { example(); exit(0); } } ////////////////////////////// // // example -- // void example(void) { } ////////////////////////////// // // usage -- // void usage(const char* command) { } // md5sum: 9c4b5886f6ab483eca870f7337fc0cd1 xmlparse2.cpp [20160320]