Back to index

nordugrid-arc-nox  1.1.0~rc6
query.cpp
Go to the documentation of this file.
00001 #ifdef HAVE_CONFIG_H
00002 #include <config.h>
00003 #endif
00004 
00005 #include <glibmm/random.h>
00006 #include <string>
00007 #include <iostream>
00008 #include <fstream>
00009 #include <list>
00010 #include <arc/XMLNode.h>
00011 #include <stdlib.h>
00012 
00013 int main(int argc, char **argv)
00014 {
00015     if(argc < 3) return -1;
00016     int filenum = atoi(argv[1]);
00017     int attrnum = atoi(argv[2]);
00018 
00019     for (int i = 0; i < filenum; i++) { 
00020            // load content of file
00021         char fname[200];
00022         snprintf(fname, sizeof(fname), "file%d.xml", i);
00023         
00024         std::string xml_str = "";
00025         std::string str;
00026            std::ifstream f(fname);
00027            while (f >> str) {
00028                xml_str.append(str);
00029                xml_str.append(" ");
00030            }
00031            f.close();
00032            Arc::XMLNode doc(xml_str);
00033            Arc::NS ns;
00034        Glib::Rand r; 
00035         int n = r.get_int_range(0, attrnum);
00036        char query[200];
00037         snprintf(query, sizeof(query), "//AttributeName%d", n);
00038         
00039         std::cout << "Query: " << query << std::endl;
00040         std::list<Arc::XMLNode> result = doc.XPathLookup(query, ns);
00041            std::list<Arc::XMLNode>::iterator it;
00042        
00043            for (it = result.begin(); it != result.end(); it++) {
00044                std::cout << fname << ":" << (*it).Name() << ":" << std::string(*it) << std::endl;
00045            }
00046     }
00047     return 0;
00048 }