Back to index

nordugrid-arc-nox  1.1.0~rc6
testxpath.cpp
Go to the documentation of this file.
00001 // -*- indent-tabs-mode: nil -*-
00002 
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006 
00007 #include "ArcConfig.h"
00008 #include "XMLNode.h"
00009 #include <iostream>
00010 #include <fstream>
00011 #include <string>
00012 #include <list>
00013 #include <map>
00014 
00015 
00016 int main(void) {
00017   std::string xml_str = "";
00018   std::string str;
00019   std::ifstream f("testxpath.xml");
00020 
00021   // load content of file
00022   while (f >> str) {
00023     xml_str.append(str);
00024     xml_str.append(" ");
00025   }
00026   f.close();
00027 
00028   std::cout << "Get the \"child2\" node with namespace \"uri:bbb\" inside the root node" << std::endl;
00029 
00030   Arc::NS nsList;
00031   nsList.insert(std::pair<std::string, std::string>("test", "uri:bbb"));
00032   Arc::XMLNode root(xml_str);
00033   std::list<Arc::XMLNode> list = root.XPathLookup("//test:child2", nsList);
00034   std::list<Arc::XMLNode>::iterator it;
00035   for (it = list.begin(); it != list.end(); it++)
00036     std::cout << (*it).FullName() << ":" << (std::string)(*it) << std::endl;
00037 
00038   std::cout << "************************" << std::endl;
00039 
00040   std::cout << "Get the \"child2\" node with namespace \"uri:ccc\" inside the root node" << std::endl;
00041 
00042   nsList.erase("test");
00043   nsList.insert(std::pair<std::string, std::string>("test1", "uri:ccc"));
00044   list = root.XPathLookup("//test1:child2", nsList);
00045   for (it = list.begin(); it != list.end(); it++)
00046     std::cout << (*it).FullName() << ":" << (std::string)(*it) << std::endl;
00047 
00048   std::cout << "************************" << std::endl;
00049 
00050   std::cout << "Get the \"parent\" node with namespace \"uri:bbb\" inside the root node" << std::endl;
00051 
00052   nsList.erase("test1");
00053   nsList.insert(std::pair<std::string, std::string>("test2", "uri:bbb"));
00054   list = root.XPathLookup("//test2:parent", nsList);
00055   Arc::XMLNode tmp;
00056   for (it = list.begin(); it != list.end(); it++) {
00057     tmp = *it;
00058     std::cout << (*it).FullName() << ":" << (std::string)(*it) << std::endl;
00059   }
00060 
00061   tmp = root.Child();
00062   std::string tmpndstr;
00063   tmp.GetXML(tmpndstr);
00064 
00065   std::cout << "************************" << std::endl;
00066 
00067   std::cout << "Now the current node is: " << tmpndstr << std::endl;
00068 
00069   std::cout << "Looking for the \"child2\" node with namespace \"uri:ccc\"" << std::endl;
00070 
00071   nsList.erase("test2");
00072   nsList.insert(std::pair<std::string, std::string>("test3", "uri:ccc"));
00073   list = tmp.XPathLookup("//test3:child2", nsList);
00074   for (it = list.begin(); it != list.end(); it++) {
00075     std::cout << (*it).FullName() << ":" << (std::string)(*it) << std::endl;
00076     std::cout << "Can get the node by search from the non-root node" << std::endl;
00077   }
00078 
00079   return 0;
00080 }